Need help with the formula
Hi
Need help with the formula:
Code:
Program Simpson;
uses Crt;
const
a=1;
b=3;
var
n,l:integer;
eps,g1,g2:real;
function f(x:real):real;
begin
f:=x;
end;
procedure Simp(n1:integer;var s:real);
var
i:integer;
h:real;
s1,s2:real;
begin
h:=(b-a)/n1;
s1:=0;
s2:=0;
for i:=1 to n1-1 do
if i mod 2=0 then s1:=s1+f(a+i*h)
else s2:=s2+f(a+i*h);
s:=h/3*(f(a)+f(b)+2*s2+4*s1);
end;{end Simp}
begin {Main}
ClrScr;
write('n='); readln(n);
writeln;
Simp(n,g1);
eps:=-1; l:=0;
repeat
n:=2*n;
Simp(n,g2);
eps:=abs(g1-g2);
g1:=g2;
l:=l+1;
until (eps<1e-3 ) or (l>100);
if l>100 then writeln('rozbigna')
else begin
writeln('g=',g2);
writeln('n=',n);
writeln('l=',l);
end;
readln;
end. {end Main}