```python
import scipy
from scipy.misc import derivative
import math
```


```python
def f(x):
    return math.sin(x)
```


```python
# Importing the best package ever
from sympy import *
init_printing(use_unicode=True)
```


```python
# Variable Initialization
from sympy.physics.vector import dynamicsymbols
theta, phi, sigma, psi, theta_dot, phi_dot, sigma_dot, psi_dot, x_dot, x= dynamicsymbols("theta phi sigma psi theta_dot phi_dot sigma_dot psi_dot x_dot x")
l1, l2, l3, l4, m1, m2, m3, m4, g = symbols("l1 l2 l3 l4 m1 m2 m3 m4 g")

```


```python
# Potential Energy
arg1 = l1*cos(theta)
arg2 = l1*cos(theta) + l2*cos(phi)
arg3 = l1*cos(theta) + l2*cos(phi) + l3*cos(sigma)
arg4 = l1*cos(theta) + l2*cos(phi) + l3*cos(sigma) + l4*cos(psi)
pe = g*(m1*(arg1) + m2*(arg2) + m3*(arg3) + m4*(arg4))
```


```python
# Kinetic Energy
argv1_x = x_dot - theta_dot*l1*cos(theta)
argv2_x = x_dot - theta_dot*l1*cos(theta) - phi_dot*l2*cos(phi)
argv3_x = x_dot - theta_dot*l1*cos(theta) - phi_dot*l2*cos(phi)
- sigma_dot*l3*sin(sigma)
argv4_x = x_dot - theta_dot*l1*cos(theta) - phi_dot*l2*cos(phi)
- sigma_dot*l3*sin(sigma) - psi_dot*l4*sin(psi)

# all the y dir stuff
argv1_y = -l1*theta_dot*sin(theta)
argv2_y = -l1*theta_dot*sin(theta) - phi_dot*l2*sin(phi)
argv3_y = -l1*theta_dot*sin(theta) - phi_dot*l2*sin(phi)
- sigma_dot*l3*sin(sigma)
argv4_y = -l1*theta_dot*sin(theta) - phi_dot*l2*sin(phi)
- sigma_dot*l3*sin(sigma) - psi_dot*l4*sin(psi)

#kinetic energy of the system
ke = 1/2*(m1*(argv1_x**2 + argv1_y**2) + m2*(argv2_x**2 + argv2_y**2) + 
         m3*(argv3_x**2 + argv3_y**2) + m4*(argv4_x**2 + argv4_y**2))

```


```python
#Construction the Lagrangian
L = ke - pe
```


```python
(Derivative(L, theta_dot)).diff(t,1) - Derivative(L, theta)
WRT_THETA = (diff(L, theta_dot)).diff(t,1) - diff(L, theta)
WRT_THETA
```


```python
(Derivative(L, phi_dot)).diff(t,1) - Derivative(L, phi)
WRT_PHI = (diff(L, phi_dot)).diff(t,1) - diff(L, phi)
WRT_PHI
```


```python
(Derivative(L, sigma_dot)).diff(t,1) - Derivative(L, sigma)
WRT_SIGMA = (diff(L, sigma_dot)).diff(t,1) - diff(L, sigma)
WRT_SIGMA
```


```python
(Derivative(L, psi)).diff(t,1) - Derivative(L, psi)
WRT_PSI = (diff(L, psi_dot)).diff(t,1) - diff(L, psi)
WRT_PSI
```


```python
(Derivative(L, x_dot)).diff(t,1) - Derivative(L, x)
WRT_X = (diff(L, x_dot)).diff(t,1) - diff(L, x)
WRT_X
```


```python

```

9b1ffaa854fd5b966b485626d61ca96fee8d1a94
ipynb
Jupyter Notebook
Equations/Quad_Inverted_Pendulum.ipynb
shauray8/quadruple_inverted_pendulum
3b5746c534423d39da2582d4bae54ea7ecdacffd
MIT
Equations/Quad_Inverted_Pendulum.ipynb
shauray8/quadruple_inverted_pendulum
3b5746c534423d39da2582d4bae54ea7ecdacffd
MIT
Equations/Quad_Inverted_Pendulum.ipynb
shauray8/quadruple_inverted_pendulum
3b5746c534423d39da2582d4bae54ea7ecdacffd
MIT
Qwen/Qwen-72B
1. YES
2. YES