```python
import sympy as sp
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.animation import FuncAnimation
```


```python
# import symbols
g, b, t, d, A, delt, l0, gam, A0 = sp.symbols(r'g \beta t \rho A \delta l_0, \gamma, A_0')
```

# The motion of the pendulum can be attributed to the superposition of 2 damped perpendicular SHMs who have angular frequencies as multiples of the variable angular frequency of the pendulum.

$$x = A_1(t)\;sin(n\omega t)\newline
y = A_2(t)\;sin(m\omega t + \delta)$$


```python
# Define the values of n amd m. By default, these are set two 6 and 5 respesctively.
try:
    n = int(input('Please enter n: '))
    m = int(input('Please enter m: '))
except:
    n = 6
    m = 5 
```

### $$Let\; \delta = \text{initial phase difference of the perpendicular SHMs}, \newline
l_0 = \text{initial length of pendulum}\newline
\beta = \text{rate of mass outflow}\newline
\rho = \text{density of sand}\newline
A = \text{area of container}$$


```python
#Defining the substitutions for later use
subst = {A0 : 5, #initial amplitude of pendulum 
         g: 9.8, # acceleration due to gravity
         d: 10, # density of sand
         l0: 1, #initial length of pendulum
         gam: 0.1, #damping coefficient
         b: 0.5, #rate of mass outflow
         A: 0.4, # c.s area of the container
         delt:0 # initial phase difference of the two SHMs
        }
```

$$\omega(t) =\sqrt{\frac{g}{l_0 + \frac{\beta t}{\rho a}}}\newline
x = A_1(t)\;sin(\omega t)\newline
y = A_2(t)\; sin(\omega t + \delta)\newline
\frac{x^2}{A_1^2} + \frac{y^2}{A_2^2} - \frac{2xy\;cos(\delta)}{A_1A_2} = sin^2(\delta) - Equation\;of\;the\;curves 
$$


```python
# define the time dependent symbolic functions
w = sp.Function(r'\omega')(t)
A1 = sp.Function(r'A_1')(t)
A2 = sp.Function(r'A_2')(t)
```


```python
# Define the angular frequency and the amplitudes
w = sp.sqrt(g/(l0 + (b*t/(d*A))))
A1 = A0*sp.exp(-gam*t)
A2 = A0*sp.exp(-gam*t)
```

# The amplitudes of the perpendicular SHMs are given as
## $$A_1(t) = A_0e^{-\beta t}\newline
A_2(t) = A_0e^{-\beta t}$$
## The individual perpendicular SHMs are damped and hence follow the general equation:
## $$ \ddot{x} + 2\beta\dot{x} + kx = 0, \newline \;where\; a,and\; \beta\; are \;constants \;and\; \beta =\;damping\; parameter.$$ 

The working formula of the angular frequency of the pendulum is 
$$ \omega(t) =\sqrt{\frac{g}{l_0 + \frac{\beta t}{\rho a}}}$$

The effective length of the pendulum is also changing. Hence, the working formula for the effective length of the pendulum is
$$ l_{eff}(t) = L_0 + \frac{\beta}{A\rho}t$$

## The x and y components of the curves are given by the individual damped SHMs:
### $$x = A_1(t)\;sin(n\omega t)\newline
y = A_2(t)\;sin(m\omega t + \delta)$$


```python
# Define the symbolic x values and the y values
x = A1*sp.sin(n*w*t)
y = A2*sp.sin(m*w*t + delt)
```


```python
# Convert the symbolic expressions to functions for plotting
w_f = sp.lambdify(t, w.subs(subst))
x_pts = sp.lambdify(t, x.subs(subst))
y_pts = sp.lambdify(t, y.subs(subst))

# Defining the time of plotting
time = np.linspace(0,20,1000)

# create the data points
x_div = x_pts(time)
y_div = y_pts(time)
```


```python
# animating the graph

#Set the figure
fig, ax = plt.subplots(figsize=(12,10))
ax.grid()
ax.set_xlabel(r'$x\rightarrow$')
ax.set_ylabel(r'$y\rightarrow$')
ax.set(xlim = (-5, 5), ylim = (-5,5))
line, =  ax.plot([],[], 'ro-') # blank line object for the lines

# define the animating function which append to the empty line object for every x and y value
def animate(i):
    line.set_data(x_div[:i], y_div[:i])
    return line,

# Create the animation
anim = FuncAnimation(fig, animate, frames = len(time), blit = True, interval = 50)

# Change the output format to JavaScript Html 'jshtml'
plt.rcParams['animation.html'] = 'jshtml'

plt.rcParams['animation.embed_limit'] = 50

# Call the animation
anim
```

239665ecf56665e9248f012de37d177df98d870b
ipynb
Jupyter Notebook
Lissajous figures.ipynb
ScientificArchisman/Simulations
b9f3e7cc5d94a150931c12dac5fa21391736c47f
MIT
Lissajous figures.ipynb
ScientificArchisman/Simulations
b9f3e7cc5d94a150931c12dac5fa21391736c47f
MIT
Lissajous figures.ipynb
ScientificArchisman/Simulations
b9f3e7cc5d94a150931c12dac5fa21391736c47f
MIT
Qwen/Qwen-72B
1. YES
2. YES