Line Printer Graphics to Display Spring ODE Solution

**SPRING_ODE**
is 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.

This is a simple example of how to plot when you don't have a plotter. This is a particular kind of "ASCII graphics", or "typewriter graphics" or "lineprinter graphics", and shows you how valuable an illustration can be, even when it's as crude as this example.

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

F = - k xand 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/dtIf we write this as a pair of first order equations for (x,v), we have

dx/dt = v m * dv/dt = - k * x - c * vand now we can approximate these values for small time steps.

Note that the plotting assumes that the value of X will always be between -1 and +1. If the initial condition uses V = 0, and X starts between -1 and +1, then this will be OK.

The computer code and data files described and made available on this web page are distributed under the GNU LGPL license.

**SPRING_ODE** is available in
a C version and
a C++ version and
a FORTRAN90 version and
a MATLAB version.

ASCII_ART_GRAYSCALE, a data directory which contains examples of grayscale ASCII Art files, in which images are created using printable characters.

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.

LORENZ_ODE, a MATLAB program which approximates solutions to the Lorenz system, creating output files that can be displayed by gnuplot.

MANDELBROT_ASCII, a C program which generates an ASCII TEXT image of the Mandelbrot fractal set using just two lines of (very obscure) C.

PENDULUM_ODE, a MATLAB library which looks at some simple topics involving the linear and nonlinear ordinary differential equations (ODEs) that represent the behavior of a pendulum of length L under a gravitational force of strength G.

PREDATOR_PREY_ODE, a MATLAB program which solves a pair of predator prey ordinary differential equations (ODE's) using MATLAB's ode23() solver.

SPRING_ODE2, 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.

- spring_ode.m, the source code.
- spring_ode.txt, the output file.

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