MathGroup Archive 2004

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Extracting Real Parts from NN Expression

  • To: mathgroup at smc.vnet.net
  • Subject: [mg51178] Re: [mg51149] Extracting Real Parts from NN Expression
  • From: Murray Eisenberg <murray at math.umass.edu>
  • Date: Thu, 7 Oct 2004 05:26:04 -0400 (EDT)
  • Organization: Mathematics & Statistics, Univ. of Mass./Amherst
  • References: <200410060834.EAA24222@smc.vnet.net>
  • Reply-to: murray at math.umass.edu
  • Sender: owner-wri-mathgroup at wolfram.com

Again here, what's wrong with

   realPart[z_] := ComplexExpand[Re[z]]

??

In general, I would always prefer to use (or at least first try to use) 
build in functions more or less directly, rather than devise my own. 
Why?  Because I trust the Mathematica designers to have thought through 
more carefully than I how general their functions are, etc., and because 
presumably the more direct built-in will be more efficient (when that 
matters).  Thus, while I don't know what how the built-in composition of 
ComplexExpand and Re is implemented (for all I know there could be 
special code!), your definition of RealPart requires computation of a 
conjugate and then an addition, at the level of the interpreter.

On the other hand, your definition of RealPart is an interesting 
exercise for students learning about complex numbers!  "Teaching the 
computer" how to do something is often an effective way of learning it 
oneself.


Carlos Felippa wrote:
> Thank you very much to those who replied to early posts on the subject
> title and help me fix several mistakes.  Finally got a robust
> extraction function that has worked on a series of problems:
> 
> RealPart[c_]:=ComplexExpand[(c+Conjugate[c])/2,TargetFunctions->{Re,Im}];
> 
> I used this in expressions such as
> Solve[RealPart[expr]==0,{unknowns}], in which expr is a complicated
> nonnumeric complex-valued expression, to solve some stability
> transition problems in C&G.  (If the real part becomes positive
> stability is lost).
> 
> To see what happens with built-in Re[], a simple example is
> instructive:
> 
>   expr=x^2-a^2+2*I*x*y;
> 
>   Print[    Solve[Re[expr]==0,x]        //InputForm];
>   Solve returns unevaluated
> 
>   Print[    Solve[RealPart[expr]==0,x]  //InputForm];
>   {{x -> -a}, {x -> a}}
> 
> Note: a similar imaginary part extractor 
> 
> ImagPart[c_]:=ComplexExpand[-I*(c-Conjugate[c])/2,TargetFunctions->{Re,Im}];
> 
> is still iffy, but I dont need it for my application.  It could
> certainly be improved.
> 
> 
> 

-- 
Murray Eisenberg                     murray at math.umass.edu
Mathematics & Statistics Dept.
Lederle Graduate Research Tower      phone 413 549-1020 (H)
University of Massachusetts                413 545-2859 (W)
710 North Pleasant Street            fax   413 545-1801
Amherst, MA 01003-9305


  • Prev by Date: Re: Conveniently Restarting Notebooks
  • Next by Date: Re: Integrating Feynman integrals in mathematica
  • Previous by thread: Re: Extracting Real Parts from NN Expression
  • Next by thread: recover a value in module at the end