%MATLAB version of the script for example 7.4 on page 323 of conte/deboor
% example 7.4  Trapezoid Rule
% MATLAB computes in double precision. To get results in single precision,
% enter at least one input as a single precision number. Then all calculations
% ultimately involving that number are done in single precision.
%
%  Reference:
%
%    Samuel Conte, Carl de Boor,
%    Elementary Numerical Analysis,
%    Third Edition,
%    SIAM, 2017,
%    ISBN: 978-1-611975-19-2.
%
F = @(x) exp(-x.*x);
disp('Example 7.4: Trapezoidal Rule')
disp('   N    I(SP)           I(DP)            ERROR(SP)    ERROR(DP)')

for N=50*2.^[0:4]
   value = TRAP(F,single(0),1,N); error =  0.746824132812427  - value;
   valued = TRAP(F,0,1,N); errord =  0.746824132812427 - valued;
   fprintf('  %3d  %14.7e  %14.7e   %10.3e   %10.3e\n', ...
             [N,    value,  valued,  error,   errord])
end
