function which takes functions as arguments



If the inputs are functions, it seems to me that the output should also
be a function:

(%i1) load(linearalgebra)$

(%i2) find_jacobian(f) := block([n : length(f), v, j],
   v : makelist(?gensym(),i,1,n),
   j : jacobian(map(lambda([s], apply(s, v)), f),v),
   buildq([v,j], lambda(v,j)))$

Test:

(%i3) x(r,theta,phi):=r*sin(theta)*cos(phi)$
(%i4) y(r,theta,phi):=r*sin(theta)*sin(phi)$
(%i5) z(r,theta,phi):=r*cos(theta)$

(%i6) f : find_jacobian([x,y,z])$
(%i7) f(r,theta,phi);

(%o7) matrix([cos(phi)*sin(theta),cos(phi)*r*cos(theta), < junk deleted >

(%i8) trigsimp(determinant(%));
(%o8) r^2*sin(theta)

BW

-----maxima-bounces at math.utexas.edu wrote: -----

>To: maxima at math.utexas.edu
>From: "U&#287;ur G?ney" <ugurguney at gmail.com>
>Sent by: maxima-bounces at math.utexas.edu
>Date: 10/03/2007 03:13PM
>Subject: function which takes functions as arguments
>
># Hi all,
># I want to study coordinate transformations using Maxima. What I want is
>to have a function, find_jacobian(), which takes tree functions as
>arguments and returns a matrix. For example, the three functions are
>
>x(r,theta,phi):=r*sin(theta)*cos(phi);
>y(r,theta,phi):=r*sin(theta)*sin(phi);
>z(r,theta,phi):=r*cos(theta);
># These are transformation functions from rectangular to spherical
>coordinates.
># The elements of the matrix Jacobian are
>
>[ del x/del r   del x/del theta   del x/del phi ]
>[ del y/del r  ...]
>[...]
># the user will define three functions
>x1(q1,q2,q3):= some function of q1,q2 and q3;
>x2(q1,q2,q3);= ...;
># and call
>J: find_jacobian(x1,x2,x3);
>
># and have the Jacobian in J.
># How can I do this? What notation should I use in order to have functions
>in arguments (like in integrate() for example)? And in the function body,
>how can I say "differentiate x1 with respect to first argument of x1" I
>looked at the manual
>http://maxima.sourceforge.net/docs/manual/en/maxima_39.html but could not
>find this kind of definition.
># Regards.
>-ugur guney-
>
>_______________________________________________
>Maxima mailing list
>Maxima at math.utexas.edu
>http://www.math.utexas.edu/mailman/listinfo/maxima