sum = 0;%the sumn n = 44;%the number of intervals pi = 3.141592654; a = 1;%lower limit b = 3;%upper limit I = 1.295836866;%the real integral i=0; for x = a:(b-a)./n:b f = log(x);%the function if x == a sum = sum + f; end if x == b sum = sum + f; end if x > a && x < b if (rem(i,2)==0) sum = sum + 2*f; else sum = sum + 4*f; end end i=i+1; end S = (sum.*(b-a))./(3*n) E = I - S %I - S