program e_1 (input,output);
uses crt;
type TF = function(x:real):real;
var x1,x2,x3,I1,I2,I,i11,i21,I12,I22,k1,k2,eps1,eps:real;
    n0,k,l,o:longint;
    m:boolean;
{----------------------------------------------------------------------------}
{$F+}
{1}{Function F1(x:real):real;
         begin
         f1:=exp(ln(2)*x)+1
         end;
Function F11(x:real):real;
         begin
         f11:=exp(ln(2)*x)*ln(2)
         end;
Function F2(x:real):real;
         begin
         f2:=sqr(sqr(x))*x
         end;
Function F21(x:real):real;
         begin
         f21:=5*sqr(sqr(x))
         end;
Function F3(x:real):real;
         begin
         f3:=(1-x)/3;
         end;
Function F31(x:real):real;
         begin
         f31:=-1/3
         end;}
{----------------------------------------------------------------------------}
{2}{Function F1(x:real):real;
         begin
         f1:=5/x
         end;
Function F11(x:real):real;
         begin
         f11:=-10/sqr(x)
         end;
Function F2(x:real):real;
         begin
         f2:=2.5*x-9.5
         end;
Function F21(x:real):real;
         begin
         f21:=2.5
         end;
Function F3(x:real):real;
         begin
         f3:=1.5/(1+x)+3;
         end;
Function F31(x:real):real;
         begin
         f31:=-1.5/sqr(x+1)
         end;}
{----------------------------------------------------------------------------}
{3}{Function F1(x:real):real;
         begin
         f1:=exp(-x)+3
         end;
Function F11(x:real):real;
         begin
         f11:=-exp(-x)
         end;
Function F2(x:real):real;
         begin
         f2:=2*x-2
         end;
Function F21(x:real):real;
         begin
         f21:=2
         end;
Function F3(x:real):real;
         begin
         f3:=1/x
         end;
Function F31(x:real):real;
         begin
         f31:=-1/sqr(x)
         end;}
{----------------------------------------------------------------------------}
{4}{Function F1(x:real):real;
         begin
         f1:=exp(x)+2
         end;
Function F11(x:real):real;
         begin
         f11:=exp(x)
         end;
Function F2(x:real):real;
         begin
         f2:=-1/x
         end;
Function F21(x:real):real;
         begin
         f21:=1/sqr(x)
         end;
Function F3(x:real):real;
         begin
         f3:=-2*(x+1)/3
         end;
Function F31(x:real):real;
         begin
         f31:=-2/3
         end;}
{----------------------------------------------------------------------------}
{5}{Function F1(x:real):real;
         begin
         f1:=0.35*sqr(x)-0.95*x+2.7
         end;
Function F11(x:real):real;
         begin
         f11:=0.7*x-0.95
         end;
Function F2(x:real):real;
         begin
         f2:=exp(ln(3)*x)+1
         end;
Function F21(x:real):real;
         begin
         f21:=exp(ln(3)*x)*ln(3)
         end;
Function F3(x:real):real;
         begin
         f3:=1/(x+2)
         end;
Function F31(x:real):real;
         begin
         f31:=-1/sqr(x+2)
         end;}
{----------------------------------------------------------------------------}
{6}{Function F1(x:real):real;
         begin
         f1:=0.6*x+3
         end;
Function F11(x:real):real;
         begin
         f11:=0.6
         end;
Function F2(x:real):real;
         begin
         f2:=(x-2)*sqr(x-2)-1
         end;
Function F21(x:real):real;
         begin
         f21:=3*sqr(x-2)
         end;
Function F3(x:real):real;
         begin
         f3:=3/x
         end;
Function F31(x:real):real;
         begin
         f31:=-3/sqr(x)
         end;}
{----------------------------------------------------------------------------}
{7}{Function F1(x:real):real;
         begin
         f1:=1/(2-x)+6
         end;
Function F11(x:real):real;
         begin
         f11:=1/sqr(2-x)
         end;
Function F2(x:real):real;
         begin
         f2:=-2*x+14
         end;
Function F21(x:real):real;
         begin
         f21:=-2
         end;
Function F3(x:real):real;
         begin
         f3:=ln(x)
         end;
Function F31(x:real):real;
         begin
         f31:=1/x
         end;}
{----------------------------------------------------------------------------}
{8}{Function F1(x:real):real;
         begin
         f1:=exp(x)+2
         end;
Function F11(x:real):real;
         begin
         f11:=exp(x)
         end;
Function F2(x:real):real;
         begin
         f2:=-2*x+8
         end;
Function F21(x:real):real;
         begin
         f21:=-2
         end;
Function F3(x:real):real;
         begin
         f3:=-5/x
         end;
Function F31(x:real):real;
         begin
         f31:=5/sqr(x)
         end;}
{----------------------------------------------------------------------------}
{9}Function F1(x:real):real;
         begin
         f1:=3/((x-1)*(x-1)+1)
         end;
Function F11(x:real):real;
         begin
         f11:=-6*(x-1)/sqr((x-1)*(x-1)+1)
         end;
Function F2(x:real):real;
         begin
         f2:=sqrt(x+0.5)
         end;
Function F21(x:real):real;
         begin
         f21:=0.5/sqrt(x+0.5)
         end;
Function F3(x:real):real;
         begin
         f3:=exp(-x)
         end;
Function F31(x:real):real;
         begin
         f31:=-exp(-x)
         end;
{----------------------------------------------------------------------------}
{10}{Function F1(x:real):real;
         begin
         f1:=1+4/(sqr(x)+1)
         end;
Function F11(x:real):real;
         begin
         f11:=-8*x/sqr(1+sqr(x))
         end;
Function F2(x:real):real;
         begin
         f2:=sqr(x)*x
         end;
Function F21(x:real):real;
         begin
         f21:=3*sqr(x)
         end;
Function F3(x:real):real;
         begin
         f3:=exp(ln(2)*(-x))
         end;
Function F31(x:real):real;
         begin
         f31:=-exp(ln(3)*x)*ln(3)
         end;}
{----------------------------------------------------------------------------}
procedure root(f,f1,g,g1:Tf; a,b,eps1:real; var x:real);
var x11,x12,e1,e,l,d:real;
    begin
    repeat
    l:=(f1(a)-g1(a))*((f((A+b)/2)-g((a+b)/2)-(f(b)-g(b)-F(a)+G(b))/2));
    if l<0 then begin d:=b; e:=a end else begin D:=a; e:=b end;
    x11:=d-(f(d)-g(d))/(f1(d)-g1(d));
    x12:=e-(d-e)*(f(E)-g(e))/(f(d)-g(d)-f(E)+g(e));
    e1:=(x11+x12)/2;
    if l<0
       then begin a:=x12;b:=x11 end
       else begin a:=x11;b:=x12 end;
    until abs(e1-x11)<eps1;
    x:=e1
    end;
{----------------------------------------------------------------------------}
Function ft(n:longint; f,g:TF; a,b:real):real;
var x,IntN,h:real;
         begin
         x:=a;
         IntN:=(f(a)-g(a)+f(b)+g(b))/2;
         h:=(b-a)/n;
         while x<b-h/2 do
               begin
               x:=x+h;
               IntN:=IntN+f(x)-g(x)
               end;
         ft:=IntN*h
         end;
{----------------------------------------------------------------------------}
function integral(a,b,eps:real; f,g:Tf; n0:LONGint):real;
    var IntN,Int2N:real;
        o:longint;
    begin
    o:=0;
    Int2N:=ft(n0, f, g, a, b);
    repeat
          intN:=Int2N;
          n0:=2*n0;
          Int2N:=ft(n0, f, g, a, b);
          o:=O+1
    until abs(IntN-Int2N)<(3*eps);
    if m then writeln('   with the number of iteration o=',o,' pogreshnost not larger, than ',eps:1:k);
    integral:=IntN
    end;
{----------------------------------------------------------------------------}
begin clrscr;
repeat
       writeln ('Program has been made in order to find points of intersection of functions:');
       writeln ('        F1=3/((x-1)^2+1),  F2=sqrt(x+0.5),  F3=e^(-x)     ');
       writeln ('and to count the area of the figure limited with these three functions');
      readln;
      eps:=0.001;
      m:=false;
{----------------------------------------------------------------------------}
       writeln('The counting of points of intersection of functions f1 and f3...');

      {1}{k1:=-2.65;
      k2:=-2.35;}

      {2}{k1:=1.25;
      k2:=1.45;}

      {3}{k1:=0.25;
      k2:=0.28;}

      {4}{k1:=-4.1;
      k2:=-4;}

      {5}{k1:=-1.85;
      k2:=-1.75;}

      {6}{k1:=0.8;
      k2:=0.9;}

      {7}{k1:=2.15;
      k2:=2.25;}

      {8}{k1:=-2.45;
      k2:=-2.35;}

      {9}k1:=-0.35;
      k2:=-0.15;

      {10}{k1:=-1.35;
      k2:=-1.25;}

      root(f1, f11, f3, f31, k1, k2, eps, x1);
       Writeln('        x1=',x1:5:3,' - point of intersection of f1 i f3, counted with eps=',eps:5:3);
       writeln('The counting is finished!');
      writeln;
{----------------------------------------------------------------------------}
       writeln('The counting of points of intersection of functions f2 and f3...');

      {1}{k1:=0.55;
      k2:=0.75;}

      {2}{k1:=4.15;
      k2:=4.35;}

      {3}{k1:=1.3;
      k2:=1.4;}

      {4}{k1:=-1.9;
      k2:=-1.8;}

      {5}{k1:=-1.3;
      k2:=-1.2;}

      {6}{k1:=3.2;
      k2:=3.3;}

      {7}{k1:=4.15;
      k2:=4.25;}

      {8}{k1:=-0.6;
      k2:=-0.5};

      {9}k1:=0.15;
      k2:=0.35;

      {10}{k1:=0.75;
      k2:=0.85;}

      root(f2, f21, f3, f31, k1, k2, eps, x2);
       Writeln('        x2= ',x2:5:3,' - point of intersection of f2 i f3, counted with eps=',eps:5:3);
       writeln('The counting is finished!');
      writeln;
{----------------------------------------------------------------------------}
       writeln('The counting of points of intersection of functions f1 and f2...');

      {1}{k1:=1.25;
      k2:=1.35;}

      {2}{k1:=5.05;
      k2:=5.15;}

      {3}{k1:=2.5;
      k2:=2.6;}

      {4}{k1:=-0.45;
      k2:=-0.35;}

      {5}{k1:=0.25;
      k2:=0.35;}

      {6}{k1:=3.75;
      k2:=3.85;}

      {7}{k1:=6.05;
      k2:=6.15;}

      {8}{k1:=1.2;
      k2:=1.3;}

      {9}k1:=1.85;
      k2:=2.25;

      {10}{k1:=1.3;
      k2:=1.4;}

      root(f1, f11, f2, f21, k1, k2, eps, x3);
       Writeln('        x3= ',x3:5:3,' - point of intersection of f2 i f1, counted with eps=',eps:5:3);
       writeln('The counting is finished!');
      readln;
{----------------------------------------------------------------------------}
       writeln('The counting of eps1...');
       {write ('Input the first number of segnementation n0:= ');
      readln (n0);}
      n0:=1;
      k:=3;
      I11:=abs(integral(x1+0.001, x2+0.001, eps, f1, f3, n0));
      I21:=abs(integral(x2+0.001, x3+0.001, eps, f1, f2, n0));
      I1:=I11+I21;
      I12:=abs(integral(x1-0.001, x2-0.001, eps, f1, f3, n0));
      I22:=abs(integral(x2-0.001, x3-0.001, eps, f1, f2, n0));
      I2:=I12+I22;
      eps1:=abs((i2-i1)/2);
      Writeln('        Eps1:=',eps1);
      k:=0;
      while eps1<1 do
            begin
            k:=k+1;
            eps1:=eps1*10
            end;
      eps1:=round(eps1);
      for
      l:=1 to k do eps1:=eps1/10;
       Writeln('        round of Eps1 in larger side:=',eps1:1:k);
       writeln('The counting is finished!');
      writeln;
{----------------------------------------------------------------------------}
      m:=true;
       writeln('The counting of I1...');
      I1:=abs(integral(x1, x2, eps1, f1, f3, n0));
       writeln('        I1= ',I1:1:k);
       writeln('The counting is finished!');
      writeln;
{----------------------------------------------------------------------------}
       writeln('The counting of I2...');
      I2:=abs(integral(x2, x3, eps1, f1, f2, n0));
       writeln('        I2= ',I2:1:k);
       writeln('The counting is finished!');
      writeln;
{----------------------------------------------------------------------------}
      I:=I1+I2;
       Writeln('The area of figure S=I1+I2=',I:1:k,' limited of f1,f2,f3,');
       Writeln('counted with eps=',eps1:1:k);
      readln;
{----------------------------------------------------------------------------}
       writeln('Do you want to continue computings???');
       writeln('even number and 0 to quit, not even - to continue');
      readln(n0)
until not odd(n0) or (n0=0)
end.