```
In [1]:
```from IPython.display import SVG
SVG(filename='mass_spring_damper.svg')

```
Out[1]:
```

Start by loading in the core functionality of both SymPy and Mechanics.

```
In [2]:
```import sympy as sym
import sympy.physics.mechanics as me

We can make use of the pretty printing of our results by loading the SymPy printing extension.

```
In [3]:
```%load_ext sympy.interactive.ipythonprinting

```
In [4]:
```x, v = me.dynamicsymbols('x v')

```
In [5]:
```m, c, k, g, t = sym.symbols('m c k g t')

```
In [6]:
```ceiling = me.ReferenceFrame('C')

```
In [7]:
```o = me.Point('o')
p = me.Point('p')

The velocity of point $o$ in the ceiling is zero.

```
In [8]:
```o.set_vel(ceiling, 0)

Point $p$ can move downward in the $x$ direction and it's velocity is $v$ in the downward direction.

```
In [9]:
```p.set_pos(o, x * ceiling.x)
p.set_vel(ceiling, v * ceiling.x)

```
In [10]:
```damping = -c * p.vel(ceiling)
stiffness = -k * p.pos_from(o)
gravity = m * g * ceiling.x
forces = damping + stiffness + gravity
forces

```
Out[10]:
```

Now we can use Newton's second law, $0=F-ma$, to form the equation of motion of the system.

```
In [11]:
```zero = me.dot(forces - m * p.acc(ceiling), ceiling.x)
zero

```
Out[11]:
```

```
In [12]:
```dvdt = sym.solve(zero, v.diff(t))[0]
dxdt = v
dvdt, dxdt

```
Out[12]:
```

`LagrangesMethod`

and `KanesMethod`

. Here we will make use of Kane's method to find the same equations of motion which we found manually above. First define a particle which represents the mass attached to the damper and spring.

```
In [13]:
```mass = me.Particle('mass', p, m)

`KanesMethod`

object by passing in the generalized coordinate, $x$, the generalized speed, $v$, and the kinematical differential equation which relates the two, $0=v-\frac{dx}{dt}$.

```
In [14]:
```kane = me.KanesMethod(ceiling, q_ind=[x], u_ind=[v], kd_eqs=[v - x.diff(t)])

Now Kane's equations can be computed which returns $F_r$ and $F_r^*$.

```
In [15]:
```kane.kanes_equations([(p, forces)], [mass])

```
Out[15]:
```

```
In [16]:
```M = kane.mass_matrix_full
f = kane.forcing_full
M, f

```
Out[16]:
```

```
In [17]:
```M.inv() * f

```
Out[17]:
```