title: MATLAB : Simpson's 1/3 Rule
body: <p>I've created a code for the Simpson's rule but I think I got the function wrong. I have no other sources to refer to (or they're too difficult to be understood). Here is my code:</p>
  
  <pre><code>function s = simpson(f_str, a, b, h)
  
  f = inline(f_str);
  
  n = (b-a)/h; 
  
  
  x = a + [1:n-1]*h;
  xi = a + [1:n]*h;
  
  
  s = h/3 * (f(a) + f(b) + 2*sum(f(x)) + 4*sum(f(xi)));
  
  end
  </code></pre>
  
  <p>Can anybody help see where is the wrong part?</p>