home *** CD-ROM | disk | FTP | other *** search
/ Power Programming / powerprogramming1994.iso / progtool / borland / jnfb88.arc / SKYDIV.ARC / BISECT2.PAS < prev    next >
Pascal/Delphi Source File  |  1987-07-17  |  2KB  |  65 lines

  1. PROGRAM Bisect2;
  2.  
  3. {------------------------------------------------------------------}
  4. {-                                                                -}
  5. {- Purpose: This program demonstrates the bisection routine with  -}
  6. {-          a bare minimum of calling code.                       -}
  7. {-          No I/O options or error checking code.                -}
  8. {-                                                                -}
  9. {-                                                                -}
  10. {- Include files:   BISECT.INC     procedure Bisect               -}
  11. {-                                                                -}
  12. {-    Version July 1987                                           -}
  13. {------------------------------------------------------------------}
  14.  
  15.  
  16. VAR
  17.   LeftEndpoint, RightEndpoint : Real; { Endpoints of the region }
  18.   Answer, yAnswer : Real;             { Root of F(X) }
  19.   Tol : Real;                         { Tolerance }
  20.   Iter, MaxIter : Integer;            { Number of iterations }
  21.   Error : Byte;                       { Flags something wrong}
  22.  
  23.  
  24.  
  25.   {----- HERE IS THE FUNCTION TO FIND A ROOT OF ------}
  26.  
  27.   FUNCTION TNTargetF(X : Real) : Real;
  28.   BEGIN
  29.     TNTargetF := -40.0+X*(1.0-Exp(-98.1/X))/(1.0+Exp(-98.1/X));
  30.   END; { function TNTargetF }
  31.  
  32.   {---------------------------------------------------}
  33.  
  34.  
  35.   {$I BISECT.INC}  { Load procedure Bisect }
  36.  
  37.  
  38. BEGIN
  39.   { Get necessary input. }
  40.   Error := 0;
  41.   WriteLn('Enter LeftEndpoint RightEndpoint seperated by a space.');
  42.   ReadLn(LeftEndpoint, RightEndpoint);
  43.   WriteLn;
  44.   Write('Enter the tolerance (1E-8 suggested): ');
  45.   ReadLn(Tol);
  46.   Write('Enter maximum number of interations (100 suggested): ');
  47.   ReadLn(MaxIter);
  48.  
  49.   Bisect(LeftEndpoint, RightEndpoint, Tol, MaxIter,
  50.          Answer, yAnswer, Iter, Error);
  51.  
  52.   { Give resulting output. }
  53.   WriteLn;
  54.   WriteLn('Error = ', Error);
  55.   WriteLn('left endpoint: ':30, LeftEndpoint);
  56.   WriteLn('right endpoint: ':30, RightEndpoint);
  57.   WriteLn('Tolerance: ':30, Tol);
  58.   WriteLn('Maximum number of iterations: ':30, MaxIter);
  59.   WriteLn;
  60.   WriteLn('Number of iterations: ':26, Iter:3);
  61.   WriteLn('Calculated root: ':26, Answer);
  62.   WriteLn('Value of the function  ':26);
  63.   WriteLn('at the calculated root: ':26, yAnswer);
  64. END.
  65.