Try this:
func <- function(x) {}
body(func) <- D(quote(x^2-1), "x")
uniroot(func, interval=c(-0.1,1.1), tol=1e-6)
On 4/13/07, Patrick Wang <pwang at berkeley.edu>
wrote:> Hi, All
>
> Assume I have function x^2-1, I tried to find the root of its derivative
> 2*x = 0.
>
> I run the command below but it return 1, root of the original function.
> Does anyone know how to get the root of the derived function?
>
> Thanks
> pat
> =======================================> func =
deriv(parse(text="x^2-1"), "x", func=TRUE)
> uniroot(func, interval=(-0.1,1.1), tol=1e-6)
> =======================> $root
> [1] 1
>
> $f.root
> [1] -1.709702e-07
> attr(,"gradient")
> x
> [1,] 2
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>