[R] nlm question
Laura Holt
lauraholt_983 at hotmail.com
Mon Oct 11 19:51:25 CEST 2004
Dear R People:
I am trying to duplicate the example from Dennis and Schnabel's "Numerical
Methods for Unconstrained Optimization and Nonlinear Equations", which
starts on page 149.
My reason for doing so: to try to understand the "nlm" function.
Here is the function:
>mfun1
function(x) {
z <- matrix(0,nrow=2,ncol=1)
z[1,1] <- x[1]^2 + x[2]^2 - 2
z[2,1] <- exp(x[1]-1) + x[2]^3 - 2
res <- 0.5*t(z)%*%z
res
}
This function has a root at c(1,1).
When I use the following:
>nlm(mfun1,c(2,0.5))
$minimum
[1] 0.09168083
$estimate
[1] 1.485078e+00 -4.973395e-07
$gradient
[1] -8.120649e-09 1.096345e-09
$code
[1] 1
$iterations
[1] 19
I get the solution of 1.485078 and zero.
Now when I use:
>nlm(mfun1,c(1.2,0.85))
$minimum
[1] 2.025965e-12
$estimate
[1] 1.000001 0.999999
$gradient
[1] 6.799786e-08 6.520232e-08
$code
[1] 1
$iterations
[1] 8
>
I get the appropriate answer.
What can I put into my code to improve the estimates, please?
Thanks
Sincerely,
Laura Holt
R Version 2.0.0
Windows
mailto: lauraholt_938 at hotmail.com
More information about the R-help
mailing list