Numerical Analysis Week 1 (Ter)

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 2

NUMERICAL ANALYSIS

(MATLAB)

NAME: AHSAN FAROOQ


ROLL NO:FA20-BME-005
SECTION:A
Newton Forward Difference Interpolation Method:
x=[100:50:400];
y=[11.63 13.03 15.04 17.81 19.42 20.9 22.27]
a=length(x);
b=length(y);
for n=1:6
del(1,n)=y(n+1)-y(n);
end
dell=[ del';0]
for m=1:5
squaredel(1,m)=del(m+1)-del(m);
end
squaredell=[squaredel';0;0];
for t=1:4
cubedel(1,t)=squaredel(t+1)-squaredel(t);
end
cubedell=[cubedel';0;0;0];
for u=1:3
fourdel(1,u)=cubedel(u+1)-cubedel(u);
end
fourdell=[fourdel';0;0;0;0]
for v=1:2
fivedel(1,v)=fourdel(v+1)-fourdel(v);
end
fivedell=[fivedel';0;0;0;0;0]
for w=1:1
sixdel(1,w)=fivedel(w+1)-fivedel(w);
end
sixdell=[sixdel';0;0;0;0;0;0]

dt=[x' y' dell squaredell cubedell fourdell fivedell sixdell];


xj=218;
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);
yj=y(1,1)+a+b+c+d+e+f;
disp('the difference table is as under')
dt
h
xo
p
xj
fprintf('the required value of the function is %f\n',yj)

You might also like