Скачиваний:
27
Добавлен:
09.12.2013
Размер:
2.71 Кб
Скачать
program lab2;
uses crt;
const n=4;a=1.2;b=0.4;
t:array[0..n] of real=(0.9062,0.5385,0,-0.5385,-0.9062);
c:array[0..n] of real=(0.2369,0.4786,0.5689,0.4786,0.2369);
var i,j:integer;
s,bank,Q,P,H,H1,hs,hch,Eps1,hh1,Q1,Eps,Eps2,H2,Q2,Eps3,x,y,z:real;

{¤ ­­ п дг­ЄжЁп}
function f(x:real):real;
begin
f:=sqrt(x)*cos(sqr(x));
end;

{д®а¬г«  ѓ гбб }
function gauss(dawn,up:real):real;
begin
s:=0;
for i:=0 to n do
s:=s+c[i]*f((dawn+up)/2+(up-dawn)/2*t[i]);
s:=(up-dawn)/2*s;
gauss:=s;
end;

{д®а¬г«  ва ЇҐжЁ©}
function trap(dawn,up:real):real;
var h1:real;
begin
h1:=(up-dawn);
trap:=h1/6*(f(dawn)+f(up)+4*f(dawn+h1));
end;

{Џ®ЁбЄ Ї®¤е®¤п饣® ®в१Є }
procedure step(lim1,lim2:real;v:integer; var z:real);
begin
if v=1 then
repeat
h:=lim2-lim1;
q:=trap(lim1,lim2);
p:=trap(lim1,lim1+h/2)+trap(lim1+h/2,lim2);
z:=lim2;eps1:=abs(p-q)/31;
lim2:=lim1+(lim2-lim1)/2;
until eps1<=(h/(b-a)*Eps)
else repeat
h:=lim2-lim1;
q:=gauss(lim1,lim2);
p:=gauss(lim1,lim1+h/2)+gauss(lim1+h/2,lim2);
z:=lim2;eps1:=abs(p-q)/31;
lim2:=lim1+(lim2-lim1)/2;
until eps1<=(h/(b-a)*Eps);
end;

Begin
clrscr;
x:=a;y:=b;i:=0;
H1:=0;hs:=0;Q1:=0;
Eps2:=0;bank:=0;
write('Џ®ЈаҐи­®бвм=');
read(Eps);
clrscr;

textcolor(yellow);
writeln('”®а¬г«  ва ЇҐжЁЁ:');
writeln;
repeat
x:=x-bank;
step(x,y,1,z);
hs:=Eps1*(b-a)/Eps;
bank:=h-hs;
q:=trap(x,z-bank);
i:=i+1;
x:=z;y:=b;
H1:=H1+hs;
Q1:=Q1+q;
Eps2:=Eps2+Eps1;textcolor(lightgreen);
writeln('i= ' ,i,' h= ',hs:3,' Q= ',q:3,' e=',Eps1:3);
until x=y ;
step(b-bank,b,1,z);
H1:=H1+h;
Q1:=Q1+q;
Eps2:=Eps2+Eps1;textcolor(lightred);
writeln('Ў ­Є: h=',h:2:2,' Q=',q:2:2,' e=',eps1);
writeln('б㬬Ёа®ў ­ЁҐ: h=',h1:2:2,' Q=',q1,' e=',eps2);

readln;readln;
x:=a;y:=b;
j:=0;
H2:=0;Q2:=0;
hch:=0;
Eps3:=0;bank:=0;textcolor(yellow);
writeln('”®а¬г«  ѓ гбб :');
writeln;
repeat
x:=x-bank;
step(x,y,2,z);
j:=j+1;
hch:=Eps1*(b-a)/Eps;
bank:=h-hch;
q:=gauss(x,z-bank);
x:=z;
y:=b;
H2:=H2+hch;Q2:=Q2+q;
textcolor(lightgreen);
Eps3:=Eps3+Eps1;
writeln('i=' ,j:2,' h= ',hch:2:2,' Q=',q:2:2,' e=',Eps1);
until x=y ;
step(b-bank,b,2,z);
j:=j+1;
H2:=H2+h;
Q2:=Q2+q;
Eps3:=Eps3+Eps1;
textcolor(lightred);
writeln('Ў ­Є: h=',h:10:5,' Q=',q:10:5,' e=',eps1);
writeln('б㬬Ёа®ў ­ЁҐ: h=',h2:10:5,' Q=',q2,' e=',eps3);

readln;
end.

Соседние файлы в папке Мишины