home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: sci.math.symbolic
- Path: sparky!uunet!snorkelwacker.mit.edu!bloom-picayune.mit.edu!athena.mit.edu!bhattas
- From: bhattas@athena.mit.edu (Saurav D Bhatta)
- Subject: RE: mathematica-complex variables
- Message-ID: <1992Aug27.163329.15675@athena.mit.edu>
- Sender: news@athena.mit.edu (News system)
- Nntp-Posting-Host: m37-332-5.mit.edu
- Organization: Massachusetts Institute of Technology
- Date: Thu, 27 Aug 1992 16:33:29 GMT
- Lines: 251
-
- Some time back i had posted a question regarding complex variable manipulations
- in mathematica. someone sent me mail requesting that i put together the various
- responses and post them here so that other people could also read them. here they
- are:
-
- my initial post:
-
- > Subject: mathematica question- using complex symbols
- > Message-Id: <1992Aug11.202102.14808@athena.mit.edu>
- > Organization: Massachusetts Institute of Technology
- > Status: R
- >
- > I have been trying to manipulate complex symbols
- > ^^^^^^^^
- > (as opposed to complex numbers) using mathematica. I had expected
- > mathematica to be able to simplify expressions containing complex
- > symbols the same way it simplifies complex number expressions.
- > for example, if we do z= 3+ 4 I , and then compute
- > z*Conjugate[z], the answer output will be 25. but on the other hand,
- > if we do z=x + I y and then compute z*Conjugate[z], mathematica,
- > instead of giving the desired answer x^2 + y^2, outputs something like
- > (I x + y)*Conjugate(I x + y). i.e. it refuses to simplify the complex
- > expression.
- >
- > i am wondering if it is possible to get around this problem. i am going
- > to to be using long expressions containing many complex symbols, and would
- > like to get the final answer as a sum of one real part and one imaginary
- > part. i am a relatively inexperienced user of this software (and am using it
- it
- > only for some very specific purposes)- so any suggestion will be greatly
- > appreciated. thanks.
- >
- >
- > saurav bhatta
- > (bhattas@presto.mit.edu)
- >
- >
-
- The suggestions:
-
- 1.From: Tony Coates <coates@newton.physics.uq.oz.au>
- I have some code which allows you to declare variables to be real,
- and then takes care of them when you do operations like 'Conjugate'
- and the like. If you are interested, I can email you a copy of it.
-
- Tony.
- _______________________________________________________________________________
-
- A.B.Coates (Tony)
- Department of Physics
- The University of Queensland QLD 4072
- Australia
-
- Phone: (+617)365 3424 (Physics Departmental Office)
- Fax: (+617)365 1242 ( " " " )
- Email: coates@physics.uq.oz.au
-
- "My messages mirror my feelings, but do not reflect University policy."
-
-
- 2.From: dabell@dabell-next.umd.edu (Dan T. Abell
- Pick up a copy of Roman Maeder's book Programming in Mathematica.
- See p. 42 of the second edition and his dicussion of the package
- ReIm.m. This is the most elegant solution I know of. Good Luck.
-
-
- --
- --- __o Dan T. Abell (dabell@dabell-next.umd.edu)
- ---- _`\<,_ Department of Physics, University of Maryland
- --- (*)/ (*) College Park, MD 20742
-
-
- 3.From: John Novak <novak@wri.com>
- The following should work:
- (* Load the ReIm package, for manipulations of real valued variables. *)
- In[1] := <<Algebra`ReIm`
-
- (* set x and y to be only real valued (set imaginary parts equal to zero) *)
- In[2] := x/: Im[x] = 0; y/: Im[y] = 0;
-
- (* a calculation *)
- In[3] := (x + I y) Conjugate[x + I y]
-
- Out[3] = (x - I y) (x + I y)
-
- In[4] := Expand[%]
-
- 2 2
- Out[4] = x + y
-
- Hope this helps you!
- Please direct further requests for assistance to
- support@wri.com
- Please include your license number in your request.
- --John Novak
- -----------------------------------------------------------------------
- John M. Novak novak@wri.com
- Wolfram Research, Inc.
-
-
- 4. From: stefan@cs.cornell.edu (Kjartan Stefansson)
- Somebody has posted a working solution, and somebody has also
- posted an explanation why mathematica doesn't simplify things for
- you. Here is a code that allows you to have your own versions of
- re and im, and it doesn't munge with any internal functions.
-
- If you want your expression simplified your way, you can either use
-
- makereal[expression,{x1,x2,...}]
-
- where x1, etc are taken to be real. A simpler version is
-
- makereal[exp]
-
- which takes all symbols to be real variables.
-
- --------------------------------------------------
- conjugate[x_] := re[x]- I im[x];
- re[a_+b_] := re[a]+re[b];
- re[a_*b_] := re[a]*re[b]-im[a]*im[b];
- im[a_+b_] := im[a]+im[b];
- im[a_*b_] := re[a]*im[b]+re[b]*im[a];
- im[a_Real] := 0;
- im[I] := 1;
- im[a_Complex] := Im[a];
- im[a_Number] := Im[a];
- im[a_Integer] := Im[a];
- re[a_Real] := a;
- re[I] := 0;
- re[a_Complex] := Re[a];
- re[a_Number] := Re[a];
- re[a_Integer] := Re[a];
-
- refy[x_] := {re[x]->x,im[x]->0};
-
- makereal[exp_] := makereal[exp,Variables[exp/. im[x_]->x /. re[x_] -> x]];
- makereal[exp_,varlist_] := exp /. Flatten[Map[refy,varlist]];
- --------------------------------------------------
-
- This seems simpler than some of the things posted.
-
- Kjartan Stefansson
- (stefan@cs.cornell.edu)
-
- 5.From: rayes@mcs.kent.edu (Mohamed Omar Rayes)
- I do not know to what extent MATHEMATICA can handle complex symbols.
- Most of the existing algebra systems know very little about complex
- arithmetic. In your case, the Conjugate function appearently
- does not know how to handle symbols as opposed to numbers. Here at
- kent, we have written a complex number package that can be attached
- to MACSYMA to handel complex number arithmetic. Feel free to obtain
- a copy via anonymous ftp from hp3.mcs.kent.edu /pub/complex.tar.Z.
- Enjoy and best regards,
- Mohamed.
-
- 6.From: aal@cfdlab.ae.utexas.edu (Alfred LorberFrom: aal@cfdlab.ae.utexas.edu (Alfred Lorber
- I too have had the same problems. I have found that ample usage of
- ComplexExpand seems to help. At the bottom of this message is a copy
- of an example session I keep around to remind myself how to do complex
- symbolic work in Mathematica. I hope it helps. In a few weeks if you
- could post on sci.math.symbolic a summary of what people told you
- about complex symbolic manipulation, I think it would be of great help
- to a number of people.
-
- -Alfred
- ------------------------------------------------------
-
- In[1]:= g = (a + b + c) - I(a^2 + b^2d)
-
- 2 2
- Out[1]= a + b + c - I (a + b d)
-
- In[2]:= Conjugate[%]
-
- 2 2
- Out[2]= Conjugate[a + b + c - I (a + b d)]
-
- In[3]:= ComplexExpand[%]
-
- 2 2
- Out[3]= a + b + c + I (a + b d)
-
- In[4]:= gcon = %
-
- 2 2
- Out[4]= a + b + c + I (a + b d)
-
- In[5]:= g*gcon
-
- 2 2 2 2
- Out[5]= (a + b + c - I (a + b d)) (a + b + c + I (a + b d))
-
- In[6]:= ComplexExpand[%]
-
- 2 2 2 2 2
- Out[6]= (a + b + c) - (-a - b d) (a + b d) +
- > I ((a + b + c) (-a - b d) + (a + b + c) (a + b d))
-
- In[9]:= Simplify[%6]
-
- 2 2 2 2
- Out[9]= (a + b + c) + (a + b d)
-
- In[10]:= ComplexExpand[Re[%3]]
-
- Out[10]= a + b + c
-
- In[11]:= ComplexExpand[Im[%3]]
-
- 2 2
- Out[11]= a + b d
-
- In[12]:= g
-
- 2 2
- Out[12]= a + b + c - I (a + b d)
-
- In[13]:= ComplexExpand[Abs[g]] % <-- Doesn't seem to work, thus need to do
- stuff with Congegate shown above.
-
- 2 2
- Out[13]= Abs[a + b + c - I (a + b d)]
-
- In[14]:= ?*Abs*
- Abs AbsolutePointSize AbsoluteThickness AbsoluteTime
- AbsoluteDashing
-
- In[14]:= ?Abs
- Abs[z] gives the absolute value of the real or complex number z.
-
-
-
- --
- -----------------------------------------------------------------------
- Alfred Lorber (aal@cfdlab.ae.utexas.edu) | "It occurs to us that the
- | majority of our problems are
- Computational Fluid Dynamics Laboratory | caused by workers that don't
- Dept. of Aerospace Eng. & Eng. Mechanics | think, and thinkers that
- The University of Texas at Austin | don't work"
- Austin, Texas 78712 (512) 471-4069 | -- West Texas saying
- |
- \\_____/===\_____// |
- --0\ /0-- |
- (@) |
- -----------------------------------------------------------------------
-
-
- saurav
-
-
-
-