function TES=ThreeEighthSimp(t,y)

% t is a row vector of domain values and y a vector of dependent values
% t and y must have the same length

if length(t)~=length(y)
disp('the two data vectors must have equal length') 

elseif (  ceil(length(t)/3)==length(t)/3  ) || (  ceil((length(t)+1)/3)==(length(t)+1)/3 )
disp('the number of data intervals must be divisible by three (so the number of data points must be of the form 3*k+1)') 

elseif diff(t)-t(2)+t(1)~=zeros(1,length(t)-1)
disp('data vectors must be rows and each data interval must be the same length') 

elseif length(t)==4

TES=3*(t(2)-t(1))/8*(  y(1)+3*y(2)+3*y(3)+y(4) );

else
h=t(2)-t(1);
L2=[2:3:(length(t)-2)];
L3=[3:3:(length(t)-1)];
L4=[4:3:(length(t)-3)];


A=y(L2);
B=y(L3);
C=y(L4);

TES=3*h/8*(y(1)+y(length(y))+3*sum(A)+3*sum(B)+2*sum(C));






end


