%FIG11_02 Figure 11.2, The derivation of Simpson's rule.
% If you want to run other graphs after having used this
% file, you may have to enter the command CLF.
x = 0: pi/90: pi/2; % abscissa of integrand
y = 1+ sin(x); % integrand
xs = 0: pi/20: pi/2; % abscissa of substitute integrand
A = [ 1 0 0
1 pi/4 (pi/4)^2
1 pi/2 (pi/2)^2 ];
B = [ 1 ; (1 + sin(pi/4)) ; (1 + sin(pi/2)) ];
a = A\B; % coefficients of substitute parabola
for i = 1: 1: length(xs);
ys(i) = a(1) + (a(2) + a(3)*xs(i))*xs(i);
end
x0 = [ 0 0 ]; y0 = [ 0 1 ];
a = [ 0 1.6 ]; b = [ 0 0 ];
x3 = [ 0 pi/2 ]; % chord extremities
y3 = [ 1 (1 + sin(pi/2)) ]; % chord values
x4 = [ pi/4 pi/4 ];
y4 = [ 0 (1 + sin(pi/4)) ];
d = sin(pi/4) - sin(pi/2)/2;
y5 = [ (1 + d) (1 + sin(pi/2) + d) ];
x6 = [ pi/2 pi/2 ];
y6 = [ 0 y5(2) ];
hold on
plot(x,y,'-', xs, ys,'--', x3,y3,':g', x4,y4,':g', x3,y5,':g', x6, y6,':g')
axis('off')
plot(x0, y0, ':g', a, b, '-')
xlabel('x')
text(0.01, 0.07, 'A')
text(0.01, 0.9, 'B')
text((pi/4+0.01), (1.07 + sin(pi/4)), 'C')
text((pi/2+0.008), (1 + sin(pi/2)), 'D')
text((pi/2+0.008), 0.07, 'E')
text((pi/4+0.01), 0.07, 'F')
text((pi/4+0.01), (0.9 + sin(pi/2)/2), 'G')
text(3.08*pi/8, (1.016+ sin(3*pi/8)), 'f(x)')
text(0.01, y5(1)+0.07, 'H')
text((pi/2+0.008), y5(2)+0.07, 'I')
text(0.2, 0.4, 'The continous line represents f(x)')
text(0.2, 0.2, 'The dotted line represents substitution by parabola')
hold off