Advertisement
Guest User

Untitled

a guest
Feb 19th, 2019
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.09 KB | None | 0 0
  1. #include "functioncalculater.h"
  2. #include <stdlib.h>
  3.  
  4.  
  5. FunctionCalculater::FunctionCalculater()
  6. {
  7. }
  8.  
  9. //method  Monte-Carlo
  10. double FunctionCalculater::integrate(double (*calculate)(double), double from, double to)
  11. {
  12.     double resultSum = 0;
  13.  
  14.     for(double tmp = from; tmp<to; tmp+=gap)
  15.     {
  16.         double base = ( tmp+gap<=to)?(gap):(to-tmp);
  17.  
  18.         resultSum += base * calculate(tmp);
  19.     }
  20.  
  21.     return resultSum;
  22. }
  23.  
  24.  
  25. double *FunctionCalculater::calculateInInterval(double (*calculate)(double), double from, double to)
  26. {
  27.     int count = (int) (( to-from)/gap);
  28.     double *result = new double[ (int) (( to-from)/gap) ];
  29.  
  30.     return result;
  31. }
  32.  
  33. comp FunctionCalculater::cintegrate(comp (*calculate)(comp), const comp& from , const comp& to)
  34.     {
  35.         comp resultSum;
  36.  
  37.         for(comp tmp = from; std::abs(tmp) < std::abs(to); tmp+=gap)
  38.         {
  39.             comp base = ( std::abs(tmp+gap)<=std::abs(to))?(gap):(to-tmp);
  40.  
  41.             resultSum += base * ( calculate(tmp) );
  42.             cout << resultSum << endl;
  43.         }
  44.  
  45.         return resultSum;
  46.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement