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.
CoefficientRules[expr // TrigExpand, {Cos[θ], Sin[θ]}]
whereexpr
ise + b Cos[θ]^4 + d Sin[θ]^2 + c Cos[θ] Sin[θ]^3 + a Sin[θ]^4
. $\endgroup$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$