2
$\begingroup$

I have written a program that produces a Lagrangian. Additionally, I need damping for the spring I am simulating in the Lagrangian. Here is the 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 + ys + zs
vq =v**2
Ekin = 0.5*m*vq
Epot = g*(L+s)*sp.cos(theta)+0.5*k*s**2

#display(vq)
#display(xs)

L = Ekin + Epot

#display(L)

ELTheta = sp.solve(sp.diff(sp.diff(L,sp.Derivative(theta,t)), t) + sp.diff(L,theta),theta)
ELPhi = sp.solve(sp.diff(sp.diff(L,sp.Derivative(phi,t)), t) + sp.diff(L,phi),phi)
ELs = sp.solve(sp.diff(sp.diff(L,sp.Derivative(s,t)), t) + sp.diff(L,s),s)
#display(ELTheta)
#display(ELPhi)
#display(ELs)

The Lagrangian is supposed to describe a pendulum hanging from a spinning disk, that is suspended with a spring.

My idea is that the numerical solution and its visualisation don't look like they are supposed to, because the spring isn't damped. The deflection adds up and the result is not plausible.

I don't know how to add damping on to the spring, maybe you can help.

$\endgroup$
2
  • $\begingroup$ Perhaps you could write the Lagrangian you expect to have for the damped spring in the post and then compare an analytical approach. Per the computational-physics guidelines, we do not aid in debugging or writing code. $\endgroup$
    – Kyle Kanos
    Commented Jun 13 at 12:32
  • $\begingroup$ @Kyle Kanos Oh thanks for the notice $\endgroup$
    – Mo711
    Commented Jun 14 at 6:52

0