function z = gaussian3(f,a,b)
% GAUSSIAN3  Use n=3 Gauss-Legendre rule to approximate integral.  Uses
% x1,x2,x3 and c1,c2,c3 from textbook.
%
% Example:
%   >> gaussian3(@(x) sin(x),0,pi/4)
%   >> exact = 1 - sqrt(2)/2          % = 0.2928932188

sh = @(t) 0.5 * ((b-a) * t + a+b);  % does shift and scale: x = sh(t)

t1 = 0.7745966692;  t2 = 0.0;     t3 = - t1;
c1 = 5/9;           c2 = 8/9;     c3 = 5/9;

z = c1 * feval(f,sh(t1)) + c2 * feval(f,sh(t2)) + c3 * feval(f,sh(t3));
z = 0.5 * (b-a) * z;
