Solving $B=m\cos^2\alpha + k\cos\alpha\sin\alpha + n\sin^2\alpha$ for $\alpha$ The context of this question comes from calculating the fidelity drop of quantum systems after applying rotational X and Z gates. The equation to solve is shown below, for which the angle $\alpha$ needs to be found.
$$
B = m\cos^{2}(\alpha) + k\cos(\alpha)\sin(\alpha) + n\sin^{2}(\alpha)
$$
In the equation $B$, $m$, $k$, and $n$ are known.
I would be happy to receive some help with this, thanks in advance!
 A: $$
B = m\cos^{2}(\alpha) + k\cos(\alpha)\sin(\alpha) + n\sin^{2}(\alpha)
$$
$$
\implies B-\frac{m+n}{2}=\frac{m-n}{2} \cos 2 \alpha + \frac{k}{2} \sin 2\alpha
$$
$$
\frac{2B-m-n}{\sqrt{(m-n)^2+k^2}}=\frac{(m-n) \cos 2 \alpha + k \sin 2\alpha}{\sqrt{(m-n)^2+k^2}}=\cos(2\alpha-\beta)
$$
Finally we get $$\alpha=\frac{1}{2}\cos^{-1}\left[\frac{2B-m-n}{\sqrt{(m-n)^2+k^2}}\right]+\frac{\beta}{2},~~ \beta=\tan^{-1}\frac{k}{m-n}.$$
A: *

*Move the $\cos\alpha\sin\alpha$ term to one side, then square both sides of the equation

*Use $x=\cos^2\alpha$, so then $\sin^2\alpha=1-x$

*Solve the equation in $x$

*Finds $\alpha$.

*Check the solution by plugging it back into the original equation. You might need to adjust the sign of $\alpha$
EDIT:
$$
(B - m\cos^{2}(\alpha) - n\sin^{2}(\alpha))^2= k^2\cos^2(\alpha)\sin^2(\alpha)
$$
Substituting $\cos^2\alpha=x,\ \sin^2\alpha=1-\cos^2\alpha=1-x$, you get:
$$(B-mx-n(1-x))^2=k^2x(1-x)$$
This is a simple quadratic equation in $x$.
A: Hint:
Avoid squaring as it generally introduces When do we get extraneous roots?
Divide both sides by $\cos^2\alpha$ to find $$B(1+t^2)=m+kt+nt^2$$ which on rearrangement is a quadratic equation in $t=\tan^2\alpha$
We can divide both sides by $\sin^2\alpha$ as well to find another quadratic equation in $\dfrac1t$
