% Computes the integral of arctan(x) from 0 to 1 which % equals pi/4-1/2*ln(2) clc format compact format long a=0, b=1, n1=10 dx1=(b-a)/n1 x1=[a+dx1:dx1:b] % Break up the interval into 10 parts y1=atan(x1) % 10 rectangles based upon height of right endpoint ymid1=atan(x1-dx1/2) % 10 rectangles using the midpoint as your height sum(y1)*dx1 % sum of right rectangles sum(ymid1)*dx1 % sum of midpoint rectangles % Repeat with 1000 rectangles n2=1000 dx2=(b-a)/n2 x2=[a+dx2:dx2:b]; % Note the semicolon y2=atan(x2); % Another semicolon ymid2=atan(x2-dx2/2); sum(y2)*dx2 sum(ymid2)*dx2 exact=pi/4-1/2*log(2) % How do these values compare with the exact value?