You can run .pas file in Turbo Pascal 7.0
Integral is calculated by the Simpson's rule.
Here is the program:
program NumIntegration;
uses Crt;
const a=0.0; b=10.0;
function U(x : real) : real;
begin
U:= x * x;
end;
function rectang(a,b, delta : real) : real;
var h,l1n,l2n,teta,Delta2n,xi : real; j,n : word;
begin
teta:=1/3;
delta2n:=delta + 1;
n:=7;
l1n:=0;
l2n:=0;
repeat
l1n := l2n;
l2n := 0;
H:=(b-a)/(2*n);
{Calculate l2}
for j:=1 to 2*n-1 do
begin
xi:=a+j*H;
l2n := l2n + U(xi);
end;
l2n:= l2n + (U(a) + U(b)) / 2;
l2n:=l2n*H;
Delta2n:=teta*abs(l1n-l2n);
n:=2*n; { double the number of subintervals}
until Delta2n <= delta;
rectang:=l2n;
end:{rectang}
var S : real; Delta : real;
BEGIN
Delta:=0.001; {accuracy}
clrscr;
S:=rectang(a,b,delta);
writeLN('S=',S:7:3);
readkey;
END.
Comments