Hi,
I am working on some simple numerical quadrature methods, and I am trying to get the Simpson's 3/8 method to work using the following code:
function I = SimpThreeEight(f, a, b, n)h = (b-a)/n;S =feval(f,a);for i = 1 : 3: n-1x(i) = a + h*i;S = S + 3*feval(f, x(i));endfor i = 2 : 3: n-2x(i) = a + h*i;S = S + 3*feval(f, x(i));endfor i = 3 : 3: n-3x(i) = a + h*i;S = S + 2*feval(f, x(i));endS = S + feval(f, b);I = 3*h*S/8;
However, using test data with know values my approximations are all off. Can someone identify why?
Thanks!
Best Answer