Simulating mass-spring-damper system with lagrangian mechanics

Becouse of damping term, Lagrangian equation looks like this:
\(\frac{d}{dt}\frac{\partial \mathcal{L}}{\partial \dot{x}}-\frac{\partial \mathcal{L}}{\partial x} = - \frac{\partial D}{\partial \dot{x}}\)
Potential energy of the mass is given by \( V = -m g h \)
Potential energy of the spring is given by \( V = \frac{1}{2} k x^2 \)
Kinetic energy of the mass is given by \( T = \frac{1}{2} m \dot{x}^2 \)
Energy disipated by the damper is given by \( D = \frac{1}{2} b \dot{x}^2 \)
\( \mathcal{L} = T-V = \frac{1}{2} m \dot{x}^2 + m g h - \frac{1}{2} k x^2\)
Lagrange equation is then:
\(m\ddot{x}-mg+kx = -b \dot{x}\)
Rearanging a bit:
\(\ddot{x} = \frac{mg-kx-b\dot{x}}{m}\), substituting \(\dot{x} = v\) we get differential equations:
\(\begin{aligned} \dot{x} &= v \\ \dot{v} &= \frac{mg-kx-bv}{m} \end{aligned}\), where \(m\) is mass, \(k\) is spring stifness, \(b\) is damper stifness, \(g\) is gravity and \(x\) is position of the mass.


Mass (m) \([ kg ]\)
Spring stifness (k) \([ kg \cdot m\cdot s^{-2} ]\)
Damper stifness (b) \([ kg \cdot s^{-1} ]\)
Gravity (g) \([ m \cdot s^{-2} ]\)