```python
from sympy import symbols, solve, cos
from sympy.physics.mechanics import dynamicsymbols, ReferenceFrame, Point, Particle
from sympy.physics.mechanics import RigidBody, inertia, KanesMethod, init_vprinting, Lagrangian, LagrangesMethod
```


```python
init_vprinting()
```


```python
x1, x2 = dynamicsymbols('x1, x2')
v1, v2 = dynamicsymbols('v1, v2')
m1, m2, k, g = symbols('m1, m2, k, g')
```


```python
N = ReferenceFrame('N')
```


```python
O = Point('O')
P1 = O.locatenew('P1', x1 * N.x)
P2 = O.locatenew('P2', x2 * N.x)
```


```python
O.set_vel(N, 0)
P1.set_vel(N, v1 * N.x)
P2.set_vel(N, v2 * N.x)
```


```python
block1 = Particle('block1', P1, m1)
block2 = Particle('block2', P2, m2)
```

# Kane's Method


```python
force1 = (P1, m1 * g * N.x - k * x1 * N.x + k * (x2 - x1) * N.x)
force2 = (P2, m2 * g * N.x - k * (x2 - x1) * N.x)
```


```python
kane = KanesMethod(N, (x1, x2), (v1, v2), kd_eqs=(x1.diff() - v1, x2.diff() - v2))
fr, frstar = kane.kanes_equations((force1, force2), (block1, block2))
```


```python
fr_plus_frstar = fr + frstar
fr_plus_frstar.simplify()
fr_plus_frstar
```

This gives the two equilibrium points:


```python
eq_points = solve(fr_plus_frstar.subs({v1.diff(): 0, v2.diff(): 0, v1: 0, v2: 0}), x1, x2)
eq_points
```

# Lagrange's Method


```python
P1.set_vel(N, x1.diff() * N.x)
P2.set_vel(N, x2.diff() * N.x)
```


```python
block1.kinetic_energy(N) + block2.kinetic_energy(N)
```


```python
block1.potential_energy = k * x1**2 / 2 + k * (x2 - x1)**2 / 2 - m1 * g * x1 
block2.potential_energy = -m2 * g * x2
```


```python
L = Lagrangian(N, block1, block2)
L
```


```python
lagrange = LagrangesMethod(L, (x1, x2))
```


```python
lagranges_equations = lagrange.form_lagranges_equations()
lagranges_equations.simplify()
lagranges_equations
```


```python
eq_points = solve(lagranges_equations.subs({x1.diff().diff(): 0,
                                            x2.diff().diff(): 0,
                                            x1.diff(): 0, x2.diff(): 0}), x1, x2)
eq_points
```

# Compare


```python
should_be_zero = fr_plus_frstar.subs({v1: x1.diff(), v2: x2.diff()}) + lagranges_equations
should_be_zero.simplify()
should_be_zero
```

7c9c932c894ccc9481ce7ea2f5dd0a6c419eca75
ipynb
Jupyter Notebook
content/materials/notebooks/two_masses_with_springs_in_series.ipynb
greg1877/eng122
3a9821f41c860e190cd3c8285fac212ae897337b
CC-BY-4.0
2020-05-11T05:56:54.000Z
2020-12-20T13:44:12.000Z
content/materials/notebooks/two_masses_with_springs_in_series.ipynb
greg1877/eng122
3a9821f41c860e190cd3c8285fac212ae897337b
CC-BY-4.0
2016-09-20T01:26:33.000Z
2020-01-22T02:10:33.000Z
content/materials/notebooks/two_masses_with_springs_in_series.ipynb
greg1877/eng122
3a9821f41c860e190cd3c8285fac212ae897337b
CC-BY-4.0
2017-06-09T01:28:45.000Z
2020-02-29T02:36:18.000Z
Qwen/Qwen-72B
1. YES
2. YES