Given the IVP y(1)(t = t y(t) - t2 + 1 with y(0) = 3, to approximate y(1), we can do:
t[0] := 0; t[1] := 1; y[0] := 3; f := (t, y) -> t*y - t^2 + 1; h := t[1] - t[0]; K[0] := f(t[0], y[0] ); K[1] := f(t[0] + h/2, y[0] + h/2*K[0]); K[2] := f(t[0] + h/2, y[0] + h/2*K[1]); K[3] := f(t[0] + h , y[0] + h*K[2]); y[1] := y[0] + h*(K[0] + 2*K[1] + 2*K[2] + K[3])/6;
Copyright ©2005 by Douglas Wilhelm Harder. All rights reserved.