Code and Math

System dynamics for the wave machine can be described mathematically, using equations.

Computer code is the "machine" that implements the mathematical models of system dynamics. The two forms look somewhat different from each other.

Math models are defined by concise, specialized forms such as differential equations.

Waves are described by a wide variety of equations, depending on the type of wave.


(∂/∂t  c∂/∂x) (∂/∂t + c∂/∂x) u(t, x) = 0

This equation means that the rate of change in time is proportional to rate of change in space. The equation is computed at each turtle's position, for each time step in the simulation.

The function u(t, x) represents the quantities that changes. (position and velocity)

"c" is the value (often just a number) that determines proportionality.

If c = 1, then the rate of change in time is equal to the rate of change in space.

If c = 2, then the rate of change in time is twice the rate of change in space.

Computer code is more mechanical:

There is rarely anything abstract about simulation code. Typical forms are similar to:

The differential equations of the math model are written as difference equations in computer code. They look more like basic math, such as algebra and arithmetic.

g = ( f(x)  f(x + h) ) / h

f(x) corresponds to u(t, x) in the wave equation mentioned above.

h is a small change in the system. This could be time , distance or both.

For the wave machine, the changing quantities are the vertical height, and the velocity.

Only the velocity is actually computed using a difference equation:

velocity = velocity +
(stiffness * (sum( neighborturtles [z] )  z)))

The vertical height ( z ) is used as data for the equation, just as the friction and stiffness parameters are used as data.

After the velocity for each turtle is computed for the new time step, the turtle's height is computed from the new velocity:

