home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #16 / NN_1992_16.iso / spool / sci / math / 9483 < prev    next >
Encoding:
Internet Message Format  |  1992-07-23  |  1.7 KB

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