function I = sri(x,y)
%Simpsons-Rule Integration
% by Christian Himpe (2012)
% 
% Input:  x - vector of supporting points
%         y - vector of function values at x
% 
% Output: I - approximated integral value

n = numel(x)-1;			%adjusted number of elements

s0 = y(1) + y(n+1);		%boundary cases
s1 = 0;				%initialize even sum
s2 = 0;				%initialize odd sum
K = 2; 				%initialize double step counter
for J=2:(n/2)			%for half the steps
s1 = s1 + y(K);			% sum at even
s2 = s2 + y(K+1);		% sum at odd
K = K+2;			% increase double step counter
end				%*

h = (x(n)-x(1))/n;		%determine h

I = h/3 *(s0+4*s1+2*s2);	%combine as SR instructs
