\[
x = x_p(t) + l \sin (\theta) = A \cos(\omega t - \delta) + l \sin (\theta),
\]
\[
y = l \cos (\theta)
\]
The velocity components of the pendulum bob are:
\[
\dot{x} = -A \omega \sin(\omega t - \delta) + l \dot{\theta} \cos (\theta),
\]
\[
\dot{y} = -l \dot{\theta} \sin (\theta)
\]
The total kinetic energy \( T \) is therefore:
\[
T = \frac{1}{2} m (\dot{x}^2 + \dot{y}^2)
\]
Expanding this expression, we get:
\[
T = \frac{1}{2} m \left[ \left(-A \omega \sin(\omega t - \delta) + l \dot{\theta} \cos (\theta)\right)^2 + \left(l \dot{\theta} \sin (\theta)\right)^2 \right]
\]
Expanding further and simplifying, we obtain:
\[
T = \frac{1}{2} m \left( A^2 \omega^2 \sin^2(\omega t - \delta) + l^2 \dot{\theta}^2 - 2 A l \omega \dot{\theta} \cos (\theta) \sin(\omega t - \delta) \right)
\]
The potential energy \( V \) is due to gravity and is given by:
\[
V = -m g y = -m g l \cos (\theta)
\]
The Lagrangian \( L \) is given by:
\[
L = T - V = \frac{1}{2} m \left( A^2 \omega^2 \sin^2(\omega t - \delta) + l^2 \dot{\theta}^2 - 2 A l \omega \dot{\theta} \cos (\theta) \sin(\omega t - \delta) \right) + m g l \cos (\theta)
\]
Using the Euler-Lagrange equation:
\[
\frac{d}{dt} \left( \frac{\partial L}{\partial \dot{\theta}} \right) - \frac{\partial L}{\partial \theta} = 0,
\]
\[
\frac{\partial L}{\partial \dot{\theta}} = m l^2 \dot{\theta} - m A l \omega \cos (\theta) \sin(\omega t - \delta).
\]
\[
\frac{d}{dt} \left( \frac{\partial L}{\partial \dot{\theta}} \right) = m l^2 \ddot{\theta} - m A l \omega \left( -\dot{\theta} \sin (\theta) \sin(\omega t - \delta) + \cos (\theta) \omega \cos(\omega t - \delta) \right)
\]
\[
\frac{\partial L}{\partial \theta} = m l \left( A \omega \dot{\theta} \sin(\omega t - \delta) \sin (\theta) - g \sin (\theta) \right)
\]
\[
m l^2 \ddot{\theta} - m A l \omega \left( -\dot{\theta} \sin (\theta) \sin(\omega t - \delta) + \cos (\theta) \omega \cos(\omega t - \delta) \right) - m l \left( A \omega \dot{\theta} \sin(\omega t - \delta) \sin (\theta) - g \sin (\theta) \right) = 0
\]
\[
l \ddot{\theta} - A \omega \left( -\dot{\theta} \sin (\theta) \sin(\omega t - \delta) + \cos (\theta) \omega \cos(\omega t - \delta) \right) - \left( A \omega \dot{\theta} \sin(\omega t - \delta) \sin (\theta) - g \sin (\theta) \right) = 0
\]
\[
l \ddot{\theta} - A \omega \left( -\dot{\theta} \sin (\theta) \sin(\omega t - \delta) + \cos (\theta) \omega \cos(\omega t - \delta) + \dot{\theta} \sin(\omega t - \delta) \sin (\theta) \right) + g \sin (\theta) = 0
\]
\[
\ddot{\theta} - \frac{ A \omega}{l} \left( -\dot{\theta} \sin (\theta) \sin(\omega t - \delta) + \cos (\theta) \omega \cos(\omega t - \delta) + \dot{\theta} \sin(\omega t - \delta) \sin (\theta) \right) + \frac{g}{l} \sin (\theta) = 0
\]
\[
\ddot{\theta} + \frac{g}{l} \sin (\theta) = \frac{ A \omega}{l} \left( -\dot{\theta} \sin (\theta) \sin(\omega t - \delta) + \cos (\theta) \omega \cos(\omega t - \delta) + \dot{\theta} \sin(\omega t - \delta) \sin (\theta) \right)
\]
\[
\ddot{\theta} + \frac{g}{l} \sin (\theta) = \frac{ A \omega}{l} \left( \cos (\theta) \omega \cos(\omega t - \delta) \right)
\]
\begin{equation}
\boxed{\ddot{\theta} + \frac{g}{l} \sin (\theta) = \frac{ A \omega^2}{l} \left( \cos (\theta) \cos(\omega t - \delta) \right)} \label{eq:horizontal_original_no_damping} \tag{1}
\end{equation}
Expanding about \(\theta = 0\) yields to first order \(\sin(\theta) \sim 0 + \cos(0) (\theta-0) = \theta\), \(\cos(\theta) \sim 1\), yielding
\[
\boxed{\ddot{\theta} + \frac{g}{l}\theta = \frac{ A \omega^2}{l}\cos(\omega t - \delta)}
\]
with solution
\[\theta{\left(t \right)} = \frac{A \omega^{2} \cos{\left(\delta - \omega t \right)}}{g - l \omega^{2}} + C_{1} \sin{\left(\frac{\sqrt{g} t}{\sqrt{l}} \right)} + C_{2} \cos{\left(\frac{\sqrt{g} t}{\sqrt{l}} \right)}\]
To second order, \(\sin(\theta) \sim \theta\), \(\cos(\theta) \sim 1 - \dfrac{\theta^2}{2}\), yielding
\begin{equation}
\boxed{\ddot{\theta} + \frac{g}{l}\theta = \frac{ A \omega^2}{l}\left(1 - \dfrac{\theta^2}{2}\right)\cos(\omega t - \delta)} \label{eq:hoizontal_second_order_no_damping} \tag{2}
\end{equation}
Considering linear damping simply modifies equation \ref{eq:horizontal_original_no_damping} to be:
\begin{equation}
\boxed{\ddot{\theta} + \frac{g}{l} \sin (\theta) = \frac{ A \omega^2}{l} \left( \cos (\theta) \cos(\omega t - \delta) \right) -\lambda \dot{\theta}}\label{eq:horizontal_original_linear_damping}\tag{3}
\end{equation}
Vertical
\[
x = l \sin (\theta),
\]
\[
y = y_p(t) + l \cos (\theta) = A \cos(\omega t - \delta) + l \cos (\theta)
\]
The velocity components of the pendulum bob are:
\[
\dot{x} = l \dot{\theta} \cos (\theta),
\]
\[
\dot{y} = -A \omega \sin(\omega t - \delta) - l \dot{\theta} \sin (\theta)
\]
The total kinetic energy \( T \) is therefore:
\[
T = \frac{1}{2} m (\dot{x}^2 + \dot{y}^2)
\]
Expanding this expression, we get:
\[
T = \frac{1}{2} m \left[ \left(l \dot{\theta} \cos (\theta)\right)^2 + \left(-A \omega \sin(\omega t - \delta) - l \dot{\theta} \sin (\theta)\right)^2 \right]
\]
Expanding further and simplifying, we obtain:
\[
T = \frac{1}{2} m \left( A^2 \omega^2 \sin^2(\omega t - \delta) + l^2 \dot{\theta}^2 + 2 A l \omega \dot{\theta} \sin (\theta) \sin(\omega t - \delta) \right)
\]
The potential energy \( V \) is due to gravity and is given by:
\[
V = -m g y = -m g \left(A \cos (\omega t - \delta) + l \cos (\theta)\right)
\]
The Lagrangian \( L \) is given by:
\[
L = T - V = \frac{1}{2} m \left( A^2 \omega^2 \sin^2(\omega t - \delta) + l^2 \dot{\theta}^2 + 2 A l \omega \dot{\theta} \sin (\theta) \sin(\omega t - \delta) \right) + m g \left(A \cos (\omega t - \delta) + l \cos (\theta)\right)
\]
Using the Euler-Lagrange equation:
\[
\frac{d}{dt} \left( \frac{\partial L}{\partial \dot{\theta}} \right) - \frac{\partial L}{\partial \theta} = 0,
\]
\[
\frac{\partial L}{\partial \dot{\theta}} = m l^2 \dot{\theta} + m A l \omega \sin (\theta) \sin(\omega t - \delta).
\]
\[
\frac{d}{dt} \left( \frac{\partial L}{\partial \dot{\theta}} \right) = m l^2 \ddot{\theta} + m A l \omega \left( \dot{\theta} \cos (\theta) \sin(\omega t - \delta) + \sin (\theta) \omega \cos(\omega t - \delta) \right)
\]
\[
\frac{\partial L}{\partial \theta} = m l \left( A \omega \dot{\theta} \sin(\omega t - \delta) \cos (\theta) - g \sin (\theta) \right)
\]
\[
m l^2 \ddot{\theta} + m A l \omega \left( \dot{\theta} \cos (\theta) \sin(\omega t - \delta) + \sin (\theta) \omega \cos(\omega t - \delta) \right) - m l \left( A \omega \dot{\theta} \sin(\omega t - \delta) \cos (\theta) - g \sin (\theta) \right) = 0
\]
\[
l \ddot{\theta} + A \omega \left( \dot{\theta} \cos (\theta) \sin(\omega t - \delta) + \sin (\theta) \omega \cos(\omega t - \delta) \right) - \left( A \omega \dot{\theta} \sin(\omega t - \delta) \cos (\theta) - g \sin (\theta) \right) = 0
\]
\[
l \ddot{\theta} + A \omega \left( \dot{\theta} \cos (\theta) \sin(\omega t - \delta) + \sin (\theta) \omega \cos(\omega t - \delta) - \dot{\theta} \sin(\omega t - \delta) \cos (\theta) \right) + g \sin (\theta) = 0
\]
\[
\ddot{\theta} + \frac{A \omega}{l} \left( \dot{\theta} \cos (\theta) \sin(\omega t - \delta) + \sin (\theta) \omega \cos(\omega t - \delta) - \dot{\theta} \sin(\omega t - \delta) \cos (\theta) \right) + \frac{g}{l} \sin (\theta) = 0
\]
\[
\ddot{\theta} + \frac{g}{l} \sin (\theta) = -\frac{A \omega}{l} \left( \sin (\theta) \omega \cos(\omega t - \delta) \right)
\]
\begin{equation}
\boxed{\ddot{\theta} + \frac{g}{l} \sin (\theta) = -\frac{A \omega^2}{l} \left( \sin (\theta) \cos(\omega t - \delta) \right)} \label{eq:vertical_original_no_damping} \tag{6}
\end{equation}
Expanding about \(\theta = 0\) yields to first order \(\sin(\theta) \sim 0 + \cos(0) (\theta-0) = \theta\), \(\cos(\theta) \sim 1\), yielding:
\[
\boxed{\ddot{\theta} + \frac{g}{l} \theta = -\frac{A \omega^2}{l} \left( \theta \cos(\omega t - \delta) \right)}
\]
To second order, \(\sin(\theta) \sim \theta\), \(\cos(\theta) \sim 1 - \dfrac{\theta^2}{2}\), yielding
\begin{equation}
\boxed{\ddot{\theta} + \frac{g}{l} \theta = -\frac{A \omega^2}{l} \left( \theta \cos(\omega t - \delta) \right)} \label{eq:vertical_second_order_no_damping} \tag{7}
\end{equation}
Considering linear damping simply modifies equation \ref{eq:vertical_original_no_damping} to be:
\begin{equation}
\boxed{\ddot{\theta} + \frac{g}{l} \sin (\theta) = -\frac{A \omega^2}{l} \left( \sin (\theta) \cos(\omega t - \delta) \right) -\lambda \dot{\theta}}\label{eq:vertical_original_linear_damping} \tag{8}
\end{equation}
\[
x = x_p(t) + l \sin (\theta)
\]
\[
y = l \cos (\theta)
\]
The velocity components of the pendulum bob are:
\[
\dot{x} = \dot{x}_p(t) + l \dot{\theta} \cos (\theta),
\]
\[
\dot{y} = -l \dot{\theta} \sin (\theta)
\]
The total kinetic energy \( T \) is therefore:
\[
T = \frac{1}{2} m (\dot{x}^2 + \dot{y}^2)
\]
Expanding this expression, we get:
\[
T = \frac{1}{2} m \left[ \left(\dot{x}_p(t) + l \dot{\theta} \cos (\theta)\right)^2 + \left(l \dot{\theta} \sin (\theta)\right)^2 \right]
\]
Expanding further and simplifying, we obtain:
\[
T = \frac{1}{2} m \left( \dot{x_p}^2(t) + l^2 \dot{\theta}^2 + 2 l \dot{x}_p(t) \dot{\theta} \cos (\theta) \right)
\]
The potential energy \( V \) is due to gravity and is given by:
\[
V = -m g y = -m g l \cos (\theta)
\]
The Lagrangian \( L \) is given by:
\[
L = T - V = \frac{1}{2} m \left( \dot{x_p}^2(t) + l^2 \dot{\theta}^2 + 2 l \dot{x}_p(t) \dot{\theta} \cos (\theta) \right) + m g l \cos (\theta)
\]
Using the Euler-Lagrange equation:
\[
\frac{d}{dt} \left( \frac{\partial L}{\partial \dot{\theta}} \right) - \frac{\partial L}{\partial \theta} = 0,
\]
\[
\frac{\partial L}{\partial \dot{\theta}} = m l^2 \dot{\theta} + m l \dot{x}_p(t) \cos (\theta)
\]
\[
\frac{d}{dt} \left( \frac{\partial L}{\partial \dot{\theta}} \right) = m l^2 \ddot{\theta} + m l \left( \ddot{x}_p(t)\cos(\theta) - \dot{x}_p(t)\dot{\theta}\sin(\theta) \right)
\]
\[
\frac{\partial L}{\partial \theta} = -m l \left( \dot{x}_p(t)\dot{\theta}\sin(\theta) + g \sin (\theta) \right)
\]
\[
m l^2 \ddot{\theta} + m l \left( \ddot{x}_p(t)\cos(\theta) - \dot{x}_p(t)\dot{\theta}\sin(\theta) \right) + m l \left( \dot{x}_p(t)\dot{\theta}\sin(\theta) + g \sin (\theta) \right) = 0
\]
\[
l \ddot{\theta} + \left( \ddot{x}_p(t)\cos(\theta) - \dot{x}_p(t)\dot{\theta}\sin(\theta) \right) + \left( \dot{x}_p(t)\dot{\theta}\sin(\theta) + g \sin (\theta) \right) = 0
\]
\[
l \ddot{\theta} + \ddot{x}_p(t)\cos(\theta) + g \sin (\theta) = 0
\]
\(\underline{\textbf{Steps to learn } \mathbf{x_p(t)}}\)
Generate a function \(x_p(t)\)
Numerically integrate \(\theta(t)\) from \(t = 0\) to \(t_\text{final}\) with \(\theta(0) = \theta_0\), \(\dot{\theta}(0) = 0\)
Measure the loss as \(\mathcal{L} \sim \max(\vec{\theta} - \theta_0)\)
Optimize the parameters in \(x_p(t)\) to minimize \(\mathcal{L}\)