Re: Re: Defining differential operators question
- To: mathgroup at smc.vnet.net
- Subject: [mg13856] Re: [mg13850] Re: [mg13797] Defining differential operators question
- From: Paul Abbott <paul at physics.uwa.edu.au>
- Date: Mon, 31 Aug 1998 01:09:17 -0400
- Sender: owner-wri-mathgroup at wolfram.com
At 1:11 AM +0800 31/8/98, BobHanlon at aol.com wrote: >If you calculate each derivative using Table, you do not make use of the fact >that you have already calculated the earlier derivatives. Recommend that you >use NestList. NestList is better -- but it still does not save the earlier derivatives if you recomputed the differential operator with different coefficients. You could, of course, use dynamic programming if the computation of the derivatives was that expensive (not the usual situation). >Also, why restrict the function to being a Symbol? One reason: see what happens to difOp[{a0, a1, a2, a3}, Function[{x}, x^2]] >difOp[coef_List, func_, sym_Symbol:x] := > coef.NestList[D[#, sym]&, func, Length[coef]-1] /; > Length[coef] > 0 > >coef = {a0, a1, a2, a3}; > >difOp[coef, f[x]] > >a0*f[x] + a1*Derivative[1][f][x] + a2*Derivative[2][f][x] + > a3*Derivative[3][f][x] > >difOp[coef, g[y], y] > >a0*g[y] + a1*Derivative[1][g][y] + a2*Derivative[2][g][y] + > a3*Derivative[3][g][y] > >difOp[coef, a x^2 + b x + c] > >2*a*a2 + a1*(b + 2*a*x) + a0*(a*x^2 + b*x + c) The problem with this code is that it does not produce a differential operator. Here is a slight modification of Jurgen Tischer's code (to use NestList): In[1]:= difOp[l_List /; Length[l] > 0, f_Symbol] := Function[{y}, Evaluate[l.Through[NestList[ Derivative[1], f, Length[l] - 1][y]]]] This produces a differential operator: In[2]:= difOp[{a0, a1, a2, a3}, f] Out[2]= Function[{y$}, a0 f[y$] + a1 f'[y$] + a2 f''[y$] + a3 f'''[y$]] which can be evaluate for any argument: In[3]:= difOp[{a0, a1, a2, a3}, f][t] Out[3]= (3) a0 f[t] + a1 f'[t] + a2 f''[t] + a3 f [t] Cheers, Paul