home *** CD-ROM | disk | FTP | other *** search
/ Simtel MSDOS 1992 September / Simtel20_Sept92.cdr / msdos / turbopas / pas_sci.arc / SIMP2.PAS < prev    next >
Pascal/Delphi Source File  |  1985-09-06  |  541b  |  32 lines

  1. program simp2;        { -> 278 }
  2. { integration by Simpson's method }
  3. { Turbo Pascal cannot pass function names as arguments}
  4.  
  5. const    tol        = 1.0E-6;
  6. var    sum,upper,lower    : real;
  7.  
  8. function fx(x: real): real;
  9. { find f(x)=1/x }
  10. { watch out for x=0 }
  11.  
  12. begin
  13.   fx:=1.0/x
  14. end;    { function fx }
  15.  
  16. function dfx(x:real):real;
  17. begin
  18.   dfx:=-1.0/sqr(x)
  19. end;
  20.  
  21. {$I simps.lib}
  22.  
  23. begin        { main program }
  24.   ClrScr;
  25.   lower:=1.0;
  26.   upper:=9.0;
  27.   writeln;
  28.   simps(lower,upper,tol,sum);
  29.   writeln;
  30.   writeln(chr(7),'area= ',sum)
  31. end.
  32.