program RK1; (* Enkelt program i Pascal för Runge-Kuttas metod för första ordningens differentialekvation. dy/dx = x^2 + sin(xy) y(1) = 2 *) var antal, i : integer; h, k1, k2, k3, k4, x, y : real; function f(x,y : real) : real; begin f := x*x + sin(x*y) end; begin antal := 1; while antal > 0 do begin x := 1.0; y := 2.0; writeln(' Ge antal steg '); read(antal); if antal >= 1 then begin writeln(' Ge steglängd '); read(h); writeln(' x y'); writeln(x, y); for i := 1 to antal do begin k1 := h*f(x,y); k2 := h*f(x+0.5*h,y+0.5*k1); k3 := h*f(x+0.5*h,y+0.5*k2); k4 := h*f(x+h,y+k3); x := x + h; y := y + (k1+2*k2+2*k3+k4)/6; writeln(x, y); end; end; end; end.