Let we have linear combination of complex exponents with possibly complex coefficients:
N
∑
j=1
c
i
α
j
Under certain conditions it could be reduced to a linear combination of Sin and Cos without imaginary part.
This happens, for example, when we manually solve a linear differential equation, as in this question.
But how to reduce exponents to a closed trigonometric form (if possible)?
This happens, for example, when we manually solve a linear differential equation, as in this question.
But how to reduce exponents to a closed trigonometric form (if possible)?
Let’s try example from the question:
formExp = + + + ;
c
1
- t
c
2
t
c
3
-2 t
c
4
2 t
In[]:=
complexFormTrig=ExpToTrig@formExp
Out[]=
Cos[t]-Sin[t]+Cos[t]+Sin[t]+Cos[2t]-Sin[2t]+Cos[2t]+Sin[2t]
c
1
c
1
c
2
c
2
c
3
c
3
c
4
c
4
But how to convert it to trigonometric form without imaginary part?
We know that it’s possible, ‘cause formExp is solution of ODE:
We know that it’s possible, ‘cause formExp is solution of ODE:
In[]:=
x[t]/.First@DSolve[x''''[t]+5x''[t]+4x[t]==0,x[t],t]
Out[]=
3
1
4
2
I tried many ways: ComplexExpand, TrigReduce etc. and created a question on this topic,
but proposed solutions are too partial or artificial. So I made some custom approach.
but proposed solutions are too partial or artificial. So I made some custom approach.
Firstly we need to refine trigonometric basis. We assume it contains only Sin[x_] or Cos[x_]so:
In[]:=
basis=Union@Cases[Level[complexFormTrig,{2}],Sin[x_]|Cos[x_]]
Out[]=
{Cos[t],Cos[2t],Sin[t],Sin[2t]}
Final trig form should be linear combination of basis:
In[]:=
formTrig=basis.Table,{j,Length@basis}
k
j
Out[]=
Cos[t]+Cos[2t]+Sin[t]+Sin[2t]
k
1
k
2
k
3
k
4
Coefficients in formExp may be different symbols, so let’s select them directly:
In[]:=
coeffsExp=Cases[Level[formExp,{2}],Except@Exp[x_]]
Out[]=
{,,,}
c
1
c
2
c
3
c
4
Finally we find such coeffsExp that formExp could be convert to closed trig form formTrig with real coeffs:
coeffsExpSubs=First@Solve[ForAll[Evaluate@basis,complexFormTrig==formTrig],coeffsExp]
Out[]=
(+),(-),(+),(-)
c
1
1
2
k
1
k
3
c
2
1
2
k
1
k
3
c
3
1
2
k
2
k
4
c
4
1
2
k
2
k
4
And check it:
ComplexExpand[formExp/.coeffsExpSubs]==formTrig
Out[]=
True
Of course it is possible that the solution does not exist . This is taken into account in the final module.
Single module
Single module
Clear[linExpToTrig];linExpToTrig[linExp_]:= Module[{ce=Cases[Level[linExp,{2}],Except@Exp[x_]], cft=ExpToTrig@linExp,ft,b,s}, b=Union@Cases[Level[cft,{2}],Sin[x_]|Cos[x_]]; ft=b.Table[,{j, Length@b}]; s=Solve[ForAll[Evaluate@b,cft==ft],ce]; If[s=={},"No solution", <|"TrigForm"->ft,"Coeffs"->First@s|>]];
k
j
Tests
Tests
In[]:=
linExpToTrig[+]
c
1
-t
c
2
t
Out[]=
TrigFormCos[t]+Sin[t],Coeffs(+),(-)
k
1
k
2
c
1
1
2
k
1
k
2
c
2
1
2
k
1
k
2
linExpToTrig[aE^(-It)+bE^(It)+cE^(-2It)+dE^(2It)]
Out[]=
TrigFormCos[t]+Cos[2t]+Sin[t]+Sin[2t],Coeffsa(+),b(-),c(+),d(-)
k
1
k
2
k
3
k
4
1
2
k
1
k
3
1
2
k
1
k
3
1
2
k
2
k
4
1
2
k
2
k
4
linExpToTrig[aE^(-2It)+bE^(It)+cE^(-3It)+dE^(2It)]
Out[]=
No solution
CITE THIS NOTEBOOK
CITE THIS NOTEBOOK
Custom ExpToTrig Proposal
by Denis Ivanov
Wolfram Community, STAFF PICKS, March 5, 2024
https://community.wolfram.com/groups/-/m/t/3135609
by Denis Ivanov
Wolfram Community, STAFF PICKS, March 5, 2024
https://community.wolfram.com/groups/-/m/t/3135609