function [ I ] = TrapIteration( f, a, b, n ) % Simspon formula evaluated % n number of divisions of intervals in two parts if a > b temp = a; a = b; b = temp; disp('a and b interchanged') end % Case ip = 0 (only one interval) i = 0; h0 = (b-a); I = h0 * 1/2 * (f(a) + f(b)); fprintf('Iteration n= %d with I = %f \n', i, I); for i = 1: n ip = 2.^(i-1); % number of inner points h = (b-a)/(2*ip); x0 = a + h; sum = 0; for j = 1:ip sum = sum + f(x0 + j * 2*h); end I = 0.5 * I + h * sum; format long fprintf('Iteration n= %d with I = %f \n', i, I); end end