0% found this document useful (0 votes)
52 views3 pages

Fa20-Bme-030 (Week1 Matlab)

The document describes the Newton forward and backward difference interpolation methods. It provides sample code to calculate interpolation polynomials up to degree 8 for given x and y data sets. The code calculates successive differences of the y data (delta, square delta, etc.) to build the interpolation polynomials. It then uses these polynomials to calculate the interpolated y value for given x values, such as 56 for the forward method and 101 for the backward method.

Uploaded by

Ahsan Farooq
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
52 views3 pages

Fa20-Bme-030 (Week1 Matlab)

The document describes the Newton forward and backward difference interpolation methods. It provides sample code to calculate interpolation polynomials up to degree 8 for given x and y data sets. The code calculates successive differences of the y data (delta, square delta, etc.) to build the interpolation polynomials. It then uses these polynomials to calculate the interpolated y value for given x values, such as 56 for the forward method and 101 for the backward method.

Uploaded by

Ahsan Farooq
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Newton Forward Difference Interpolation Method:

x=[31:31:279];
y=[34 78 99 145 289 456 560 789 1079];
a=length(x);
b=length(y);
fprintf(' x y dell squaredell cubedell fourdell fivedell sixdell sevendell
eightdell\n')
for n=1:8
del(1,n)=y(n+1)-y(n);
end
dell=[ del';0];
for m=1:7
squaredel(1,m)=del(m+1)-del(m);
end
squaredell=[squaredel';0;0];
for t=1:6
cubedel(1,t)=squaredel(t+1)-squaredel(t);
end
cubedell=[cubedel';0;0;0];
for u=1:5
fourdel(1,u)=cubedel(u+1)-cubedel(u);
end
fourdell=[fourdel';0;0;0;0];
for v=1:4
fivedel(1,v)=fourdel(v+1)-fourdel(v);
end
fivedell=[fivedel';0;0;0;0;0];
for w=1:3
sixdel(1,w)=fivedel(w+1)-fivedel(w);
end
sixdell=[sixdel';0;0;0;0;0;0];
for i=1:2
sevendel(1,i)=sixdel(i+1)-sixdel(i);
end
sevendell=[sevendel';0;0;0;0;0;0;0];
for j=1:1
eightdel(1,j)=sevendel(j+1)-sevendel(j);
end
eightdell=[eightdel';0;0;0;0;0;0;0;0];
xj=56;
h=x(1,2)-x(1,1);
xo=x(1,1);
p=(xj-xo)/h;
a=(p*dell(1,1));
b=(p*(p-1)*squaredell(1,1))/factorial(2);
c=(p*(p-1)*(p-2)*cubedell(1,1))/factorial(3);
d=(p*(p-1)*(p-2)*(p-3)*fourdell(1,1))/factorial(4);
e=(p*(p-1)*(p-2)*(p-3)*(p-4)*fivedell(1,1))/factorial(5);
f=(p*(p-1)*(p-2)*(p-3)*(p-4)*(p-5)*sixdell(1,1))/factorial(6);
g=(p*(p-1)*(p-2)*(p-3)*(p-4)*(p-5)*(p-6)*sevendell(1,1))/factorial(7);
l=(p*(p-1)*(p-2)*(p-3)*(p-4)*(p-5)*(p-6)*(p-7)*eightdell(1,1))/factorial(8);
yj=y(1,1)+a+b+c+d+e+f+g+l;
fprintf('%f\t %f\t %f\t %f\t %f\t %f\t %f\t %f\t %f\t %f\n',[x',y',dell,squaredell,cubedell,fourdell,fivedel
l,sixdell,sevendell,eightdell]')
h;
xo;
p;
xj;
fprintf('the required value of the function is %f\n',yj)

Newton Backward Difference Interpolation Method:


x=[12:12:108];
y=[78 88 109 245 675 876 944 1090 1456];
a=length(x);
b=length(y);
fprintf(' x y dell squaredell cubedell fourdell fivedell sixdell sevendell
eightdell\n')
for n=1:8
del(1,n)=y(1+n)-y(n);
end
dell=[0;del'];
for m=1:7
squaredel(1,m)=del(1+m)-del(m);
end
squaredell=[0;0;squaredel'];
for o=1:6
cubedel(1,o)=squaredel(1+o)-squaredel(o);
end
cubedell=[0;0;0;cubedel'];
for p=1:5
fourdel(1,p)=cubedel(1+p)-cubedel(p);
end
fourdell=[0;0;0;0;fourdel'];
for q=1:4
fivedel(1,q)=fourdel(1+q)-fourdel(q);
end
fivedell=[0;0;0;0;0;fivedel'];
for r=1:3
sixdel(1,r)=fivedel(1+r)-fivedel(r);
end
sixdell=[0;0;0;0;0;0;sixdel'];
for s=1:2
sevendel(1,s)=sixdel(1+s)-sixdel(s);
end
sevendell=[0;0;0;0;0;0;0;sevendel'];
for t=1:1
eightdel(1,t)=sevendel(1+t)-sevendel(t);
end
eightdell=[0;0;0;0;0;0;0;0;eightdel'];
xj=101;
h=x(1,2)-x(1,1);
xn=x(1,9);
p=(xj-xn)/h;
a=(p*dell(9,1));
b=(p*(p+1)*squaredell(9,1))/factorial(2);
c=(p*(p+1)*(p+2)*cubedell(9,1))/factorial(3);
d=(p*(p+1)*(p+2)*(p+3)*fourdell(9,1))/factorial(4);
e=(p*(p+1)*(p+2)*(p+3)*(p+4)*fivedell(9,1))/factorial(5);
f=(p*(p+1)*(p+2)*(p+3)*(p+4)*(p+5)*sixdell(9,1))/factorial(6);
g=(p*(p+1)*(p+2)*(p+3)*(p+4)*(p+5)*(p+6)*sevendell(9,1))/factorial(7);
l=(p*(p+1)*(p+2)*(p+3)*(p+4)*(p+5)*(p+6)*(p+7)*eightdell(9,1))/factorial(8);
yj=y(1,9)+a+b+c+d+e+f+g+l;
fprintf('%f\t %f\t %f\t %f\t %f\t %f\t %f\t %f\t %f\t %f\n',[x',y',dell,squaredell,cubedell,fourdell,fivedel
l,sixdell,sevendell,eightdell]')
h;
xn;
p;
xj;
fprintf('the required value of the function is %f\n',yj)

You might also like