Re: [R] how to get higher derivatives with deriv

2010-08-01 Thread mhofert
Dear all, many thanks, great work. Here is the feature which Peter suggested (it also includes a string containing the variable name): DD - function(f, var.string=x, order=1){ res - f body.res - body(f) i - 1 while(i = order){ body.res -

Re: [R] how to get higher derivatives with deriv

2010-07-30 Thread mhofert
Okay, great. Thanks. Cheers, Marius -- View this message in context: http://r.789695.n4.nabble.com/how-to-get-higher-derivatives-with-deriv-tp2306711p2307709.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org

Re: [R] how to get higher derivatives with deriv

2010-07-30 Thread peter dalgaard
On Jul 29, 2010, at 11:27 PM, Wu Gong wrote: ## specify the function string f.str - x^alpha ## higher derivatives DD - function(f.str, x = 2, alpha=3,order = 1){ expr.s - parse(text=f.str) while(order=1) { expr.s - D(expr.s,x) order - order-1} eval(expr.s) } compute

Re: [R] how to get higher derivatives with deriv

2010-07-30 Thread Ravi Varadhan
-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of peter dalgaard Sent: Friday, July 30, 2010 9:52 AM To: Wu Gong Cc: r-help@r-project.org Subject: Re: [R] how to get higher derivatives with deriv On Jul 29, 2010, at 11:27 PM, Wu Gong wrote: ## specify the function

Re: [R] how to get higher derivatives with deriv

2010-07-30 Thread peter dalgaard
On Jul 30, 2010, at 4:28 PM, Ravi Varadhan wrote: I am not as lazy as Peter (but neither am I as good as him)! So, please allow me to take a stab at completing his exercise: Deriv - function(fn, order=1) { ddf - fn body(ddf) - D(body(f),x) ### Typo: body(ddf) or body(fn) if (order 1)

Re: [R] how to get higher derivatives with deriv

2010-07-30 Thread Wu Gong
Hi Peter, Here is my homework :) DD - function(f,order=1){ f.str - body(f) while(order=1) { f.str - paste('D(',f.str,',x)',sep=) order - order-1} ddf - f body(ddf) - eval(parse(text=f.str)) ddf} f - function(x,alpha) x^alpha DD(f)(2,3) g

[R] how to get higher derivatives with deriv

2010-07-29 Thread Marius Hofert
Dear ExpeRts, I have trouble implementing a function which computes the k-th derivative of a specified function f and returns it as a function. I tried to adapt what I found under ?deriv but could not get it to work. Here is how it should look like: ## specify the function f - function