[R] Deriv and integrate

Thomas Lumley tlumley at u.washington.edu
Thu Jul 4 18:06:54 CEST 2002


On Thu, 4 Jul 2002 tlorino at vet-alfort.fr wrote:

>  Dear R users,
>
> I would like to express a function (with only one argument) as the integrate of its derivate.
> For example, for y=x^2, I would like something like
>
> integrate(deriv(~x^2,"x", function(x) NULL, formal=T),0,2)
>
> which would give me... 4.

 integrate(function(x) attr(deriv(~x^2,"x", function(x) NULL, formal=T)(x),
			    "gradient"),0,2)

will do it. The deriv() function is designed to produce derivatives for
optimisers, which is why it returns the function value with the derivative
as an attribute.

This does seem a strange thing to want to do...


	-thomas

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list