# Simplify trigonometric identities in complex expression

The function FullSimplify can easily reformat this expression

FullSimplify[Cos[omegan t]^2 + Sin[omegan t]^2]
(* output: 1 *)


However, it cannot simplify the same expression if contained in a larger expression:

sol = DSolve[m*(x''[t] + omegan^2 * x[t]) == B*Exp[I*omegad*t], x, t]


Result:

$-\frac{B e^{i \omega_d t} \left(\sin ^2(\omega_n t)+\cos ^2(\omega_n t)\right)}{m (\omega_d-\omega_n) (\omega_d+\omega_n)}+c_2 \sin (\omega_n t)+c_1 \cos (\omega_n t)$

$-\frac{B e^{i \omega_d t}}{m (\omega_d^2-\omega_n^2)}+c_2 \sin (\omega_n t)+c_1 \cos (\omega_n t)$

What is the command I'm missing?

Collect with its optional 3rd argument is very effective here

Collect[x[t] /. Flatten[sol], B, FullSimplify]
(* -((B E^(I omegad t))/(m omegad^2 - m omegan^2)) + C[1] Cos[omegan t] + C[2] Sin[omegan t] *)


In fact, Collect may not be needed here.

Note that simplification does not reach into the body of Function. You probably need to evaluate it before attempting to simplify.

• I think you can just use the simple FullSimplify[x[t] /. Flatten[sol]]. Aug 15, 2018 at 20:28

You can always do your own expression substitution

sol = DSolve[m*(x''[t] + omegan^2*x[t]) == B*Exp[I*omegad*t], x, t] /.
Cos[omegan t]^2 + Sin[omegan t]^2 -> 1


which gives you your desired result

(*{{x -> Function[{t},  C[1] Cos[omegan t] + C[2] Sin[omegan t] -