Hi, I am new to Symbolics.jl
and trying to verify the following trigonometric expression arising in energy system using the package:
\begin{align*}
v_k(t) &= \bar{V} \cos(\omega t + \phi_k) \\
i_k(t) &= \bar{I} \cos(\omega t + \phi_k - \psi) \\
v_k(t) \times i_k(t)
&= \frac{\bar{V}\bar{I}}{2}\cos(\psi)(1 + \cos(2(\omega t + \phi_k))) + \frac{\bar{V}\bar{I}}{2}\sin(\psi)\sin(2(\omega t + \phi_k))
\end{align*}
Verifying such trigonometric identities are very easy in Wolfram Mathematica
:
(*Define voltage and current waveforms*)
vk[t_] := Vbar Cos[ω t + ϕk];
ik[t_] := Ibar Cos[ω t + ϕk - ψ];
(*Define instantaneous power as their product*)
pk[t_] := vk[t] ik[t];
(*Use TrigReduce to expand the product of cosines*)
expandedProduct = TrigReduce[pk[t]];
(*Define the target expression from the screenshot*)
targetExpression[
t_] := (Vbar Ibar/2) Cos[ψ] (1 +
Cos[2 (ω t + ϕk)]) + (Vbar Ibar/
2) Sin[ψ] Sin[2 (ω t + ϕk)];
(*Verify if both terms are equal*)
Simplify[pk[t] - targetExpression[t]]
which outputs 0. However, when I try in Julia:
using Symbolics, SymbolicUtils
@variables t Vbar Ibar ω φk ψ
vk(t) = Vbar * cos(ω*t + φk)
ik(t) = Ibar * cos(ω*t + φk - ψ)
pk(t) = vk(t) * ik(t)
expandedProduct = simplify(pk(t), expand=true)
targetExpression(t) = (Vbar * Ibar / 2) * cos(ψ) * (1 + cos(2 * (ω*t + φk))) +
(Vbar * Ibar / 2) * sin(ψ) * sin(2 * (ω*t + φk))
difference = pk(t) - targetExpression(t)
simplified_difference = simplify(difference, expand=true)
The output is -(1//2)*Ibar*Vbar*cos(ψ) + Ibar*Vbar*cos(φk + t*ω)*cos(φk - ψ + t*ω) - (1//2)*Ibar*Vbar*sin(2φk + 2t*ω)*sin(ψ) - (1//2)*Ibar*Vbar*cos(2φk + 2t*ω)*cos(ψ)
. Is there any function similar to TrigExpand
in Julia? Any tips regarding how to simplify the term in Symbolics
will be much appreciated.