home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #19 / NN_1992_19.iso / spool / sci / math / symbolic / 2277 < prev    next >
Encoding:
Text File  |  1992-08-27  |  8.2 KB  |  263 lines

  1. Newsgroups: sci.math.symbolic
  2. Path: sparky!uunet!snorkelwacker.mit.edu!bloom-picayune.mit.edu!athena.mit.edu!bhattas
  3. From: bhattas@athena.mit.edu (Saurav D Bhatta)
  4. Subject: RE: mathematica-complex variables
  5. Message-ID: <1992Aug27.163329.15675@athena.mit.edu>
  6. Sender: news@athena.mit.edu (News system)
  7. Nntp-Posting-Host: m37-332-5.mit.edu
  8. Organization: Massachusetts Institute of Technology
  9. Date: Thu, 27 Aug 1992 16:33:29 GMT
  10. Lines: 251
  11.  
  12. Some time back i had posted a question regarding complex variable manipulations
  13. in mathematica. someone sent me mail requesting that i put together the various
  14. responses and post them here so that other people could also read them. here they
  15. are:
  16.  
  17. my initial post:
  18.  
  19. >     Subject: mathematica question- using complex symbols
  20. >     Message-Id: <1992Aug11.202102.14808@athena.mit.edu>
  21. >     Organization: Massachusetts Institute of Technology
  22. >     Status: R
  23. >     I have been trying to manipulate complex symbols
  24. >                          ^^^^^^^^ 
  25. >     (as opposed to complex numbers) using mathematica.  I had expected
  26. >     mathematica to be able to simplify expressions containing complex
  27. >     symbols the same way it simplifies complex number expressions.
  28. >     for example, if we do     z= 3+ 4 I    , and then compute 
  29. >     z*Conjugate[z], the answer output will be 25. but on the other hand,
  30. >     if we do      z=x + I y    and then compute z*Conjugate[z], mathematica,
  31. >     instead of giving the desired answer x^2 + y^2, outputs something like
  32. >     (I x + y)*Conjugate(I x + y). i.e. it refuses to simplify the complex
  33. >     expression.
  34. >     i am wondering if it is possible to get around this problem. i am going
  35. >     to to be using long expressions containing many complex symbols, and would 
  36. >     like to get the final answer as a sum of one real part and one imaginary
  37. >     part. i am a relatively inexperienced user of this software (and am using it
  38. it
  39. >     only for some very specific purposes)- so any suggestion will be greatly
  40. >     appreciated. thanks.
  41. >     saurav bhatta
  42. >     (bhattas@presto.mit.edu)
  43.  
  44. The suggestions:
  45.  
  46. 1.From: Tony Coates <coates@newton.physics.uq.oz.au>
  47. I have some code which allows you to declare variables to be real,
  48. and then takes care of them when you do operations like 'Conjugate'
  49. and the like.  If you are interested, I can email you a copy of it.
  50.  
  51.                             Tony.
  52. _______________________________________________________________________________
  53.  
  54. A.B.Coates (Tony)
  55. Department of Physics
  56. The University of Queensland  QLD  4072
  57. Australia
  58.  
  59. Phone: (+617)365 3424           (Physics Departmental Office)
  60. Fax:   (+617)365 1242           (   "         "         "   )
  61. Email: coates@physics.uq.oz.au
  62.  
  63. "My messages mirror my feelings, but do not reflect University policy."
  64.  
  65.  
  66. 2.From: dabell@dabell-next.umd.edu (Dan T. Abell 
  67. Pick up a copy of Roman Maeder's book Programming in Mathematica.   
  68. See p. 42 of the second edition and his dicussion of the package  
  69. ReIm.m.  This is the most elegant solution I know of.  Good Luck. 
  70.  
  71.  
  72. --
  73.    ---  __o       Dan T. Abell  (dabell@dabell-next.umd.edu)
  74. ----  _`\<,_      Department of Physics, University of Maryland
  75.  --- (*)/ (*)     College Park, MD  20742
  76.  
  77.  
  78. 3.From: John Novak <novak@wri.com>
  79. The following should work:
  80. (* Load the ReIm package, for manipulations of real valued variables. *)
  81. In[1] := <<Algebra`ReIm`
  82.  
  83. (* set x and y to be only real valued (set imaginary parts equal to zero) *)
  84. In[2] := x/: Im[x] = 0; y/: Im[y] = 0;
  85.  
  86. (* a calculation *)
  87. In[3] := (x + I y) Conjugate[x + I y]
  88.  
  89. Out[3] = (x - I y) (x + I y)
  90.  
  91. In[4] := Expand[%]
  92.  
  93.           2    2
  94. Out[4] = x  + y
  95.  
  96. Hope this helps you!
  97. Please direct further requests for assistance to
  98. support@wri.com
  99. Please include your license number in your request.
  100. --John Novak
  101. -----------------------------------------------------------------------
  102. John M. Novak                                           novak@wri.com
  103. Wolfram Research, Inc.
  104.  
  105.  
  106. 4. From: stefan@cs.cornell.edu (Kjartan Stefansson)
  107. Somebody has posted a working solution, and somebody has also
  108. posted an explanation why mathematica doesn't simplify things for
  109. you.  Here is a code that allows you to have your own versions of
  110. re and im, and it doesn't munge with any internal functions.
  111.  
  112. If you want your expression simplified your way, you can either use
  113.  
  114. makereal[expression,{x1,x2,...}]
  115.  
  116. where x1, etc  are taken to be real.  A simpler version is
  117.  
  118. makereal[exp]
  119.  
  120. which takes all symbols to be real variables.
  121.  
  122. --------------------------------------------------
  123. conjugate[x_] := re[x]- I im[x];
  124. re[a_+b_] := re[a]+re[b];
  125. re[a_*b_] := re[a]*re[b]-im[a]*im[b];
  126. im[a_+b_] := im[a]+im[b];
  127. im[a_*b_] := re[a]*im[b]+re[b]*im[a];
  128. im[a_Real] := 0;
  129. im[I] := 1;
  130. im[a_Complex] := Im[a];
  131. im[a_Number] := Im[a];
  132. im[a_Integer] := Im[a];
  133. re[a_Real] := a;
  134. re[I] := 0;
  135. re[a_Complex] := Re[a];
  136. re[a_Number] := Re[a];
  137. re[a_Integer] := Re[a];
  138.  
  139. refy[x_] := {re[x]->x,im[x]->0};
  140.  
  141. makereal[exp_] := makereal[exp,Variables[exp/. im[x_]->x /. re[x_] -> x]];
  142. makereal[exp_,varlist_] := exp /. Flatten[Map[refy,varlist]];
  143. --------------------------------------------------
  144.  
  145. This seems simpler than some of the things posted.
  146.  
  147. Kjartan Stefansson
  148. (stefan@cs.cornell.edu)
  149.  
  150. 5.From: rayes@mcs.kent.edu (Mohamed Omar Rayes) 
  151. I do not know to what extent MATHEMATICA can handle complex symbols.
  152. Most of the existing algebra systems know very little about complex 
  153. arithmetic. In your case, the Conjugate function  appearently
  154. does not know how to handle symbols as opposed to numbers. Here at
  155. kent, we have written a complex number package that can be attached
  156. to MACSYMA to handel complex number arithmetic. Feel free to obtain
  157. a copy via anonymous ftp from hp3.mcs.kent.edu /pub/complex.tar.Z.
  158. Enjoy and best regards,
  159. Mohamed.
  160.  
  161. 6.From: aal@cfdlab.ae.utexas.edu (Alfred LorberFrom: aal@cfdlab.ae.utexas.edu (Alfred Lorber
  162. I too have had the same problems.  I have found that ample usage of
  163. ComplexExpand seems to help.  At the bottom of this message is a copy
  164. of an example session I keep around to remind myself how to do complex
  165. symbolic work in Mathematica.  I hope it helps.  In a few weeks if you
  166. could post on sci.math.symbolic a summary of what people told you
  167. about complex symbolic manipulation, I think it would be of great help
  168. to a number of people.
  169.  
  170. -Alfred
  171. ------------------------------------------------------
  172.  
  173. In[1]:= g = (a + b + c) - I(a^2 + b^2d)
  174.  
  175.                         2    2
  176. Out[1]= a + b + c - I (a  + b  d)
  177.  
  178. In[2]:= Conjugate[%]
  179.  
  180.                                   2    2
  181. Out[2]= Conjugate[a + b + c - I (a  + b  d)]
  182.  
  183. In[3]:= ComplexExpand[%]
  184.  
  185.                         2    2
  186. Out[3]= a + b + c + I (a  + b  d)
  187.  
  188. In[4]:= gcon = %
  189.  
  190.                         2    2
  191. Out[4]= a + b + c + I (a  + b  d)
  192.  
  193. In[5]:= g*gcon
  194.  
  195.                          2    2                      2    2
  196. Out[5]= (a + b + c - I (a  + b  d)) (a + b + c + I (a  + b  d))
  197.  
  198. In[6]:= ComplexExpand[%]
  199.  
  200.                    2      2    2      2    2
  201. Out[6]= (a + b + c)  - (-a  - b  d) (a  + b  d) +
  202. >    I ((a + b + c) (-a  - b  d) + (a + b + c) (a  + b  d))
  203.  
  204. In[9]:= Simplify[%6]
  205.  
  206.                    2     2    2   2
  207. Out[9]= (a + b + c)  + (a  + b  d)
  208.  
  209. In[10]:= ComplexExpand[Re[%3]]
  210.  
  211. Out[10]= a + b + c
  212.  
  213. In[11]:= ComplexExpand[Im[%3]]
  214.  
  215.           2    2
  216. Out[11]= a  + b  d
  217.  
  218. In[12]:= g
  219.  
  220.                          2    2
  221. Out[12]= a + b + c - I (a  + b  d)
  222.  
  223. In[13]:= ComplexExpand[Abs[g]] % <-- Doesn't seem to work, thus need to do
  224.                                      stuff with Congegate shown above.
  225.  
  226.                              2    2
  227. Out[13]= Abs[a + b + c - I (a  + b  d)]
  228.  
  229. In[14]:= ?*Abs*
  230. Abs               AbsolutePointSize AbsoluteThickness AbsoluteTime
  231. AbsoluteDashing
  232.  
  233. In[14]:= ?Abs
  234. Abs[z] gives the absolute value of the real or complex number z.
  235.  
  236.  
  237.  
  238. --
  239. -----------------------------------------------------------------------
  240. Alfred Lorber (aal@cfdlab.ae.utexas.edu) | "It occurs to us that the
  241.                                          | majority of our problems are
  242. Computational Fluid Dynamics Laboratory  | caused by workers that don't
  243. Dept. of Aerospace Eng. & Eng. Mechanics | think, and thinkers that 
  244. The University of Texas at Austin        | don't work"
  245. Austin, Texas  78712      (512) 471-4069 |        -- West Texas saying
  246.                                          | 
  247.         \\_____/===\_____//              | 
  248.              --0\ /0--                   | 
  249.                 (@)                      | 
  250. -----------------------------------------------------------------------
  251.  
  252.  
  253. saurav
  254.  
  255.  
  256.  
  257.