# Re: [R] Non-linear system of equations

From: Berend Hasselman <bhh_at_xs4all.nl>
Date: Fri, 25 Apr 2008 05:55:14 -0700 (PDT)

> x^2 - y^2 = 6
> x – y = 3
>
>

You can also try this

# function

f <- function(x) {

y <- numeric(2)
y <- x^2-x^2-6
y <- x-x-3

y
}

# function values transformed to scalar # minimising fnorm this way is not the best method of finding a solution for f(x)=0
# there may be values for x which minimise fnorm but do not set f(x) = 0 # but you can always try

fnorm <- function(z) {p <- f(z);return(crossprod(p))}

#starting values
xstart <- c(0,0)

# You can use nlm or nlminb

nlm(fnorm,xstart)

nlminb(xstart,fnorm)

Sometimes minpack.lm can be used to find roots. Do

library(minpack.lm)
nls.lm(xstart,f)

and in this case you'll see that it doesn't work.

In this case stick to nlm and/or nlminb.

Berend

```--
View this message in context: http://www.nabble.com/Non-linear-system-of-equations-tp16893056p16895541.html
Sent from the R help mailing list archive at Nabble.com.

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