Repeat the procedure with increased number of sample points.
Solution:
function week9lsg(fs,a,b,vec)
% input fs as string
f=inline(fs); % inline
format short;
N=length(vec);
disp('Exact Approximated Approximated-Exact Maxerror Minerr');
for i=1:N
approximated=num2str(traprl(f,a,b,vec(i)));
fx2 = diff(fs,2);
h=(b-a)/vec(i);
fs = '2 + sin (2*(x^.5))';
errmax=num2str(((b-a)/12)*h^2*fx2(a));
errmin=num2str(((b-a)/12)*h^2*fx2(b));
exact=int(fs,a,b);
D=[exact,approximated,approximated-exact,errmax,errmin];
disp(D);
end
save with the name week10lsg.m. Then;
>> vec=[10 20 40 50 100 500 1000]';
>> week10lsg('2 + sin (2*(x^.5))',1,6,vec);
Exact Approximated Approximated-Exact Maxerror Minerr
8.1835, 8.1939, .10421e-1, 1.87500, 1.5625
8.1835, 8.1860, .25208e-2, 0.46875, 0.39062
8.1835, 8.1841, .62079e-3, 0.11719, 0.097656
8.1835, 8.1839, .42079e-3, 0.07500, 0.0625
8.1835, 8.1836, .12079e-3, 0.01875, 0.015625
8.1835, 8.1835, .20792e-4, 0.00075, 0.000625
8.1835, 8.1835, .20792e-4, 0.0001875, 0.00015625