ODE Example

var {define the variables}

SHO:T_ODE;

Func:funcArray;

x:Variables;

dx:Double;

{Define the differential equations in the next three functions.}

Function f1(x:Variables):Double; far;

{Angle rate of change.}

begin

f1:=x[2];

end;

Function f2(x:Variables):Double; far;

{Omega rate of change.}

begin

f2:=-Sin(x[1]);

end;

Function f3(x:Variables):Double; far;

{Time rate of change.}

begin

f3:=1;

end;

procedure TPend_frm.FormCreate(Sender: TObject);

{Initialize the variables and the ODE when the form is created.}

var i:Integer; theta:Double;

begin

func[1]:=f1; {These three lines set the ODE rate functions.}

func[2]:=f2;

func[3]:=f3;

SHO:=T_ODE.Create(3,func); {Create and initialize the ODE solver.}

dx:=0.2; {Set the time step}

end;

procedure TPend_frm.StepTimer(Sender: TObject);

{This is what is called by the Windows system timer. Do an RK4 Step and plot the results.}

var xPix,yPix:Integer;

begin

sho.RK4Step(dx,x); {This does the physics!}

thetaPlot.RegisterAndPlot(3,x[3],x[1]);

thetaPlot.RegisterAndPlot(4,x[3],x[2]);

end;