SHARE
TWEET

Untitled

a guest Apr 24th, 2019 66 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. double simpsonIntegral(double a, double b, int n, const std::function<double (double)> &f) {
  2.     const double width = (b-a)/n;
  3.  
  4.     double simpson_integral = 0;
  5.     for(int step = 0; step < n; step++) {
  6.         const double x1 = a + step*width;
  7.         const double x2 = a + (step+1)*width;
  8.  
  9.         simpson_integral += (x2-x1)/6.0*(f(x1) + 4.0*f(0.5*(x1+x2)) + f(x2));
  10.     }
  11.  
  12.     return simpson_integral;
  13. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top