# SPRING_ODE2 Gnuplot Graphics to Display Spring ODE Solution

SPRING_ODE2 is a MATLAB program which shows how Gnuplot graphics can be used to illustrate a solution of the ordinary differential equation (ODE) that describes the motion of a weight attached to a spring.

This program is a revision of the SPRING_ODE program. A second change that we make is that we use vectors to store the data.

Hooke's law for a spring observes that the restoring force is proportional to the displacement:

```        F = - k x
```
and Newton's law relates the force to acceleration:
```        F = m a
```

Putting these equations together, we have:

```        m * d^2 x/dt^2 = - k * x
```

We can add a damping force with coefficient c:

```        m * d^2 x/dt^2 = - k * x - c * dx/dt
```
If we write this as a pair of first order equations for (x,v), we have
```            dx/dt = v
m * dv/dt = - k * x - c * v
```
and now we can approximate these values for small time steps.

### Languages:

SPRING_ODE2 is available in a C version and a C++ version and a FORTRAN77 version and a FORTRAN90 version and a MATLAB version.

### Related Data and Programs:

FLAME_ODE, a MATLAB library which considers an ordinary differential equation (ODE) which models the growth of a ball of flame in a combustion process.

GNUPLOT, examples which illustrate the use of the gnuplot graphics program.

GRAPHICS_EXAMPLES_GNUPLOT, gnuplot scripts which illustrate how various kinds of data can be displayed and analyzed graphically using the interactive executable graphics program GNUPLOT.

SPRING_ODE, a MATLAB program which shows how line printer graphics can be used to make a crude illustration of a solution of the ordinary differential equation (ODE) that describes the motion of a weight attached to a spring.

### Examples and Tests:

• spring_ode2_output.txt, the output file, which contains just the graphics data.
• xv_time.png, a time plot, created by gnuplot, of the displacement x and velocity v.
• xv_phase.png, a phase plot, created by gnuplot, of the displacement x and velocity v.

You can go up one level to the MATLAB source codes.

Last revised on 27 June 2012.