[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:
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)
[1] -7.85401

[1] -2.895499e-05

[1] 6

[1] 6.103516e-05
> uniroot(f,lower=-5,upper=-2)
[1] -4.712389

[1] -5.805468e-08

[1] 5

[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,

Passa a Infostrada. ADSL e Telefono senza limiti e senza canone Telecom

More information about the R-help mailing list