MAT2630 Numerical Methods, FA2015

%prob 5.1.1
df=inline(‘log(1+h)/h’)
out=[];
for i=1:16
out=[out;i 10^-i df(10^-i) df(10^-i)-1];
end
format long
disp(‘ i h=10^-i df(h) error’)
disp(out)

%prob 5.1.2
df=inline(‘(exp(h)-exp(-h))/(2*h)’)
out=[];
for i=1:12
out=[out;i 10^-i df(10^-i) df(10^-i)-1];
end
format long
disp(‘ i h=10^-i df(h) error’)
disp(out)

%prob 5.1.3
df=inline(‘(sin(pi()/3+h)-sqrt(3)/2)/h’)
out=[];
for i=1:16
h=10^-i;
out=[out;h df(h) -h*sqrt(3)/4 df(h)-1/2 -h*sin(pi()/3+h)/2];
end
format long
disp(‘ h=10^-i df(h) -h*sqrt(3)/4 error -h*sin(pi()/3+h)/2’)
disp(out)

Tags:

Comment display has been disabled on this doc.

Comment posting has been disabled on this doc.