MathGroup Archive 1998

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

Search the Archive

Questions about "collecting" complex exponentials and simplifying expressions


  • To: mathgroup@smc.vnet.net
  • Subject: [mg12066] Questions about "collecting" complex exponentials and simplifying expressions
  • From: Wretch <arc@astro.columbia.edu>
  • Date: Fri, 24 Apr 1998 01:52:36 -0400
  • Organization: Vacuum

I'm trying to get mathematica to help me out with some extremely tedious
algebra, and my problems are 

1) Getting it to understand which functions and variables are complex
   or real

2) Getting mathematica to group terms in a way I like.  


Here is the specific problem.  A common approach in perturbation theory
for "weakly nonlinear systems" is to look for slowly varying wavepacket
solutions to nasty sets of nonlinear PDEs.

Specifically, consider the lowest order ansatz for one of the 
variables,

Y = A(X1,X2,...,T1,T2,...) Exp[I(omega t - kx)] + c.c.

The complex amplitude function A has dependence on the SLOW Variables
(Xj,Tj) while the exponential takes care of the fast wave variation.

What I want to do is to simplify expressions like Y^2, Y^3 by getting
mathematica to effect the multiplications and then group  terms
according to the harmonics arising from the Exp function.

For instance, the quadratic term Y^2 would be

Y^2 = (A^2 Exp[2 I(omega t - k x)]+c.c.) + 2 |A|^2

where |A|^2 = A Conjugate[A]  in mathematica lingo.

************************************************************* MY
PROBLEMS:

1) Getting mathematica to write expressions like A Conjugate[A]
   rather than ugly versions that expand
  (Re[A]+I Im[A])(Re[Conjugate[A]]+I Im[Conjugate[A]])

2) How do I tell mathematica to "Collect" in terms of the
   various Exp[j I(omega t - k x)] harmonics?
*************************************************************

My naive approach was as follows (Mathematica Script).  Note that the
function below is slightly more complicated than the Y I gave  above.

Y=A[x1,x2,t1,t2] e1+B[x1,x2,t1,t2] e2+
    Conjugate[A[x1,x2,t1,t2] e1+B[x1,x2,t1,t2] e2]

NOTE: e1=Exp[I(omega t - k x)] , e2=Exp[2 I(omega t - k x)]

I first tried the ComplexExpand function, taking care to specify that
A,B are complex:

*************************************************************
ComplexExpand[rho11^2,{A[x1,x2,t1,t2],B[x1,x2,t1,t2]}]
*************************************************************

which yielded the gruesome mess in terms of Cos and Sin (unwanted):
(SORRY FOR THE INTERNAL CODE PRESENTED HERE)
************************************************************* \!\(4\
Cos[k\ x - t\ \[Omega]]\^2\ Re[A[X\_1, X\_2, T\_1, T\_2]]\^2 + 
    8\ Cos[k\ x - t\ \[Omega]]\ Cos[2\ \((\(-k\)\ x + t\ \[Omega])\)]\ 
      Re[A[X\_1, X\_2, T\_1, T\_2]]\ Re[B[X\_1, X\_2, T\_1, T\_2]] + 
    4\ Cos[2\ \((\(-k\)\ x + t\ \[Omega])\)]\^2\ 
      Re[B[X\_1, X\_2, T\_1, T\_2]]\^2 + 
    8\ Cos[k\ x - t\ \[Omega]]\ Im[A[X\_1, X\_2, T\_1, T\_2]]\ 
      Re[A[X\_1, X\_2, T\_1, T\_2]]\ Sin[k\ x - t\ \[Omega]] + 
    8\ Cos[2\ \((\(-k\)\ x + t\ \[Omega])\)]\ Im[A[X\_1, X\_2, T\_1,
T\_2]]\ 
      Re[B[X\_1, X\_2, T\_1, T\_2]]\ Sin[k\ x - t\ \[Omega]] + 
    4\ Im[A[X\_1, X\_2, T\_1, T\_2]]\^2\ Sin[k\ x - t\ \[Omega]]\^2 - 
    8\ Cos[k\ x - t\ \[Omega]]\ Im[B[X\_1, X\_2, T\_1, T\_2]]\ 
      Re[A[X\_1, X\_2, T\_1, T\_2]]\ Sin[2\ \((\(-k\)\ x + t\
\[Omega])\)] - 
    8\ Cos[2\ \((\(-k\)\ x + t\ \[Omega])\)]\ Im[B[X\_1, X\_2, T\_1,
T\_2]]\ 
      Re[B[X\_1, X\_2, T\_1, T\_2]]\ Sin[2\ \((\(-k\)\ x + t\
\[Omega])\)] - 
    8\ Im[A[X\_1, X\_2, T\_1, T\_2]]\ Im[B[X\_1, X\_2, T\_1, T\_2]]\ 
      Sin[k\ x - t\ \[Omega]]\ Sin[2\ \((\(-k\)\ x + t\ \[Omega])\)] + 
    4\ Im[B[X\_1, X\_2, T\_1, T\_2]]\^2\ 
      Sin[2\ \((\(-k\)\ x + t\ \[Omega])\)]\^2\)


I then tried to simplify the above using the TrigToExp command, which
resulted in something even more hideous,


TrigToExp[ComplexExpand[rho11^2,{A[x1,x2,t1,t2],B[x1,x2,t1,t2]}]]


\!\(\(-\((\(-E\^\(I\ k\ x - I\ t\ \[Omega]\)\) + 
              E\^\(\(-I\)\ k\ x + I\ t\ \[Omega]\))\)\^2\)\ 
      Im[A[X\_1, X\_2, T\_1, T\_2]]\^2 + 
    2\ \((\(-E\^\(I\ k\ x - I\ t\ \[Omega]\)\) + 
          E\^\(\(-I\)\ k\ x + I\ t\ \[Omega]\))\)\ 
      \((E\^\(\(-2\)\ I\ \((\(-k\)\ x + t\ \[Omega])\)\) - 
          E\^\(2\ I\ \((\(-k\)\ x + t\ \[Omega])\)\))\)\ 
      Im[A[X\_1, X\_2, T\_1, T\_2]]\ Im[B[X\_1, X\_2, T\_1, T\_2]] - 
    \((E\^\(\(-2\)\ I\ \((\(-k\)\ x + t\ \[Omega])\)\) - 
            E\^\(2\ I\ \((\(-k\)\ x + t\ \[Omega])\)\))\)\^2\ 
      Im[B[X\_1, X\_2, T\_1, T\_2]]\^2 + 
    2\ I\ \((\(-E\^\(I\ k\ x - I\ t\ \[Omega]\)\) + 
        E\^\(\(-I\)\ k\ x + I\ t\ \[Omega]\))\)\ 
      \((E\^\(I\ k\ x - I\ t\ \[Omega]\) + 
          E\^\(\(-I\)\ k\ x + I\ t\ \[Omega]\))\)\ 
      Im[A[X\_1, X\_2, T\_1, T\_2]]\ Re[A[X\_1, X\_2, T\_1, T\_2]] - 
    2\ I\ \((E\^\(I\ k\ x - I\ t\ \[Omega]\) + 
        E\^\(\(-I\)\ k\ x + I\ t\ \[Omega]\))\)\ 
      \((E\^\(\(-2\)\ I\ \((\(-k\)\ x + t\ \[Omega])\)\) - 
          E\^\(2\ I\ \((\(-k\)\ x + t\ \[Omega])\)\))\)\ 
      Im[B[X\_1, X\_2, T\_1, T\_2]]\ Re[A[X\_1, X\_2, T\_1, T\_2]] + 
    \((E\^\(I\ k\ x - I\ t\ \[Omega]\) + E\^\(\(-I\)\ k\ x + I\ t\
\[Omega]\))
          \)\^2\ Re[A[X\_1, X\_2, T\_1, T\_2]]\^2 + 
    2\ I\ \((\(-E\^\(I\ k\ x - I\ t\ \[Omega]\)\) + 
        E\^\(\(-I\)\ k\ x + I\ t\ \[Omega]\))\)\ 
      \((E\^\(\(-2\)\ I\ \((\(-k\)\ x + t\ \[Omega])\)\) + 
          E\^\(2\ I\ \((\(-k\)\ x + t\ \[Omega])\)\))\)\ 
      Im[A[X\_1, X\_2, T\_1, T\_2]]\ Re[B[X\_1, X\_2, T\_1, T\_2]] - 
    2\ I\ \((E\^\(\(-2\)\ I\ \((\(-k\)\ x + t\ \[Omega])\)\) - 
        E\^\(2\ I\ \((\(-k\)\ x + t\ \[Omega])\)\))\)\ 
      \((E\^\(\(-2\)\ I\ \((\(-k\)\ x + t\ \[Omega])\)\) + 
          E\^\(2\ I\ \((\(-k\)\ x + t\ \[Omega])\)\))\)\ 
      Im[B[X\_1, X\_2, T\_1, T\_2]]\ Re[B[X\_1, X\_2, T\_1, T\_2]] + 
    2\ \((E\^\(I\ k\ x - I\ t\ \[Omega]\) + 
          E\^\(\(-I\)\ k\ x + I\ t\ \[Omega]\))\)\ 
      \((E\^\(\(-2\)\ I\ \((\(-k\)\ x + t\ \[Omega])\)\) + 
          E\^\(2\ I\ \((\(-k\)\ x + t\ \[Omega])\)\))\)\ 
      Re[A[X\_1, X\_2, T\_1, T\_2]]\ Re[B[X\_1, X\_2, T\_1, T\_2]] + 
    \((E\^\(\(-2\)\ I\ \((\(-k\)\ x + t\ \[Omega])\)\) + 
            E\^\(2\ I\ \((\(-k\)\ x + t\ \[Omega])\)\))\)\^2\ 
      Re[B[X\_1, X\_2, T\_1, T\_2]]\^2\)+ t\ \
*************************************************************

So, somehow I need to tell mathematica to write stuff like

A Conjugate[B]

rather than all the Im[A], Re[A], etc. stuff, which is real ugly.

How do I do this?


I apologize for the length of this message, but I just wanted to be as
clear as possible by outlining this specific example.

Thanks for any help,

Alex



  • Prev by Date: Re: Newbie needs help with 3D plot
  • Next by Date: Re: running calculations in a batch mode
  • Prev by thread: Q. about Solve as applied to vector equations
  • Next by thread: Very odd behaviour in Mod/N