32 lines
533 B
Plaintext
32 lines
533 B
Plaintext
'[RC] Runge-Kutta method
|
|
'initial conditions
|
|
x0 = 0
|
|
y0 = 1
|
|
'step
|
|
h = 0.1
|
|
'number of points
|
|
N=101
|
|
|
|
y=y0
|
|
FOR i = 0 TO N-1
|
|
x = x0+ i*h
|
|
IF x = INT(x) THEN
|
|
actual = exactY(x)
|
|
PRINT "y("; x ;") = "; y; TAB(20); "Error = "; actual - y
|
|
END IF
|
|
|
|
k1 = h*dydx(x,y)
|
|
k2 = h*dydx(x+h/2,y+k1/2)
|
|
k3 = h*dydx(x+h/2,y+k2/2)
|
|
k4 = h*dydx(x+h,y+k3)
|
|
y = y + 1/6 * (k1 + 2*k2 + 2*k3 + k4)
|
|
NEXT i
|
|
|
|
function dydx(x,y)
|
|
dydx=x*sqr(y)
|
|
end function
|
|
|
|
function exactY(x)
|
|
exactY=(x^2 + 4)^2 / 16
|
|
end function
|