Help with finding tangent to curve at a point 
Find an equation for the tangent to the curve at $P\left( \dfrac{\pi}{2},3 \right )$ and the horizontal tangent to the curve at $Q.$ 
  $$y=5+\cot x-2\csc x$$

$y\prime=-\csc ^2 x -2(-\csc x \cot x)$
$y\prime= 2\csc x \cot x - \csc ^2 x\implies$ This is the equation of the slope.  
Now I find the slope at $x=\dfrac{\pi}{2}:$
$$y^{\prime}=2\csc \left( \frac{\pi}{2} \right) \cot \left( \frac{\pi}{2} \right)- \csc ^2 \left( \frac{\pi}{2} \right)$$ $$y^{\prime}= -1$$ 
Equation for the tangent to the curve at $P$:
$$y-3=-1\left( x-\frac{\pi}{2} \right)$$ $$y=-x+\frac{6+\pi}{2}$$ 
Then I found the horizontal tangent at $Q$, which is where the slope is $0.$ So I set the slope equation equal to $0:$ 
$$y^{\prime}= 2\csc x \cot x - \csc ^2 x=0$$ $$-\csc ^2 x = -2\csc x \cot x$$ 
$$-\frac{1}{\sin^2 x}=-2\left( \frac{1}{\sin x} \frac{\cos x}{\sin x} \right )$$ 
$$\cos x = \frac{1}{2}$$

I don't know how to proceed from here. Since $\cos x = \dfrac{1}{2}$, $\cos^{-1}\left (\dfrac{1}{2}\right)=\dfrac{\pi}{3}$.
Plugging this into the equation would give the $y$ value, and I'd be able to find the equation of the tangent line, but I'm confused because there is not just one $x$ to consider, since $x=2n \pm \dfrac{\pi}{3}$. 
The answer for equation of tangent at $Q$ is $y=5-\sqrt{3}$, and I don't know how to get this. 
Can you please show how to work this last part in details? Thank you. 
 A: The first part looks good. For the second part as you see the solution to the equation gives
$$2 \cot x \csc x - \csc^2 x = 0 \Rightarrow x=2n \pi \pm\frac{\pi}{3}.$$
Choose $x=\frac{\pi}{3}$ as it is one such solution. We find the point on $y$ to be
$$5+\cot\left( \frac{\pi}{3} \right)-2\csc\left( \frac{\pi}{3} \right)=5-\sqrt{3},$$
And so $y=5-\sqrt{3}$ is indeed a horizontal tangent line, in particular the horizontal tangent line at $x=\frac{\pi}{3}$. You can verify this in WA.
A: I think what's you need is to consider $$\sin(2k \pi-\alpha)=-\sin(\alpha),~~~\sin(2k \pi+\alpha)=\sin(\alpha)\\ \cot(2k \pi-\alpha)=-\cot(\alpha),~~~\cot(2k \pi+\alpha)=\cot(\alpha)$$
A: This means that there can be infinitely many horizontal tangents. As simple as that .
Just pick up the one you want.
$x = 2n \pm \dfrac{\pi}3$ is one solution.
Corresponding $y$ value

$y = 5 + \cot\left(2n \pm \dfrac{\pi}3\right) -2\csc\left(2n \pm \dfrac{\pi}3\right)$
$y = 5 \pm \dfrac1{\sqrt3} \pm \dfrac4{\sqrt3} $
$y = 5 \pm \sqrt3$

So one solution is $ y = 5 - \sqrt3$
It's better you solve $x = 2n + \dfrac{\pi}3$ and $x = 2n - \dfrac{\pi}3$ separately so as to not get yourself confused.
A: Here is the graph. Do you see what happens?
A: You need to find the $y$ coordinate of $Q$, let it be called $y_0$. The horizontal tangent passes from $Q=(x_0,y_0)$ and so the equation will be $y=y_0$.
$\sin(x_0)=\sqrt{1-\cos^2(x_0)}=\dfrac{\sqrt{3}}2$ since  $\cos(x_0)=\dfrac{1}2$, so $\cot(x_0)=\dfrac{1}{\sqrt{3}}$.
And $\csc(x_0)=\dfrac{2}{\sqrt{3}}$ so $y_0=5-\sqrt{3}$
Even if you choose some other $x_0$, you will get the same $y_0$. It's a horizontal tangent line.
