If $\frac{3-\tan^2\frac\pi7}{1-\tan^2\frac\pi7}=k\cos\frac\pi7$, find $k$ I need help solving this question:
$$
\text{If }\frac{3-\tan^2\frac\pi7}{1-\tan^2\frac\pi7}=k\cos\frac\pi7\text{, find k.}
$$
I simplified this down to:
$$
\frac{4\cos^2\frac\pi7-1}{2\cos^2\frac\pi7-1}
$$
But am unable to proceed further. The value of k is given to be 4, but I am unable to derive that result.
Kindly provide me with some insight, or with a step-by-step solution.
Thanks in advance,
Abhigyan

Set $z=e^{i\pi/7}$, so $z^7=e^{i\pi}=-1$ and $z^{-1}=\bar{z}$.
Then
$$
\cos\frac{\pi}{7}=\frac{z+\bar{z}}{2}=\frac{z^2+1}{2z},
\qquad
\sin\frac{\pi}{7}=\frac{z-\bar{z}}{2i}=\frac{z^2-1}{2iz}
$$
Therefore
$$
\tan\frac{\pi}{7}=-i\frac{z^2-1}{z^2+1}
$$
Plugging in the left hand side, we get
$$
\frac{3(z^2+1)^2+(z^2-1)^2}{(z^2+1)^2+(z^2-1)^2}=
\frac{4z^4+4z^2+4}{2z^4+2}=2\frac{z^4+z^2+1}{z^4+1}
$$
and finally
$$
k=2\frac{z^4+z^2+1}{z^4+1}\frac{2z}{z^2+1}=
\frac{4z(z^4+z^2+1)}{(z^4+1)(z^2+1)}
$$
The denominator reads $z^6+z^4+z^2+1$, but from $z^7+1=0$ we can deduce $z^6-z^5+z^4-z^3+z^2-z+1=0$ and so
$$
z^6+z^4+z^2+1=z^5+z^3+z=z(z^4+z^2+1)
$$
and you get
$$
k=4
$$
