The model evolution
As a generic example, let us name our model variables as
The system developes from the current state of the variables
In EJS two ways are available to implement evolution from state to state: direct mathematical expressions and differential equations.
An animation of a harmonic oscillator can be created by specifying (in code that complies with Java syntax) the following expression, which has the x-coordinate as a function of time.
But in the actual world an oscillator will experience some form of friction. With friction the oscillation will decay, but what will the decay look like? To obtain an answer to that question the setup must be framed in the form of differential equations. In EJS the differential equations that can be entered are of the type called ‘Ordinary Differential Equation’ (ODE).
On an empty evolution panel the top half says ‘Click to create a page of code’, and the bottom half says ‘Click to create a page of ODEs’.
Three factors affect the rate at which the simulation is computed, and the rate at which it is displayed: the Increment, the Frames Per Second (FPS) and the Steps Per Display (SPD).
20 frames per second is a good choice, and there is rarely a situation where there is any benefit in choosing another frame rate.
With the settings as displayed in the image, increment at 0.05 and SPD at 1, the simulation will unfold in real time.
If the increment is set to for example 0.01 then simulation time will progress 5 times slower than real time. To compensate for that you can adjust the SPD entry. With SPD at 5 the simulation will process 5 increment steps in between displayed frames. With FPS at 20, increment at 0.01 and SPD at 5 the simulation will proceed in real time again.
The slider position and the value in the number field FPS are connected. Moving the slider will reflect in the number field, and the other way round.
If the checkbox Autoplay is checked the simulation will start automatically when the program is opened.