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

From: Paul Smith <phhs80_at_gmail.com>
Date: Fri, 25 Apr 2008 13:58:08 +0100

p0 <- rnorm(2)

But you sure that your system has a solution, Evgeniq?

Paul

> Hello Paul,
>
> Thank you for your quick answer. I have tried to use your advice and to estimate the parameters of beta distribution with moments matching. This is my code:
>
>
> ex <- 0.3914877
> ex2 <- 0.2671597
>
> my.mm <- function(x){
> p <- x
> q <- x
> p <- .Machine\$double.eps
> q <- .Machine\$double.eps
>
> F <- rep(NA,2)
>
> F <- p/(p + q)
> F<- (p*q + (p + q + 1)*p^2)/((p + q + 1)*(p + q)^2)
>
> return(F)
> }
>
> p0 <- c(ex,ex2)
>
> dfsane(par=p0, fn=my.mm,control=list(maxit=50000))
>
> and I became the following output:
>
> …
> iteration: 3640 ||F(xn)|| = 0.7071068
> iteration: 3641 ||F(xn)|| = 0. 7071068
> …
> iteration: 49990 ||F(xn)|| = 0. 7071068
> iteration: 50000 ||F(xn)|| = 0. 7071068
> \$par
>  -446.2791 -446.4034
>
> \$residual
>  0.5
>
> \$fn.reduction
>  0
>
> \$feval
>  828495
>
> \$iter
>  50001
>
> \$convergence
>  1
>
> \$message
>  "Maximum limit for iterations exceeded"
>
> I have tried maxiter=100000 but the output is the same. I know that ex and ex2 are bringing the problems, but I am stuck with them. How can I make it convergent?
>
> Thank you,
>
> Evgeniq
>
>
>
> >> 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^2-x^2-6
> >> f2 <-z~ x-x-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
> > x2 <- x
> >
> > F <- rep(NA, 2)
> >
> > F <- x1^2 - x2^2 - 6
> > F <- 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
> >and provide commented, minimal, self-contained, reproducible code.
> >
>
> ______________________________________________
> R-help_at_r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help