home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / autopsp.zip / REGRESS / CSIMP.H < prev    next >
C/C++ Source or Header  |  1994-01-23  |  2KB  |  49 lines

  1. // CSimpson
  2. //   Numerical integration by the Simpsons method.
  3. //   This is a parent class.  The function to be integrated
  4. //   Must be derived from this class and have the funciton
  5. //   to be integrated in the over-ridden mehtod IntMe();
  6.  
  7. #include "stdio.h"
  8. #include "stdlib.h"
  9. #include "math.h"
  10. #include "values.h"
  11.  
  12. #ifndef CSIMPSON
  13. #define CSIMPSON
  14.  
  15. #define INFINITY MAXDOUBLE        // Allows us to hold the value of
  16.                                   //  infinity in a finit floating point
  17.                                   //  variable.
  18.  
  19.  
  20. class CSimpson
  21. {
  22.   public:
  23.   CSimpson(void);
  24.  
  25.   double         Gamma(double x); // Gamma is used by multiple functions
  26.                                   //  so it is here for convenience.
  27.   virtual double IntMe(double x); // Overridable function to hold the
  28.                                   //  function to integrate.
  29.                                   // Sets the private member tolerance.
  30.   void           SetTolerance(double Tol);
  31.                                   // Integrates the desired funcition by
  32.                                   //  taking into account for infinity and
  33.                                   //  calling the CalcSimpsons funtion.
  34.   double         Integrate(double low, double high, double total);
  35.  
  36.   private:                        // Calculates simpsons summation using
  37.                                   //  the info generated in Integrate.
  38.   void           CalcSimpsons(double low, double high);
  39.  
  40.   int            n;               // Number of blocks in use.
  41.   double         cur_result;      // current simpsons result.
  42.   double         old_result;      // previous simpsons result.
  43.   double         result;          // actual found result.
  44.   double         width;           // width of each block.
  45.   double         tolerance;       // error tolerance
  46. };
  47.  
  48.  
  49. #endif