DECLARE FUNCTION f# (x AS DOUBLE)
DECLARE FUNCTION Integ# (a AS DOUBLE, b AS DOUBLE, n AS LONG)
'Main program
DIM eps AS DOUBLE, n AS LONG, s AS DOUBLE, s1 AS DOUBLE
DIM a AS DOUBLE, b AS DOUBLE
CLS
a = 0: b = 1: eps = .001
n = 100
s = Integ#(a, b, 10#)
DO
s1 = s
s = Integ#(a, b, n)
n = n * 2
LOOP UNTIL ABS(s - s1) <= eps<br>PRINT s
END
FUNCTION f# (x AS DOUBLE)
f# = x ^ 3 * EXP(x ^ 2)
END FUNCTION
FUNCTION Integ# (a AS DOUBLE, b AS DOUBLE, n AS LONG)
DIM h AS DOUBLE, xb AS DOUBLE, x AS DOUBLE
DIM s AS DOUBLE, i AS INTEGER
h = (b - a) / n
s = 0
xb = a
FOR i = 0 TO n - 1
x = xb + i * h
s = s + f(x) * h
NEXT i
Integ# = s
END FUNCTION
Результат выполнения программы:
.4991509793572241
Погрешность не превышает 0.001 при контрольном значении, равном 0.5