Question: Trouble with RK4 (Runge-Kutta)!

January 11 2013 gabrielmp 5
Maple 15

0

Hi guys. I need to do a Runge-Kutta method to solve two equations and I'm having trouble at using functions. My program is as shown below:

restart; A := Matrix();

dt := 0.1e-2;

diff(x(t), t) := v;

diff(v, t) := a(x(t), v);

xo := 0; vo := 0;

for i to 1000 do

xn := xo+v.dt;

vn := vo+a.dt;

dx1 := vn.dt; dv1 := a.dt;

dx2 := (vn+(1/2)*dv1)*dt; dv2 := a(x(t)+(1/2)*dx1, (1/2)*dv1)*dt;

dx3 := (vn+(1/2)*dv2)*dt; dv3 := a(xn+(1/2)*dx2, vn+(1/2)*dv2)*dt;

dx4 := (vn+dv3)*dt; dv4 := a(xn+dx3, vn+dv3)*dt;

xn := (xo+dx1+2.*dx2+2.*dx3+dx4)*(1/6);

vn := (vo+dv1+2.*dv2+2.*dv3+dv4)*(1/6);

A(i, 1) := xn; A(i, 2) := vn; A(i, 3) := i*dt;

xo := xn;

vo := vn

end do;

ExportMatrix("RK4.txt", A)

The program is not working and I still don't know what I'm doing wrong. Any help would be great!

Thanks a lot !

Please Wait...