CONST
eps:Array[1..3] of Real=(0.01, 0.001, 0.0001);
VAR
Xmin,Xmax,Dx,X,S,Y:Real;
N,Var_f,Var_e,Var_meth:Byte;
i,j:Integer;
function Nfact(n:LongInt):Extended;
VAR
i:LongInt;
fact:Extended;
BEGIN
IF n=0 THEN fact:=1 ELSE
BEGIN
fact:=1;
FOR i:=1 TO n DO
fact:=fact*i;
END;
Nfact:=fact;
END;
function Y1(x:Real):Real;
begin
Y1:=Sin(x)/x;
end;
function Y2(x:Real):Real;
begin
Y2:=Exp(x)*Cos(x)+2;
end;
Function Sign(M:Byte):ShortInt;
begin
If (M mod 2) = 0 then Sign:=1 else Sign:=-1;
end;
Procedure Sum(f,t:Byte; Xs,e:real; var Ss:Real; var Ns:Byte);
var
Is:Integer;
Sss,Ass:Real;
Nss:Byte;
begin
If f=1 then
begin
If t=1 then
begin
Sss:=1;
Is:=0;
Repeat
Inc(Is);
Ass:=Exp(2*Is*Ln(Xs))/Nfact(2*Is+1)*Sign(Is);
Sss:=Sss+Ass;
Until (Abs(Ass)<e) or (Is=200);
end
else
begin
Sss:=1;
Is:=0;
Ass:=1;
Repeat
Inc(Is);
Ass:=-Ass*Sqr(Xs)/(2*Is)/(2*Is+1);
Sss:=Sss+Ass;
Until (Abs(Ass)<e) or (Is=200);
end;
end
else
begin
If t=1 then
begin
Sss:=3;
Is:=0;
Repeat
Inc(Is);
Ass:=Cos(Pi*Is/4)*Exp(Is*Ln(Xs*Sqrt(2)))/Nfact(Is);
Sss:=Sss+Ass;
Until ((Abs(Ass)>e/100) and (Abs(Ass)<e)) or (Is=200);
end
else
begin
Sss:=3;
Is:=0;
Ass:=1;
Repeat
Inc(Is);
Ass:=Ass*Sqrt(2)*(Xs)/Is/Cos(Pi*(Is-1)/4)*Cos(Pi*Is/4);
Sss:=Sss+Ass;
Until ((Abs(Ass)>e/100) and (Abs(Ass)<e)) or (Is=200);
end;
end;
Ss:=Sss;
Ns:=Is;
end;
BEGIN
Writeln('Enter the number of function:');
Writeln(' 1 - Sin(x)/x');
Writeln(' 2 - Exp(x)*Cos(x)+2');
Readln(Var_f);
If Var_f=1 then
begin
Xmin:=0.1;
Xmax:=0.5;
DX:=0.1;
end
else
begin
Xmin:=0.1;
Xmax:=0.7;
DX:=0.2;
end;
Writeln;
Writeln('Enter the type of calculation:');
Writeln(' 1 - each item separately');
Writeln(' 2 - next from previous');
Readln(Var_meth);
Writeln;
Writeln('Enter the accuracy number:');
Writeln(' 1 - 0.01');
Writeln(' 2 - 0.001');
Writeln(' 3 - 0.0001');
Readln(Var_e);
Writeln;
Writeln('argument accurate approximate number error');
Writeln(' value value of items');
X:=Xmin-DX;
Repeat
X:=X+DX;
If Var_f=1 then Y:=Y1(X) else Y:=Y2(X);
Sum(Var_f, Var_meth, X, Eps[Var_e], S, N);
Writeln(X:5:1,Y:14:5,S:15:5,N:9,Y-S:26:12);
Until X=Xmax;
Readln
END.