From: Paul Smith <phhs80_at_gmail.com>

Date: Fri, 25 Apr 2008 10:57:49 +0100

R-help_at_r-project.org mailing list

https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Received on Fri 25 Apr 2008 - 10:01:30 GMT

Date: Fri, 25 Apr 2008 10:57:49 +0100

2008/4/25 Radka Pancheva <radica_at_abv.bg>:

> I am trying to estimate the parameters of a bimodal normal distribution using moments matching, so I have to solve a non-linear system of equations. How can I solve the following simple example?

*>
**> x^2 - y^2 = 6
**> x – y = 3
**>
**> I heard about nlsystemfit, but I don't know how to run it exactly. I have tried the following code, but it doesn't really work:
**>
**>
**> f1 <-y~ x[1]^2-x[2]^2-6
**> f2 <-z~ x[1]-x[2]-3
**> f <- list(f1=0,f2=0)
**> nlsystemfit("OLS",f,startvals=c(0,0))
*

You could try the recent package BB by Ravi Varadhan. The code could be the following:

library(BB)

f <- function(x) {

x1 <- x[1]

x2 <- x[2]

F <- rep(NA, 2)

F[1] <- x1^2 - x2^2 - 6

F[2] <- x1 - x2 - 3

return(F)

}

p0 <- c(1,2)

dfsane(par=p0, fn=f,control=list(maxit=3000))

I got the solution:

x1 = 2.5

x2 = -0.5

Paul

R-help_at_r-project.org mailing list

https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Received on Fri 25 Apr 2008 - 10:01:30 GMT

Archive maintained by Robert King, hosted by
the discipline of
statistics at the
University of Newcastle,
Australia.

Archive generated by hypermail 2.2.0, at Fri 25 Apr 2008 - 12:30:30 GMT.

*
Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help.
Please read the posting
guide before posting to the list.
*