1
$\begingroup$

How can I extract amplitudes and angles as separate lists from an trigonometric expression?

Sample input:

$$A_{1} \cos \left(\phi -\frac{2 \pi }{3}\right)+ A_{2} \cos \left(2 \phi +\frac{\pi }{3}\right)+ A_{3} \cos \left(3 \phi -\frac{\pi }{2}\right)$$

A1 Cos[ϕ - 2 Pi/3] + A2 Cos[2 ϕ + Pi/3] + A3 Cos[3 ϕ - Pi/2]

Desired outputs:

  1. List of amplitudes: $[A_{1}, A_{2}, A_{3}]$ , {A1,A2,A3}

  2. List of angles: $[\phi -\frac{2 \pi}{3}, 2 \phi +\frac{\pi}{3}, 3 \phi -\frac{\pi}{2}]$ {ϕ - 2 Pi/3,2 ϕ + Pi/3,3 ϕ - Pi/2}

$\endgroup$
0

2 Answers 2

3
$\begingroup$
exp = A1 Cos[ϕ - 2 Pi/3] + A2 Cos[2 ϕ + Pi/3] + A3 Cos[3 ϕ - Pi/2] // HoldForm

{amplitudes, angles} = Transpose[exp /. {Plus -> List} /. {A_*Cos[phi_] :> {A, 
     Total@phi}} // ReleaseHold]
(*{{A1, A2, A3}, {-((2 π)/3) + ϕ, π/3 + 2 ϕ, -(π/2) + 3 ϕ}}*)
$\endgroup$
0
$\begingroup$
exp = Sum[ RandomReal[] Cos[RandomReal[] ϕ + RandomReal[]], {k, 10}]
0.58841 Cos[0.255484 + 0.116817 ϕ] + 
 0.410137 Cos[0.606744 + 0.187887 ϕ] + 
 0.0087033 Cos[0.267439 + 0.220191 ϕ] + 
 0.231662 Cos[0.389939 + 0.232118 ϕ] + 
 0.851933 Cos[0.0605113 + 0.275988 ϕ] + 
 0.127151 Cos[0.724798 + 0.316905 ϕ] + 
 0.587836 Cos[0.0236456 + 0.371794 ϕ] + 
 0.453645 Cos[0.459396 + 0.440963 ϕ] + 
 0.55557 Cos[0.623873 + 0.71966 ϕ] + 
 0.588512 Cos[0.0700004 + 0.939417 ϕ]
{amplitudes, angles} = Transpose@Cases[exp, Times[a_, Cos[b_]] ->  {a, b}]

OR

ReplaceAll[List @@ exp,
 {
  Times[a_, Sin[b_]] -> {a, π/2 - b},
  Times[a_, Cos[b_]] -> {a, b}
  }]
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.