Re: nested derivatives
- To: mathgroup at smc.vnet.net
- Subject: [mg93119] Re: nested derivatives
- From: Jean-Marc Gulliet <jeanmarc.gulliet at gmail.com>
- Date: Mon, 27 Oct 2008 03:12:51 -0500 (EST)
- Organization: The Open University, Milton Keynes, UK
- References: <ge14fc$9g2$1@smc.vnet.net>
Huub Mooren wrote: > How do I enter the following recursive function in Mathematica: > t[n]=(1/y')*t'[n-1], > with n the index > t[0]=x > y is some function of x Since t[n] does not explicitly depends on x, we must write t'[n-1] as D[t[n-1],x]. Having said that, we can define our function either using an explicit recursive definition (see In[1], note that the definition also includes some test on the argument and use memoization [1] for computational efficiency [2]), or we can use higher-level functions such as *Nest* [3] (see In[4], which use a pure function for its recursive call). In[1]:= t[0] = x; t[n_Integer?Positive] := t[n] = 1/y'[x] D[t[n - 1], x] Table[{n, t[n]}, {n, 4}] // TableForm[#, TableHeadings -> {None, {"n", "t[n]"}}] & // OutputForm Out[3]//OutputForm= n t[n] 1 1 ----- y'[x] 2 y''[x] -(------) 3 y'[x] 3 2 (3) 3 y''[x] y [x] --------- - ------- 4 3 y'[x] y'[x] ------------------- y'[x] 2 (3) 3 y''[x] y [x] y''[x] (--------- - -------) 4 3 y'[x] y'[x] (-(----------------------------) + 2 y'[x] 3 (3) (4) -12 y''[x] 9 y''[x] y [x] y [x] (----------- + ---------------- - -------) / y'[x]) / y'[x] 5 4 3 4 y'[x] y'[x] y'[x] In[4]:= tt[n_Integer?Positive] := Nest[1/y'[x] D[#, x] &, x, n] Table[tt[n] == t[n], {n, 4}] Out[5]= {True, True, True, True} Regards, - Jean-Marc [1] "Memoization", From Wikipedia, the free encyclopedia, http://en.wikipedia.org/wiki/Memoization [2] "Functions That Remember Values They Have Found" http://reference.wolfram.com/mathematica/tutorial/FunctionsThatRememberValuesTheyHaveFound.html [3] "Applying Functions Repeatedly" http://reference.wolfram.com/mathematica/tutorial/ApplyingFunctionsRepeatedly.html