[R] first and second derivative calculation
Adaikalavan Ramasamy
a.ramasamy at imperial.ac.uk
Sat Jan 23 18:24:40 CET 2010
How about?
eval( D( expression( t^3-6*t^2+5*t+30 ), "t" ) )
David Winsemius wrote:
> On Jan 22, 2010, at 6:49 PM, Marlin Keith Cox wrote:
>
>> I can plot this just fine:
>> t<-seq(0,4, by=.1)
>> y<- t^3-6*t^2+5*t+30
>> plot(t,y ,xlab="t-values", ylab="f(t)", type="l")
>> This is the first derivative, how I I make a similar plot?
>> t<-seq(0,4, by=.1)
>> y<- t^3-6*t^2+5*t+30
>> y1<-D(expression(t^3-6*t^2+5*t+30), 't')
>
> There might be some sort of deparse() operation that one could do on
> y1, but what follows sidesteps that level of programming.
>
>
> y1fn <- function(t) {3 * t^2 - 6 * (2 * t) + 5}
> par(new=TRUE)
> plot(t, y1fn(t), ylab="", xlab="", axes=FALSE)
> axis(side=4, at=seq(-7,5,by=1) )
>
>> --
> David.
>
>> Thanks ahead of time.
>>
>> kc
>>
>>
>> On Fri, Jan 22, 2010 at 12:41 PM, Doran, Harold <HDoran at air.org>
>> wrote:
>>
>>>> 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<http://www.r-project.org/posting-guide.html
>>> and provide commented, minimal, self-contained, reproducible code.
>>>
>>
>>
>> --
>> 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.
>
> David Winsemius, MD
> Heritage Laboratories
> West Hartford, CT
>
> ______________________________________________
> 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.
More information about the R-help
mailing list