In the first tutorial, we learned how to enter a single first-order ODE into ODE Toolkit. In this tutorial, we greatly expand the types of equations that we can work with to include second-order (and higher) ODE's. In addition, we learn how to define and use parameters in our equations. Note: In this tutorial, red text denotes invalid input to ODE Toolkit while green text denotes valid input.
Consider the following equation, used to model the motion of simple harmonic oscillators,
x'' + (omega^2)*x = 0The state variable x gives the system's displacement from its equilibrium point, and the parameter omega specifies the angular frequency of the system's oscillations about equilibrium. Your first inclination might be to enter the equation as-is, or, remembering that ODE's must be entered in normal form, you might try to enter it as x'' = -omega^2*x. Alas, it is not so simple. ODE Toolkit only supports first-order systems in normal form, but fortunately for us, almost any ODE of order n can always be written as an equivalent system of n first-order ODE's in normal form. To enter the simple harmonic oscillator equation, we introduce a new state variable, v, defined as the first time derivative of x. Thus, our second-order equation x''+omega^2*x=0 can be converted into a first-order equation by replacing x'' with v'. Now we have the following equivalent first-order system:
v' + omega^2*x = 0 v=x'
Remember, however, that all ODE's must be entered in normal form, so to
enter the system into ODE Toolkit, you would type the following into the
text input box:
v' = -omega^2*x
x' = v
Note that the derivatives of the state variables are always given on the left-hand-side of the equations and that the right-hand-sides of the equations are functions of the state variables and t only.
The above input is incomplete, however, since we have not defined
omega. To define omega and set it equal to pi, enter the
following line anywhere in the text input box:
omega = pi. Thus, the final input should look something like this:
v' = -omega^2*x
x' = v
omega = pi
There are three useful things to note about this input. First, although
each equation was entered on a separate line, they didn't have to be.
Equations can be entered on the same line as long
as they are separated from each other by semi-colons. Second, the order
in which the equations are entered does not matter. We could have just as
well have defined omega first or defined x' before v',
for instance. Third, ODE Toolkit ignores all spaces between identifiers
and operators, so the spaces around the equal signs are unnecessary.
For example, we could have entered the system like this:
omega=pi; v'= - omega ^ 2 * x;x' = v
...or like this:
x' = v
omega = pi; v' = - omega ^ 2 * x
...but not like this:
v' = -omega^2*x x' = v omega = pi