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]
{{x->Function[{t},C[1] Cos[omegan t]+C[2] Sin[omegan t]-(B E^(I omegad t) (Cos[omegan t]^2+Sin[omegan t]^2))/(m (omegad-omegan) (omegad+omegan))]}}


$-\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)$

Instead of:

$-\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?


2 Answers 2


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.

  • 2
    $\begingroup$ I think you can just use the simple FullSimplify[x[t] /. Flatten[sol]]. $\endgroup$
    – Carl Woll
    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] -
    (B E^(I omegad t))/(m (omegad - omegan) (omegad + omegan))]}}*)

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.