title: Boole's rule for N intervals (C)
body: <p>I am attempting to implement Boole's rule over n intervals using this formula <img src="https://upload.wikimedia.org/math/0/c/5/0c536bbbe48862a3cca221e089bc0d46.png" alt="boole&#39;s rule">
  <img src="https://upload.wikimedia.org/math/8/4/3/8439a2de9d4263495323aa9cee5ff5c6.png" alt="x="></p>
  
  <p>So far I have developed this code: </p>
  
  <pre><code>//f = function on the range [a,b] n = number of intervals
  long double booles(long double (*f) (long double), 
                  double a, double b, int n) 
  {
    long double sum=7*f(a); //because the starting value is not doubled 
    long double h = (b - a)/(n-1); //width of each interval
    int mod;
    int i =1;
    while (i&lt;n-1)
      {
        mod = i%4;
        if (mod==0)
          sum+=14*f(a+i*h);
        else if (mod==1)
          sum+=32*f(a+i*h);
        else if (mod==2)
          sum+=12*f(a+i*h);
        else
          sum+=32*f(a+i*h);
        ++i;
      }
    return 2* h/45 * sum;
  }
  </code></pre>
  
  <p>This will run and give a decent answer but it not within the rules for Bool's error which states that the error is <img src="https://upload.wikimedia.org/math/a/2/2/a22758d87e7cf7ba2dc7dc35653a986d.png" alt="error">.
  I fixed the problem with doubling the first term but I am not sure how to fix the possible doubling near the end of the loop. Also, the error is relatively large enough that I don't think that my only problem is the last four terms. </p>