3
$\begingroup$

I have two symbolic Expressions and the both contain the same functions, as follows: $$ 3.12592+5.96272 \cos (2 \theta )+5.15739 \cos (4 \theta )+4.00413 \cos (6 \theta )+2.72961 \cos (8 \theta )+2.04608 \cos (10 \theta ) $$ and $$ 2. \text{$\Gamma $5} + 2. \text{$\Gamma $0} \cos (10 \theta )+2. \text{$\Gamma $1} \cos (8 \theta )+2. \text{$\Gamma $2} \cos (6 \theta )+2. \text{$\Gamma $3} \cos (4 \theta )+2. \text{$\Gamma $4} \cos (2 \theta ) $$ I want to solve for the Capital gammas by equating both equations coefficients. I tried Solve and it gave me an error "Equations may not give solutions for all "solve" variables" with the following solution: $$ \text{$\Gamma $5}\to -1. \text{$\Gamma $0} \cos (10. \theta )-1. \text{$\Gamma $1} \cos (8. \theta )-1. \text{$\Gamma $2} \cos (6. \theta )-1. \text{$\Gamma $3} \cos (4. \theta )-1. \text{$\Gamma $4} \cos (2. \theta )+2.98136 \cos (2. \theta )+2.5787 \cos (4. \theta )+2.00206 \cos (6. \theta )+1.3648 \cos (8. \theta )+1.02304 \cos (10. \theta )+1.56296 $$

I also tried Coefficient but it cannot extract the constant from the expression, CoefficientList does not work in this case as it is not a polynomial. Any Ideas? My code:

A=0.05;
zl=50;
z0=500;
n=10;
\[CapitalGamma]=0;
sec\[Theta]m=Cosh[1/n*ArcCosh[Abs[Log[zl/z0]/(2*0.05)]]];

glist=Table[Symbol["\[CapitalGamma]" <> ToString[i]], {i,0, n/2}];
conum=Range[n,Boole[OddQ[n]],-2];
For[i=1,i<=Length[glist],i++,
    \[CapitalGamma]= N[2]*glist[[i]] * Cos[conum[[i]]\[Theta]] + \[CapitalGamma]
    ];

TrigReduce[ChebyshevT[10,sec\[Theta]m*Cos[\[Theta]]]]
\[CapitalGamma]
Solve[TrigReduce[ChebyshevT[10,sec\[Theta]m*Cos[\[Theta]]]] == \[CapitalGamma], glist]
$\endgroup$
3
  • 1
    $\begingroup$ Welcome to the Mathematica Stack Exchange. Could you please load Mathematica code for your equations that forum participants can copy to their notebooks and experiment with? It is difficult to offer concrete advice otherwise. Thanks. $\endgroup$
    – Syed
    Commented Jun 3, 2022 at 11:39
  • $\begingroup$ I updated the question with the code. Thanks for the suggestion! $\endgroup$
    – Potatturu
    Commented Jun 3, 2022 at 11:57
  • $\begingroup$ I think you want SolveAlways[ ..., theta]. $\endgroup$
    – evanb
    Commented Jun 3, 2022 at 12:20

3 Answers 3

6
$\begingroup$

Another way with SolveAlways

f1 = 5.96272 Cos[2 θ] + 5.15739 Cos[4 θ] + 
   4.00413 Cos[6 θ] + 2.72961 Cos[8 θ] + 
   2.04608 Cos[10 θ] + 3.12592;

f2 = 2 Γ0 Cos[10 θ] + 
   2 Γ1 Cos[8 θ] + 
   2 Γ2 Cos[6 θ] + 
   2 Γ3 Cos[4 θ] + 
   2 Γ4 Cos[2 θ] + 2 Γ5;

vars = Variables[f2][[7 ;;]]

(*   {Cos[2 θ], Cos[4 θ], Cos[6 θ], Cos[8 θ], 
 Cos[10 θ]}   *)

SolveAlways[f1 == f2, vars]

(*   {{Γ0 -> 1.02304, Γ1 -> 
   1.36481, Γ2 -> 2.00207, Γ3 -> 
   2.5787, Γ4 -> 2.98136, Γ5 -> 1.56296}}   *)
$\endgroup$
2
  • $\begingroup$ @march , thanks for editing. Silly question: How to get this format whithout editing every variable singularily ? Conversion to RawInputForm and Copy doesn't work for me. $\endgroup$
    – Akku14
    Commented Jun 4, 2022 at 5:12
  • $\begingroup$ I installed the chrome plugin here. $\endgroup$
    – march
    Commented Jun 6, 2022 at 20:26
5
$\begingroup$

To be able to use "CoefficientList" we must first transform your equation to a polynomial by e.g. Lefthand Side-Righthand Side. Then we replace Cos[i theta] by e.g. c^i:

eq = {5.96272 Cos[2 θ] + 5.15739 Cos[4 θ] + 
    4.00413 Cos[6 θ] + 2.72961 Cos[8 θ] + 
    2.04608 Cos[10 θ] + 
    3.12592 - (2 Γ0 Cos[10 θ] + 
      2 Γ1 Cos[8 θ] + 
      2 Γ2 Cos[6 θ] + 
      2 Γ3 Cos[4 θ] + 
      2 Γ4 Cos[2 θ] + 2 Γ5)} /. 
  Cos[i_ θ] -> c^i

enter image description here

Now we can apply CoefficientList:

eq1= CoefficientList[eq, c][[1]]

enter image description here

Finally we solve for the gammas by equating the coefficients to zero:

Solve[Thread[ eq1 == 0], {Γ0, Γ1, Γ2, Γ3, Γ4, Γ5}]

enter image description here

$\endgroup$
0
4
$\begingroup$

Here's a way that's a bit silly but which should work. (I'm on a computer without MM on it right now, so if the code doesn't work please ping me in the comments and I'll fix it as soon as I'm able.)

expr = {5.96272 Cos[2 θ] + 5.15739 Cos[4 θ] + 
4.00413 Cos[6 θ] + 2.72961 Cos[8 θ] + 
2.04608 Cos[10 θ] + 
3.12592 - (2 Γ0 Cos[10 θ] + 
  2 Γ1 Cos[8 θ] + 
  2 Γ2 Cos[6 θ] + 
  2 Γ3 Cos[4 θ] + 
  2 Γ4 Cos[2 θ] + 2 Γ5)}
Solve[Table[FourierCosCoefficient[expr, θ, i] == 0, {i, 0, 10}], {Γ0, Γ1, Γ2, Γ3, Γ4, Γ5}]

This relies on the fact that your expressions are already effectively Fourier cosine series.

$\endgroup$

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.