# Re: [R] Solve f(x) = 0

From: Spencer Graves <spencer.graves_at_pdf.com>
Date: Thu 09 Jun 2005 - 02:20:31 EST

Have you plotted f(x)? Plot(s) might help reveal why "the solution is very unstable." If f is a function of a univariate x, this is trivial. If f is a function of a bivariate x, use something like contour or persp. If higher dimensions, I might use something like

```	  fit <- optim(... hessian=TRUE)
eigen(fit\$hessian)

hope this helps.
spencer graves

```

Martyn Plummer wrote:

```>>Hi!
>>
>>Im need a function that solves the equation f(x) = 0 (i.e. the root of
>>the function) when f is a nonlinear function. Is there any? Ive tried nlm
>>and optim on the square of the function but the solution is very unstable.
```

>
>
> Your colleague Martin Englund asked the same question. If x is scalar,
> you can use uniroot(). If it's a polynomial then polyroot() finds all
> the zeros. I hope that helps.
>
> Martyn
>
> ______________________________________________
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help