
$$\begin{equation*}
\begin{split}
x &= l \sin \theta \\
y &= -l \cos \theta \\
\dot{x} &= l\frac{\partial}{\partial t} \sin \theta = l \cos \theta \dot{\theta} \\
\dot{y} &= l\frac{\partial}{\partial t} \cos \theta = -l \sin \theta \dot{\theta} \\
\end{split}
\end{equation*}$$
$$\begin{equation*}
\begin{split}
L &= T - U \\
U &= mgh = mg(l- l \cos \theta) = mgl - mgl \cos \theta \\
T &= \frac{1}{2}m(\dot{x}^2 + \dot{y}^2) \\
&= \frac{1}{2}m(l^2{\cos}^2 \theta {\dot{\theta}^2} + l^2{\sin}^2 \theta {\dot{\theta}^2} ) \\
&= \frac{1}{2}ml^2{\dot{\theta}^2} \\
L &= \frac{1}{2}ml^2{\dot{\theta}^2} -mgl + mgl \cos \theta \\
\end{split}
\end{equation*}$$
$$\begin{equation*}
\begin{split}
\frac{\partial L}{\partial \theta} &= -mgl \sin \theta \\
\frac{\partial L}{\partial \dot{\theta}} &= ml^2 \dot{\theta} \\
\frac{\partial }{\partial t} \frac{\partial L}{\partial \dot{\theta}} &= ml^2 \ddot{\theta} \\
\frac{\partial }{\partial t} \frac{\partial L}{\partial \dot{\theta}} - \frac{\partial L}{\partial \theta} &= Q \\
ml^2 \ddot{\theta} + mgl \sin \theta &= Q \\
\text{where } Q = -b \dot{\theta} + u \\
\\
\text{when } Q = 0, \\
\ddot{\theta} &= -\frac{g}{l} \sin \theta \\
\text{when } b \dot{\theta} = 0, \\
\ddot{\theta} &= -\frac{g}{l} \sin \theta + \frac{1}{ml^2}u\\
\text{else}, \\
\ddot{\theta} &= -\frac{g}{l} \sin \theta - \frac{b}{ml^2} \dot{\theta} + \frac{1}{ml^2}u\\
\end{split}
\end{equation*}$$