Re: How to pass a function to a function?

*To*: mathgroup at smc.vnet.net*Subject*: [mg93656] Re: How to pass a function to a function?*From*: Albert Retey <awnl at gmx-topmail.de>*Date*: Fri, 21 Nov 2008 05:30:46 -0500 (EST)*References*: <gg3c9m$k5b$1@smc.vnet.net>

Aaron Fude schrieb: > Hi, > > How does one write a call a function that represents an operator? In > other words, it takes a function and returns another function. If you need to return a function, then do so: Laplacian[f_] := Function[{x, y}, Derivative[2, 0][f][x, y] + Derivative[0, 2][f][x, y] ] or, if you want the derivatives not to be calculated for every call of the resulting function but only when defining the Laplacian: Laplacian[f_] := With[{ d2fdx2 = Derivative[2, 0][f],d2fdy2 = Derivative[0, 2][f] }, Function[{x, y}, d2fdx2[x, y] + d2fdy2[x, y]] ] > For example, if you think of the Laplacian I want to do something like > this (pseudo code): > > f[x_, y_] := x^4 +y^4 > g = Laplacian[f]; > > N[g[1, 1], 50] > This is the above definition in action, note that it also works for pure functions: In[56]:= g=Laplacian[f] Out[56]= Function[{x$,y$},(12 #1^2&)[x$,y$]+(12 #2^2&)[x$,y$]] In[57]:= g[1,1] Out[57]= 24 In[58]:= Laplacian[#1^4+#2^4&][1,1] Out[58]= 24 hth, albert