Var a,b,h,eps,s1,s2,s:real; n,i:integer; function f(x:real):real; begin f:=exp(2*x)-2*x*x; end; begin readln(a,b,eps); n:=10; s2:=0; s:=(f(a)+f(b))/2; repeat s1:=s2; s2:=s; h:=(b-a)/n; for i:=1 to n-1 do s2:=s2+f(a+i*h); s2:=s2*h; writeln(n,' ',h:6:4,' ',s1:6:3,' ',s2:6:3); n:=n*2; until abs(s1-s2)<eps; end.
Answers & Comments
Verified answer
Var a,b,h,eps,s1,s2,s:real; n,i:integer;function f(x:real):real;
begin
f:=exp(2*x)-2*x*x;
end;
begin
readln(a,b,eps);
n:=10;
s2:=0;
s:=(f(a)+f(b))/2;
repeat
s1:=s2;
s2:=s;
h:=(b-a)/n;
for i:=1 to n-1 do s2:=s2+f(a+i*h);
s2:=s2*h;
writeln(n,' ',h:6:4,' ',s1:6:3,' ',s2:6:3);
n:=n*2;
until abs(s1-s2)<eps;
end.
Пример (для ε=0,01):
1 2 0.01
10 0.1000 0.000 19.013
20 0.0500 19.013 18.957
40 0.0250 18.957 18.943
80 0.0125 18.943 18.939