Hi

I am currently (for pedagogical purposes) writing a simple numerical
analysis library in R. I have come unstuck when writing a simple
Newton-Raphson implementation, that looks like this:

f <- function(x) { 2*cos(x)^2 + 3*sin(x) +  0.5  }

root <- newton(f, tol=0.0001, N=20, a=1)

My issue is calculating the symbolic derivative of f() inside the newton()
function. I cant seem to get R to do this...I can of course calculate the
derivative by calling D() with an expression object containing the inner
function definition, but I would like to just define the function once and
then compute the derivative of the existing function. I have tried using
deriv() and as.call(), but I am evidently misusing them, as they dont do
what I want. Does anyone know how I can define a function, say foo, which
manipulates one or more arguments, and then refer to that function later in
my code in order to calculate a (partial) derivative?

Thanks
Rory

        [[alternative HTML version deleted]]

______________________________________________
R-help@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.

Reply via email to