MathGroup Archive 2011

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

Search the Archive

Re: Coefficents of terms in an expression containing the matching string

  • To: mathgroup at smc.vnet.net
  • Subject: [mg118005] Re: Coefficents of terms in an expression containing the matching string
  • From: Bill Rowe <readnews at sbcglobal.net>
  • Date: Fri, 8 Apr 2011 04:14:23 -0400 (EDT)

On 4/7/11 at 8:05 AM, chelly85086 at gmail.com (Chelly) wrote:

>I have two questions. The solutions may be very simple, but since I
>am a Mathematica novice, need some guidance.

>1) I have an expression:

>y = 0.5*u*exp(-2 I d1 - d2 - I d4 - phi) -
>0.5*k2*k3*u*exp(-I d2 - I d4 - phi) - 0.5*k2*k4*u*exp(-I d2 - Id 3 -
>I phi) ;

I will assume you really want y defined as follows:

y = 0.5*u*Exp[-2 I d1 - d2 - I d4 - phi] -
    0.5*k2*k3*u*Exp[-I d2 - I d4 - phi] -
    0.5*k2*k4*u*Exp[-I d2 - Id 3 - I phi];

That is I assume you intend exp to be the function Exp not a
variable named exp. Mathematica is case sensitive. All built-in
functions start with an uppercase letter. Any thing starting
with a lowercase letter is something you have created and will
simply be seen as a variable with no assignment by Mathematica
until you define it. Additionally, parantheses, (), are used
only for grouping in Mathematica. So, exp(....) would be seen by
Mathematica as the variable exp times the stuff inside the
parantheses. In Mathematica, functional arguments are set off
with square brackets [].

>What command should I use to get just the amplitude of each term,
>i.e excluding the exponential - exp(). In this case, the results
>needs to be {0.5*u, 0.5*k2*k3*u, 0.5*k2*k4*u)

You can get this result with:

In[4]:= (List @@ y) /. Exp[_] -> Sequence[]

Out[4]= {0.5 u,-0.5 k2 k3 u,-0.5 k2 k4 u}

What I've done here, is convert the expression stored in y to a
list, then used pattern matching to make the Exp stuff
disappear. Strictly speaking, this is not a mathematical
transform. Nor will it be simple to get the result you want with
Mathematica using just mathematical transforms. By default,
Mathematica assumes undefined variables are complex. So, from
Mathematica's perspective y could be purely imaginary, i.e., no
amplitude term. And if I assume all undefined variables are
real, then the first amplitude term should be

0.5*u*Exp[-d2 - phi]

rather than what you said you wanted.

>2) The second question is along similar lines. I have an expression
>and I need to find out the terms that have k2^2 in the amplitude

>y = 0.5*u*exp(-2 I d1 - d2 - I d4 - phi) -
>0.5*k2^2*k3*u*exp(-I d2 - I d4 - phi) - 0.5*k2*k4*u*exp(-I d2 - Id 3
>- I phi)  - 0.5*k2^2*k5*v*exp(-I d2 - Id 3 - I phi) ;

>In this case, the answer is the second and last term:
>0.5*k2^2*k3*u*exp(-I d2 - I d4 - phi) -
>0.5*k2^2*k5*v*exp(-I d2 - Id 3 - I phi)

This can be achieved as:

In[5]:= Plus @@ DeleteCases[List @@ y, _?(FreeQ[#, k2] &)]

Out[5]= -(0.5*k2*k3*u*E^(-(I*d2) - I*d4 - phi)) -
    0.5*k2*k4*u*E^(-(I*d2) - 3*Id - I*phi)

Here the List@@y converts y to a list of terms rather than a
sum. The DeleteCases[... _?(FreeQ[... part deletes all terms
from the list that do not contain k2. Finally, the Plus@@part
reconstitutes the sum.



  • Prev by Date: Re: Picking certain values from an array of solutions
  • Next by Date: Re: why extending numbers by zeros instead of dropping precision
  • Previous by thread: Re: Coefficents of terms in an expression containing the matching string
  • Next by thread: Re: Coefficents of terms in an expression containing the matching string