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.