M

#### Mo711

##### Guest

But I want the system to be spring loaded. So instead of the mass hanging from a thread, I want the mass to hang from a spring, that rotates. I have tried putting the ODE together but it takes forever to calculate:

Code:

```
import sympy as sp
from IPython.display import display
R = sp.symbols('R')
omega = sp.symbols('omega')
t = sp.symbols('t')
phi = sp.Function('phi')(t)
theta = sp.Function('theta')(t)
s = sp.Function('s')(t)
L = sp.symbols('L')
m = sp.symbols('m')
k = sp.symbols('k')
g = sp.symbols('g')
x = R*sp.cos(omega*t)+(L+s)*(sp.sin(theta)*sp.cos(phi))
y = R*sp.sin(omega*t)+(L+s)*(sp.sin(theta)*sp.sin(phi))
z = -(L+s)*sp.cos(theta)
xs = sp.diff(x,t)
ys = sp.diff(y,t)
zs = sp.diff(z,t)
v = xs**2 + ys**2 + zs**2
Ekin = 0.5*m*v
Epot = g*(L+s)*sp.cos(theta)+0.5*k*s**2
L = Ekin + Epot
#display(L)
ELTheta = sp.diff(sp.diff(L,sp.Derivative(theta,t)), t) + sp.diff(L,theta)
ELPhi = sp.diff(sp.diff(L,sp.Derivative(phi,t)), t) + sp.diff(L,phi)
ELs = sp.diff(sp.diff(L,sp.Derivative(s,t)), t) + sp.diff(L,s)
Eq1 = sp.Eq(ELTheta,0)
Eq2 = sp.Eq(ELPhi,0)
Eq3 = sp.Eq(ELs,0)
LGS = sp.solve((Eq1,Eq2,Eq3),(sp.Derivative(theta,t,2),sp.Derivative(phi,t,2),sp.Derivative(s,t,2)))
thetadd = sp.simplify(LGS[sp.Derivative(theta,t,2)])
phidd = sp.simplify(LGS[sp.Derivative(phi,t,2)])
sdd = sp.simplify(LGS[sp.Derivative(s,t,2)])
```

I don't know whether I chose the right original condition. Is there a simpler and faster way to compute this or a different formula to the problem, that would simplify it?

<p>I want to write a simulation in Python similar to the one described in <a href="https://stackoverflow.com/questions/78227144/simulation-of-a-pendulum-hanging-on-a-spinning-disk">Simulation of a Pendulum hanging on a spinning Disk</a>.</p>

<p>But I want the system to be spring loaded. So instead of the mass hanging from a thread, I want the mass to hang from a spring, that rotates. I have tried putting the ODE together but it takes forever to calculate:</p>

<pre><code>import sympy as sp

from IPython.display import display

R = sp.symbols('R')

omega = sp.symbols('omega')

t = sp.symbols('t')

phi = sp.Function('phi')(t)

theta = sp.Function('theta')(t)

s = sp.Function('s')(t)

L = sp.symbols('L')

m = sp.symbols('m')

k = sp.symbols('k')

g = sp.symbols('g')

x = R*sp.cos(omega*t)+(L+s)*(sp.sin(theta)*sp.cos(phi))

y = R*sp.sin(omega*t)+(L+s)*(sp.sin(theta)*sp.sin(phi))

z = -(L+s)*sp.cos(theta)

xs = sp.diff(x,t)

ys = sp.diff(y,t)

zs = sp.diff(z,t)

v = xs**2 + ys**2 + zs**2

Ekin = 0.5*m*v

Epot = g*(L+s)*sp.cos(theta)+0.5*k*s**2

L = Ekin + Epot

#display(L)

ELTheta = sp.diff(sp.diff(L,sp.Derivative(theta,t)), t) + sp.diff(L,theta)

ELPhi = sp.diff(sp.diff(L,sp.Derivative(phi,t)), t) + sp.diff(L,phi)

ELs = sp.diff(sp.diff(L,sp.Derivative(s,t)), t) + sp.diff(L,s)

Eq1 = sp.Eq(ELTheta,0)

Eq2 = sp.Eq(ELPhi,0)

Eq3 = sp.Eq(ELs,0)

LGS = sp.solve((Eq1,Eq2,Eq3),(sp.Derivative(theta,t,2),sp.Derivative(phi,t,2),sp.Derivative(s,t,2)))

thetadd = sp.simplify(LGS[sp.Derivative(theta,t,2)])

phidd = sp.simplify(LGS[sp.Derivative(phi,t,2)])

sdd = sp.simplify(LGS[sp.Derivative(s,t,2)])

</code></pre>

<p>I don't know whether I chose the right original condition. Is there a simpler and faster way to compute this or a different formula to the problem, that would simplify it?</p>