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!
$$ 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}.$$