Cosine Waves

This is a simulation of a cosine. Use the start and stop buttons to run the model.

The period determines how often the calculations are executed. Enter a new number (in milliseconds) and press the period button. A lower number makes the simulation cycle faster.

The time step is a numerical parameter in the model. For the simulationists in the crowd, it is the dt in seconds. A smaller number will result in a more accurate simulation. However, there is a rate of diminishing returns. If the time step is too small, the CPU is doing a lot of work for very little gain.

When the period is equal to the time step, the model is running at real time. Try a period of 100 ms with a time step of 0.1 seconds.

The sine waves are generated by solving the second order differential equation

    y'' + y = 0

By representing y' as x, taking the derivative and substituting x' for y'', you can form two first order equations.

    y' = x
    x' = -y

These are solved with a modified Euler integration yielding, at the least, stable oscillations for time steps of 1.0 or less. The analytical solution is

    y = sin( t )

The animated bar graphs are showing four phases of the sine wave, in an attempt to be entertaining. The bar graphs are specialized widgets designed by Simulation Tools. They are written in Java; everything else, on this page, is written in JavaScript.

© 1997 Simulation Tools, Inc.