MathGroup Archive 1998

[Date Index] [Thread Index] [Author Index]

Search the Archive

RE: Simple question




A number of users answered a question from Anderson Brasil: Penny wrote:
 ----------
|I believe this will work for you:
|
|df[f_,x_,n_,x0_]:=(D[f,{x,n}] /. x->x0) |
|
|g[t_]:=Sin[t]
|df[g[t],t,2,3]
|df[g[y],y,1,4]
|
|Cheers,
|

Also Wouter sent in the long and cryptic collection of code below. I
admire Wouter's dedication to the group, but code like that is a sure
fire  way to scare beginners away from Mathematica.

Dont' use  (  y=#1^#2&@Sequence[x,2]   ) when ( y=x^2 )  will work just
as well.


Ted

|since you do not define the function and it's argument, I suppose you
|want (wisely) to operate on a functional level : in that case, here is
|something to play with:
|
|diff[f_,n_:1]:=Function[dum,Evaluate@D[f[dum],{dum,n}] ] intover[f_]:=
|Function[d,Evaluate@Integrate[f[d],d]]  intover[f_,n_:1]:=
|Nest[intover,f,n]
|
|here is a demonstration on a "pure" or "anonymous" function
|(E^-#-E^#)^10& (where you could call "#" a dummy-variable: In[10]:=
|diff[(E^-#-E^#)^10&,3 ]
|Out[10]=Function[dum$, 720*(-E^(-dum$) - E^dum$)^3* |    (E^(-dum$) -
E^dum$)^7 +
|   280*(-E^(-dum$) - E^dum$)*(E^(-dum$) - E^dum$)^9] |
|as you can see, it returns a pure function too, still without argument.
|You can give it an argument :
|In[11]:= diff[(E^-#-E^#)^10&,3 ] [z] |
|Out[11]=720*(-E^(-z) - E^z)^3*(E^(-z) - E^z)^7 + | 280*(-E^(-z) -
E^z)*(E^(-z) - E^z)^9 |
|Needless to say, once you "grok" the technique, anything goes : |
|In[12]:=Nest[intover ,1+#^2&,2]
|Out[12]=Function[d$, d$^2/2 + d$^4/12] |
|In[15]:=Nest[intover ,1+#^2&,2][x]
|Out[15]=x^2/2 + x^4/12
|
|In[16]:=intover[(1+#)^2 &,4][z]
|Out[16]=z^4/24 + z^5/60 + z^6/360
|
|In[17]:=Function[z,Evaluate@%]
|Out[17]=Function[z, z^4/24 + z^5/60 + z^6/360] |
|In[18]:=diff[%,4][x]
|Out[18]=1 + 2*x + x^2
|




  • Prev by Date: Total Newbie
  • Next by Date: Re: Help coloring plot
  • Prev by thread: Re: Simple question
  • Next by thread: Re: Simple question