0
$\begingroup$

Say I have an expression like this

a Sin[\[Theta]]^4 + b Cos[\[Theta]]^4 + 
 c Sin[\[Theta]]^3 Cos[\[Theta]] + d Sin[\[Theta]]^2 + e=0

My ultimate goal is to solve the above equation in terms of θ ; from my past experience, I need to convert the equation into a "polynomial" in terms of $\tan\theta$ by first converting the equation into a quartic homogeneous equation first, then divide everything by $\cos^4\theta$.

(P.S. The original expression I need to work on contains more different combinations of $\sin\theta$ and $\cos\theta$, with the maximum degree of their product equal to 4):

I notice that I can convert the last two terms into terms quartic in sin*cos by respectively multiplying them with (s^2+c^2) and (s^2+c^2)^2, after which I can divide all the terms by $\cos\theta$ to get a quartic polynomial, then I can solve for $\theta$. However, I'm looking for a more automatic way so that I don't have to do such substitutions manually because the expression I need to work on it much more complex, which prevents me from doing so.

According to my understanding, the above problem requires me to get the coefficient lists of the following terms $\sin\theta^4,\sin\theta^3\cos\theta,\sin\theta^2\cos\theta^2,\ldots,\sin\theta,\cos\theta$ plus the constant term. I tried to use a recursive approach to solve this, but failed. The module keeps running without returning the result.

The code I tried is as follows:


collectTrig[poly_, var_, degree_] := 
 Module[{variables, coefficients, currentVariable, currentCoefficient,
    currentPoly},
  variables = {};
  coefficients = {};
  currentPoly = poly;
  While[degree > 0,
   currentVariable = Sin[var]^degree;
   currentCoefficient = Coefficient[currentPoly, currentVariable];
   AppendTo[variables, currentVariable];
   AppendTo[coefficients, currentCoefficient];
   currentPoly = currentPoly - currentCoefficient*currentVariable
   ];
  {variables, coefficients}
  ]

So I wonder if there is any simpler way to implement my requirement?

Update1:

with the expressions provided by @Syed, I can now get the coefficients; now, the question is: since there are two terms which are not yet quartic, (namely the last two terms), I have to multiply them by $\sin^2\theta+\cos^2\theta$ and $(\sin^2\theta+\cos^2\theta)^2$ to turn them into quartics, after which I can divide all the terms by $\cos^4\theta$ to get a quartic polynomial in $\tan^4\theta$. I wonder how I can achieve this goal? I guess I may do a replacement of the corresponding rules by replacing $\cos$ with $1$ and $\sin$ with a new symbol called $t$ to represent the $\tan$, but how to get the expected expression based on this?

Update2: Currently, I found a workaround by firstly diving the expression by $\cos^4\theta$, then do the substitution:

Collect[Expand[TrigExpand[eqs]/Cos[Subscript[\[Theta], 2]]^4] /. 
    Sec[Subscript[\[Theta], 2]]^2 -> t^2 + 1 /. 
   Sec[Subscript[\[Theta], 2]]^4 -> (t^2 + 1)^2 /. 
  Tan[Subscript[\[Theta], 2]] -> t, t]

It's not elegant but does work. And I will welcome a direct solution to my previous question.

$\endgroup$
5
  • $\begingroup$ My ultimate goal is to solve the above equation in terms of $\theta$; from my past experience, I need to convert the equation into a "polynomial" in terms of $\tan\theta$ by first converting the equation into a quartic homogeneous equation first, then divide everything by $\cos^4\theta$ $\endgroup$
    – larry
    Commented Aug 23, 2023 at 6:56
  • $\begingroup$ CoefficientRules[expr // TrigExpand, {Cos[θ], Sin[θ]}] where expr is e + b Cos[θ]^4 + d Sin[θ]^2 + c Cos[θ] Sin[θ]^3 + a Sin[θ]^4. $\endgroup$
    – Syed
    Commented Aug 23, 2023 at 7:39
  • 1
    $\begingroup$ Thanks @Syed, this is exactly what I'm looking for. BTW, I wonder if there is a simple way to re_establish the original equation with the output rule, so that I can verify that the results are correct? Maybe sth like: Generate an array whose elements are the different combinations of $\cos\theta$ and $\sin\theta$, then I do a dot product? $\endgroup$
    – larry
    Commented Aug 23, 2023 at 8:27
  • $\begingroup$ I see that we can use the following code to re-establish the function: FromCoefficientRules[%, {x, y}], but I need to do some changes to some terms before summing the terms up, for example, how to achieve this if I want to multiply some of the terms with $\sin\theta^2+\cos\theta^2$ or $(\sin\theta^2+\cos\theta^2)^2$, then sum the terms up and convert the expression in to a quartic in terms of $\tan\theta$? For example, for the following term, I need to do so: $\{2, 0\} -> 1/2 (n . Subscript[f, 1])^2 (Subscript[v, 2] . Subscript[v, 3])^2$ $\endgroup$
    – larry
    Commented Aug 23, 2023 at 8:36
  • $\begingroup$ Generally, one can proceed as follows: eq1 = a Sin[\[Theta]]^4 + b Cos[\[Theta]]^4 +c Sin[\[Theta]]^3 Cos[\[Theta]] + d Sin[\[Theta]]^2 + e == 0; eq2 = eq1 /. {Sin[\[Theta]] -> Sqrt[1 - x^2], Cos[\[Theta]] -> x}; Solve[eq2, x]. The solution is however, much too cumbersome. $\endgroup$ Commented Aug 23, 2023 at 12:21

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.