# [R] solve nonlinear equation using BBsolve

Berend Hasselman bhh at xs4all.nl
Mon Nov 22 17:07:24 CET 2010

```After my reply you sent me the following privately:

> Thank you for your respond.  Now I adjust the parameters which are close
> to the value that I'm expected and it gives me the following message:  I
> tried a few combination.  My question is why it said "Unsuccessful
> convergence" but still give some answers?  Can I use the answers?
>
>
>> p0 <- c(2.5,25,25,0.8)
>> mgf_gammasum(p0)
> [1]   -17.3600000 -3410.6900000     0.3508769    -1.1028287
>> BBsolve(par = p0, fn = mgf_gammasum)[[1]]
>   Unsuccessful convergence.
> [1]  2.066909 44.068739 24.809270  0.972542
>> source(.trPaths[5], echo=TRUE, max.deparse.length=10000)
>> p0 <- c(1.7,36,50,0.9)
>> mgf_gammasum(p0)
> [1]    3.8400000 2601.0300000    0.7232021    0.2866732
>> BBsolve(par = p0, fn = mgf_gammasum)[[1]]
>   Unsuccessful convergence.
> [1]  2.0823407 18.3757502 49.9935914  0.9456666
>> p0 <- c(2,40,40,0.8)
>> mgf_gammasum(p0)
> [1]   17.6400000 2798.7100000    0.4883676   -0.5653881
>> BBsolve(par = p0, fn = mgf_gammasum)[[1]]
>   Unsuccessful convergence.
> [1]  2.059853 29.215478 39.882727  0.914894
>

It is only giving you the values it stopped at.
You are only printing  [[1]]  of BBsolve's result.
BBsolve provides more information.
You can easily check if the result is usable.

Do something like this.

p0 <- c(2.5,25,25,0.8)
bb.result <- BBsolve(par = p0, fn = mgf_gammasum)
bb.result
mgf_gammasum(bb.result\$par)

You will see that BBsolve has NOT found a solution.

If you use nleqslv as follows you will see that the jacobian matrix in your
starting point is very ill-conditioned.

nleqslv(p0,mgf_gammasum)

All your other starting points have similar problems.
You really need to rethink your system of equations.

In future please also reply to the list and not only to me privately.

best

Berend
--
View this message in context: http://r.789695.n4.nabble.com/solve-nonlinear-equation-using-BBsolve-tp3052167p3053902.html
Sent from the R help mailing list archive at Nabble.com.

```

More information about the R-help mailing list