```python
from sympy import *
from sympy.physics.mechanics import *

mass, R, c1, c2, grav = var("mass, R, c1, c2, grav", real=True, positive=True)
omega = var("omega", real=True, positive=True)

x, phi = dynamicsymbols('x, phi')
xp, phip = dynamicsymbols('x, phi', 1)

J = mass*R**2/2

T = J*phip**2/2 + mass*xp**2/2
U = - mass*grav*x + c1/2 * (x - R*phi)**2 + c2/2 * (x + R*phi)**2
L = T - U

pprint("\nL:")
pprint(L)
LM = LagrangesMethod(L, [x,phi])

# pprint(L.expand().collect([p1,p2,p3,p4]))

LM.form_lagranges_equations()
M = LM.mass_matrix
f = LM.forcing

pprint("\nMass matrix:")
pprint(M)
pprint("\nForce matrix (not stiffness matrix)")
pprint(f)
for i in range(2):
    print("--- Row "+str(i+1)+":")
    term = -1*f[i].expand()
    pprint(term.collect([x,phi]))

from sympy.abc import x, y
system = Matrix([
    (c1 + c2, R*(-c1 + c2), mass*grav), (R*(-c1 + c2), R**2*(c1 + c2), 0)
    ])
sol = solve_linear_system(system, x,y)
x0 = sol[x]
p0 = sol[y]

pprint("\nx0:")
pprint(x0)
pprint("\np0:")
pprint(p0)

```

f7ce141ed7e9a35f77053d95eea7ec5104a60e81
ipynb
Jupyter Notebook
ipynb/EMS_04/Selbst/4.7.ipynb
kassbohm/wb-snippets
f1ac5194e9f60a9260d096ba5ed1ce40b844a3fe
MIT
ipynb/EMS_04/Selbst/4.7.ipynb
kassbohm/wb-snippets
f1ac5194e9f60a9260d096ba5ed1ce40b844a3fe
MIT
ipynb/EMS_04/Selbst/4.7.ipynb
kassbohm/wb-snippets
f1ac5194e9f60a9260d096ba5ed1ce40b844a3fe
MIT
Qwen/Qwen-72B
1. YES
2. YES