I'm wondering if there's a nice way to convert only parts of an expression, say exponential functions of varible $\theta$ to trig. The motivation is best descripbed by the following example.

DSolve[{{-(1/2) I \[Theta] b[t] (I Cos[\[Phi]] + Sin[\[Phi]]), -(1/2)
   E^(I \[Phi]) \[Theta] a[t]} == {a'[t], b'[t]}, a[0] == a0, 
   b[0] == b0}, {a[t], b[t]}, {t}]

Gives the following simplified output

{{a[t] -> 
1/2 E^(-(1/2) I t \[Theta]) (a0 (1 + E^(I t \[Theta])) - 
  I b0 (-1 + E^(I t \[Theta])) Cos[\[Phi]] - 
  b0 (-1 + E^(I t \[Theta])) Sin[\[Phi]]), 
b[t] -> 1/
2 E^(-(1/2)
   I t \[Theta]) (I a0 E^(I \[Phi]) (-1 + E^(I t \[Theta])) + 
  b0 (1 + E^(I t \[Theta])))}}

Or in a bit more readable view $$\left( \begin{array}{c} a(t)\to \frac{1}{2} e^{-\frac{1}{2} i \theta t} \left(a_0 \left(1+e^{i \theta t}\right)-b_0 \left(-1+e^{i \theta t}\right) \sin (\phi )-i b_0 \left(-1+e^{i \theta t}\right) \cos (\phi )\right) \\ b(t)\to \frac{1}{2} e^{-\frac{1}{2} i \theta t} \left(i a_0 e^{i \phi } \left(-1+e^{i \theta t}\right)+b_0 \left(1+e^{i \theta t}\right)\right) \\ \end{array} \right)$$ Calling ExpToTrig and Simplify gives,

$$\left( \begin{array}{c} a(t)\to a_0 \cos \left(\frac{\theta t}{2}\right)+b_0 \sin \left(\frac{\theta t}{2}\right) (\cos (\phi )-i \sin (\phi )) \\ b(t)\to b_0 \cos \left(\frac{\theta t}{2}\right)-a_0 \sin \left(\frac{\theta t}{2}\right) (\cos (\phi )+i \sin (\phi )) \\ \end{array} \right)$$

Now if I simplify all the trig of variable $\theta$ I get the nicest output

$$\left( \begin{array}{c} a(t)\to a_0 \cos \left(\frac{\theta t}{2}\right)+b_0 e^{-i \phi } \sin \left(\frac{\theta t}{2}\right) \\ b(t)\to b_0 \cos \left(\frac{\theta t}{2}\right)-a_0 e^{i \phi } \sin \left(\frac{\theta t}{2}\right) \\ \end{array} \right)$$

Can anyone suggest a way to automate this procedure? I get that in general, it's a very complex task, but Mathematica has never failed to impress me.

  • 2
    $\begingroup$ Welcome to Mathematica.SE! ExpToTrig[answer]//FullSimplify gives desired result. $\endgroup$ – Alx Jul 26 '19 at 11:47
  • $\begingroup$ @Alx Thanks it does work, but do you have a more general solution $\endgroup$ – user2757771 Jul 26 '19 at 18:00
  • $\begingroup$ Well, someone calls this "black art"---to force Mathematica produce the answer one wants. If you FullSimplify on the first output (just the solution to differential equations), Mathematica gives for a(t) the simplified expression as you want, but for b(t) it gives more complicated one. It is strange, from LeafCount point of view (MMA tries to simplify by minimizing length of expression). So I think there is no general approach, one just need to try different combinations of expressions' transformations. That is why not only FullSimplify exists in WL. $\endgroup$ – Alx Jul 27 '19 at 13:45
  • $\begingroup$ @Alx I get it but would be nice to have the option of simplifying using a pattern or something $\endgroup$ – user2757771 Jul 28 '19 at 10:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.