[R] Search zeros of one function

enrico.foscolo enrico.foscolo at libero.it
Thu Mar 22 18:32:39 CET 2007


Dear participants to the list,

this is my problem: I want to find zeros of an arbitrary function.
With "uniroot" (package "stats") it is possible to find (numerically) a root of the function,
but I do not know how I can find at the same time the zeros
in a determined interval (if this function must have more of one solution).

For example: suppose that I have a function of this form:
f(x)=cos(x).
I can find a lot of roots.
In fact, let x be in [-10,10]:

> f<-function(x){return(cos(x))}
> uniroot(f,lower=-10,upper=-5)
$root
[1] -7.85401

$f.root
[1] -2.895499e-05

$iter
[1] 6

$estim.prec
[1] 6.103516e-05
> uniroot(f,lower=-5,upper=-2)
$root
[1] -4.712389

$f.root
[1] -5.805468e-08

$iter
[1] 5

$estim.prec
[1] 6.103516e-05

...

At last, I would want to ask to you if a package (or a function) exists that it knows
to resolve the problem of the search of the maximums or minimums (local and global)
of one function.

Many thanks for any kind of help in advance,
Enrico


------------------------------------------------------
Passa a Infostrada. ADSL e Telefono senza limiti e senza canone Telecom
http://click.libero.it/infostrada



More information about the R-help mailing list