Re: iterations, recursions and derivatives
- To: mathgroup at smc.vnet.net
- Subject: [mg22559] Re: iterations, recursions and derivatives
- From: Jens-Peer Kuska <kuska at informatik.uni-leipzig.de>
- Date: Sat, 11 Mar 2000 17:52:35 -0500 (EST)
- Organization: Universitaet Leipzig
- References: <8a7os1$kbb@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
Hi, you should stop using Mathematica for some weeks and read the Mathematica book by S. Wolfram that came with your Mathematica copy. It has a wonderful section how to define derivatives. Lets take the recursions for Hermite polynomials. First we define the polynomials with h[0, x_] := 1 h[1, x_] := 2 x h[n_Integer, x_] := 2 x*h[n - 1, x] - 2(n - 1)*h[n - 2, x] notice how easy the recursive definition is. So now lets define the derivative with Derivative[0, 1][h][n_, x_] := 2 n*h[n - 1, x] it is absolut easy and D[h[n,x],x,x] work without any definition and D[h[n,x],x,x] gives 4 (-1 + n) n h[-2 + n, x]. Regards Jens PS: I know that the iterative version of the recursion is faster & better. Otto Linsuain wrote: > > Hello. I find it hard to define a sequence of functions recursively and > be able to differenciate them at the same time. For example > > f[x_,1]:=x^2 > > Try to differentiate Derivative[1,0][f][2,1] will not work. Changing := > for = doesn't help. Can do: > > f[x_,1_]:=x^2 Notice the _ after the 1 (Kind of wierd, isn't it?) Yes because it's nonsense. > > Now, however, can differentiate: Derivative[1,0][f][2,1] works fine. > But cannot work recursions: > > f[x_,m_]:= SomeOperation[f[x,m-1]] confuses the recursion process. I > have tried defining > > f[x_,m_]:=If[m==1,x^2,SomeOperation[f[x,m-1]], but the recursion again > crashes. > > I have tried Which, Switch, Condition, Dt, D, etc, but to no avail. > When I can take the derivative, I can't update m to m+1. But you have not tried f[x_, 1] := x^2 f[x_, n_Integer] := (n - 1)*f[x, n - 1]/x all works fine including the derivative D[f[x,4],x] gives - 6/x^2 as expected.