# Sum of sinusoids at the same frequency but with different amplitudes and phases

Three sinusoids at the same frequency are superimposed:

Cos[3.1 - t] + 5 Cos[π/4 + t] + 2 Sin[0.3 + t]

How can the resulting oscillation be stated in the following forms?

a Cos[t] + b Sin[t] and A Cos[t + α]

I have tried many things; even asked chatgpt and I just cannot figure it out. Any help is greatly appreciated.

• As noted in responses, TrigExpand does the first. For the second task there is a resource function. In[591]:= ResourceFunction["TrigContract"][ Cos[3.1 - t] + 5 Cos[\[Pi]/4 + t] + 2 Sin[0.3 + t]] Out[591]= 3.50537 Cos[0.468639 + t] Dec 8, 2023 at 15:52
• @Daniel Lichtblau Thanks for pointing out the ResourceFunction
– rmw
Dec 8, 2023 at 17:55
• @DanielLichtblau Your suggestion does not work for Rationalized expressions. Dec 8, 2023 at 22:49

2 Sin[t + 0.3] + 5 Cos[t + π/4] + Cos[t - 3.1] // TrigExpand // Simplify


3.12744 Cos[t] - 1.58328 Sin[t]

a = 3.12744; b = -1.58328;
φ1 = 0; φ2 = -π/2;

amp = Sqrt[a^2 + b^2 + 2*a*b*Cos[φ2 - φ1]];
ϕ = ArcTan[a*Cos[φ1] + b*Cos[φ2], a*Sin[φ1] + b*Sin[φ2]] // N;
amp*Cos[ϕ + t]


3.50538 Cos[0.468639 + t]

• Adding Rationalize before // TrigExpand // Simplify does not produce the answer. It seems your method only works for floating point coefficients. Dec 8, 2023 at 22:47
• @yarchik Mathematica wants it that way!
– rmw
Dec 9, 2023 at 10:22
e1 = 2 Sin[t + 0.3];
e2 = 5 Cos[t + π/4];
e3 = Cos[t - 3.1];
expr = e1 + e2 + e3
FullSimplify[expr]


3.12744 Cos[t] - 1.58328 Sin[t]

res = FullSimplify[expr] /.
a_. Cos[t] + b_. Sin[t] :> a Sqrt[1 + b^2/a^2] Cos[t - ArcTan[b/a]]


3.50537 Cos[0.468639 + t]

Plot[{e1, e2, e3, expr, res}, {t, 0, 6 π},
PlotStyle -> {Automatic, Automatic, Automatic
, {Opacity[0.6, Red], Thickness[0.02]}, {Thick, Blue}}
, PlotLegends -> "Expressions"
]


How to arrive at the replacement formula:

{TrigExpand[A Cos[t - ϕ]], a Cos[t] + b Sin[t]}


{A Cos[t] Cos[ϕ] + A Sin[t] Sin[ϕ], a Cos[t] + b Sin[t]}

Comparing the two and solving:

sol = First[
Assuming[{a, b, A, ϕ} ∈ Reals,
Solve[{A Cos[ϕ] == a ,
A Sin[ϕ] == b }, {A, ϕ}]]] /. C[1] -> 1;

A Cos[t - ϕ] /. sol


Or you can hit it with a hammer.

\$Version

(* "13.3.1 for Mac OS X ARM (64-bit) (July 24, 2023)" *)

Clear["Global*"]

f[t_] = Cos[3.1 - t] + 5 Cos[π/4 + t] + 2 Sin[0.3 + t] // Rationalize;

data = Table[{t, f[t]}, {t, 0, 10, 1/10}];

(param1 = NonlinearModelFit[data,
a Cos[t] + b Sin[t], {a, b}, t,
WorkingPrecision -> 15]["BestFitParameters"]) // N

(* {a -> 3.12744, b -> -1.58328} *)

f[t] == a Cos[t] + b Sin[t] /. param1 // Simplify

(* True *)

(param2 = NonlinearModelFit[data,
A Cos[t + α], {A, α}, t,
WorkingPrecision -> 20]["BestFitParameters"]) // N

(* {A -> 3.50537, α -> 0.468639} *)

f[t] == A Cos[t + α] /. param2 // Simplify

(* True *)
`