# [R] can optimize solve paired euqations?

Thu Dec 20 23:38:56 CET 2007

```Hi Xin,

You can use the nlsolve() function that I have written to solve a nonlinear
system of equations.  It converts a root finding problem into a minimization
problem, and uses optim() to find the minimizer.

A well-known problem with this approach to root-finding is that a local
minimum of the squared residual function is not necessarily a root of the
nonlinear system.  A nice feature of nlsolve() is that it will try "really
hard" (by increasing the "nstarts" argument) to find the solution to the
system by identifying multiple local minima of the squared residual
function, if they exist.

Here is a solution to your problem (I rearranged your equations a bit).

func <- function(x, A, B, pz) {
f <- rep(NA,length(x))
f <- A/(1-pz^10) - x*(1-x)/(x*(1-x^x))
f <- A + B/A - 1/x - x*(1-x)/x
f
}

> p0 <- c(0.2,10)
> set.seed(123)
> nlsolve(par=p0, fn=func, A=327.727, B=9517.336, pz=0.114^10, nstart=1000)
\$par
 0.03443476  11.68745035

\$value
 7.01806e-05

\$counts
148       15

\$convergence
 0

\$message
NULL

Best,
Ravi.

----------------------------------------------------------------------------
-------

Assistant Professor, The Center on Aging and Health

Division of Geriatric Medicine and Gerontology

Johns Hopkins University

Ph: (410) 502-2619

Fax: (410) 614-9625

----------------------------------------------------------------------------
--------

-----Original Message-----
From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On
Behalf Of Xin
Sent: Wednesday, December 19, 2007 5:12 PM
To: R-Help
Subject: [R] can optimize solve paired euqations?

I used the command below, but R gives me the error message--syntax error.
can anyone see the mistakes I made?

optimize(function(x,y)
+ ((327.727-(1-0.114^10)*y*(1-x)/x/(1-x^y))+(9517.336-327.727
*(1+(1-x)*(1+y)/x-327.727)))^2
+ interval=c(0,1))

At the same time, I use nlm() but R gives me the code

\$code
 3

function(vals) {

x <- vals

y <- vals

sum(c((199.458913633542-(1-0.114^10)*y*(1-x)/x/(1-x^y)),(5234.11964684527-19
9.458913633542*(1+(1-x)*(1+y)/x-199.458913633542)))^2)

}

nlm(f, c(2,2))

Any one know how to deal with this case?

Thanks

Xin

[[alternative HTML version deleted]]

______________________________________________
R-help at r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help