- , QBasic.
(Y¢(x))
FUNCTION f (x, y0)
f = < >
END FUNCTION
(, b), (h), (0)
- .
-
QBasic:
1. Alt -
2. EditNew SUB -
3. EditNew FUNCTION -
4. (: eiler)
:
SUB < , >
< >
END SUB
1. SUB END SUB
2. .
3. F2.
QBASIC
QBasic
DECLARE SUB eiler (a!, b!, h!, y0!)
DECLARE SUB koshi (a!, b!, h!, y0!)
DECLARE SUB runge (a!, b!, h!, y0!)
DECLARE FUNCTION f! (x!, y0!)
CLS
DIM SHARED eilerM(1000), koshiM(1000), rungeM(1000)
INPUT " a= "; a
INPUT " b= "; b
INPUT " "; h
INPUT " Y0= "; y0
yy = y0 '
REM
CALL eiler(a, b, h, yy)
yy = y0
REM -
CALL koshi(a, b, h, yy)
yy = y0
REM -
CALL runge(a, b, h, yy)
PRINT "--------------------------------------------------------------"
PRINT "│ x │ elier │ koshi │ runge │"
PRINT "--------------------------------------------------------------"
L$ = "│ #.# │ ##.##### │ ##.##### │ ##.##### │"
i = 1
FOR x = a TO b + h / 2 STEP h
PRINT USING L$; x; eilerM(i); koshiM(i); rungeM(i)
i = i + 1
NEXT x
PRINT "--------------------------------------------------------------"
END
Save All.
:
SUB eiler (a, b, h, y0)
i = 1
eilerM(i) = y0
FOR x = a TO b + h / 2 STEP h
y = y0 + h * f(x, y0)
y0 = y
i = i + 1
eilerM(i) = y0
NEXT x
END SUB
-:
SUB koshi (a, b, h, y0)
i = 1
koshiM(i) = y0
FOR x = a TO b + h / 2 STEP h
k1 = h * f(x, y0)
k2 = h * f(x + h, y0 + k1)
|
|
y = y0 + (k1 + k2) / 2
y0 = y
i = i + 1
koshiM(i) = y0
NEXT x
END SUB
-:
SUB runge (a, b, h, y0)
i = 1
rungeM(i) = y0
FOR x = a TO b + h / 2 STEP h
k1 = h * f(x, y0)
k2 = h * f(x + h / 2, y0 + k1 / 2)
k3 = h * f(x + h / 2, y0 + k2 / 2)
k4 = h * f(x + h, y0 + k3)
y = y0 + (k1 + 2 * k2 + 2 * k3 + k4) / 6
y0 = y
i = i + 1
rungeM(i) = y0
NEXT x
END SUB
:
FUNCTION f (x, y0)
f = < >
END FUNCTION