home *** CD-ROM | disk | FTP | other *** search
- From: jpat@hpsad.sad.hp.com (Jeff Patterson)
- Date: Thu, 23 Jul 1992 19:45:06 GMT
- Subject: Re: Mathematica Help
- Message-ID: <1900005@hpsad.sad.hp.com>
- Organization: HP Signal Analysis Division - Rohnert Park, CA
- Path: sparky!uunet!zaphod.mps.ohio-state.edu!mips!sdd.hp.com!hpscdc!hplextra!hpl-opus!hpnmdla!hpsad!jpat
- Newsgroups: sci.math
- References: <1992Jul21.222351.160911@cs.cmu.edu>
- Lines: 35
-
- Mathematica will not let you make assignments to an element of a list
- directly. You can build up lists using Prepend, Append, Insert etc.
- However here's a one liner to do what you want:
-
- v=Thread[DD[f[x1,x2,x3],{x1,x2,x3}]] /. DD->D
-
- Thread[f[arg1,{arg2,arg3}] forms {f[arg1,arg2],f[arg1,arg3]}. So the
- in the above line Thread[DD[f[x1,x2,x3],{x1,x2,x3}]] forms:
-
- {DD[f[x1,x2,x3],x1],DD[f[x1,x2,x3],x2],DD[f[x1,x2,x3],x3]}.
-
- The /. DD->D replaces all the DD heads with D heads which results in the
- partial derivatives being taken. The last bit of subterfuge is necessary
- because the derivitive operator D allows a list in the second position
- as in D[f[x1,x2],{x1,5}] which yields the 5th partial of f wrt x1, so we
- first get the final list in the form we want (no list in second position)
- using the dummy head DD and then change the head to the desired D.
-
- Another way is to use the Outer function as in:
-
- v=Outer[D,{f[x1,x2,x3]},{x1,x2,x3}]
-
- Outer applies the fuction in arg 1 to a list formed by the outer product
- of lists in arg2 and arg3. Thus
-
- In[211]:= Outer[Plus,{a,b},{c,d}]
- Out[211]= {{a + c, a + d}, {b + c, b + d}}
-
- Note that using the above you can build a matrix of partials directly
-
- Outer[D,{f1[x1,x2,x3],f2[x1,x2,x3]},{x1,x2,x3}] produces a list of two lists.
- The first list contains all the partials of f1 and the second all the partials
- of f2.
-
- Hope this helps-Jeff
-