[R] first and second derivative calculation

Doran, Harold
2010-01-22T21:41:05Z

> D(expression(t^3-6*t^2+5*t + 30), 't')
3 * t^2 - 6 * (2 * t) + 5

> D(D(expression(t^3-6*t^2+5*t + 30), 't'), 't')
3 * (2 * t) - 6 * 2

-----Original Message-----
From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org]
On Behalf Of Marlin Keith Cox
Sent: Friday, January 22, 2010 4:37 PM
To: r-help at r-project.org
Subject: [R] first and second derivative calculation

I would like to calculate a first and second derivative and am having
problems finding a simple solution.  My syntax may be off as I am not a
mathematician, so pardon ahead of time.
data:
t<-seq(0,4, by=.1)
The function is:
H(t) = t^3-6*t^2+5*t + 30

from here I plot the curve:
plot(x,y ,xlab="x-values", ylab="f(x)", type="l")
But would like to similarly plot the curve for both the first and second
derivatives.
I can calculate the derivatives by hand but would like to get R to do this
for me.
by hand:
H'(t) = 3*t^2 - 12*t + 5
H''(t) = 6*t-12
Keith

--
M. Keith Cox, Ph.D.
Alaska NOAA Fisheries, National Marine Fisheries Service
Auke Bay Laboratories
17109 Pt. Lena Loop Rd.
Juneau, AK 99801
Keith.Cox at noaa.gov
marlinkcox at gmail.com
U.S. (907) 789-6603

	[[alternative HTML version deleted]]

______________________________________________
R-help at r-project.org 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.