You are on page 1of 2

6.

clear all
clc

fprintf(1,'Richardson Extrapolation.\n\n');
fprintf(1,'Input function in term of x\n');
s=input(' ','s');
f=inline(s,'x');

fprintf(1,'Input x\n');
a=input(' ');

ok=0;
while ok == 0
fprintf(1,'Input number of iteration - no decimal point.\n');
n=input(' ');
if n>0
ok=1;
else
fprintf(1,'Number must be a positive integer\n');
end
end

if ok==1
fprintf(1,'Input h\n');
h=input(' ');
fprintf(1,'Initial data:\n');
fprintf(1,'X = (%12.8f)\n',a);
fprintf(1,'Number of iteration = %3d\n',n);
fprintf(1,'\nRichardson Extrapolation Table:\n');
h(1)=h;
for j=2:n
h(j)=h(j-1)/2;
end
D=zeros(n,n+1);
D(:,1)=h;
for j=1:n
D(j,2)=f(a+h(j))/(2*h(j))-f(a-h(j))/(2*h(j));
end
for i=3:n+1
for j=i-1:n
D(j,i)=(2^(2*(i-2))*D(j,i-1)-D(j-1,i-1))/(2^(2*(i-2))-1);
end
end
end
D

You might also like