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

Lab No.5

This numerical analysis lab report describes creating a Newton's forward difference table in MATLAB. The code takes input values for x and f(x) to generate the table with differences. It then uses the table to interpolate the value of an input x-value via Newton's formula. While the code determines the relevant xo and table position correctly, there is an error in applying the interpolation formula that needs to be addressed.

Uploaded by

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

Lab No.5

This numerical analysis lab report describes creating a Newton's forward difference table in MATLAB. The code takes input values for x and f(x) to generate the table with differences. It then uses the table to interpolate the value of an input x-value via Newton's formula. While the code determines the relevant xo and table position correctly, there is an error in applying the interpolation formula that needs to be addressed.

Uploaded by

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

Numerical Analysis Lab

Lab No.5

Submitted By:
Muhammad Hassan (2020-MC-274)
Submitted to:
Dr. Arshi Khalid
--------------------------------------------------------------------------------------------------------
-

Department of Mechatronics & Control Engineering


University of Engineering & Technology Lahore,
Faisalabad Campus.
Lab report By: M.Hassan (2020-MC-274) Submitted To: Dr. Arshi Khalid

Date: 21-10-2022

Newton’s Forward Difference Table:-


Matlab Code:
% Newton's Forward Differnce Table
clearvars;
clc;
close all;
x = input('Enter the values of x: ');
y = input('Enter the values of F: ');
y_len = length(y);
x_len = length(x);
if (x_len~=y_len)
fprintf('Invalid Input')
end
xp = input('Enter the number whose value needs to be interpolate: ');
h = x(2) - x(1)
% for value of p
for a=1:x_len
if xp>x(a)
xo = x(a);
p = (xp - xo)/h;
if p>1 || p<0
xo = x(a+1);
elseif p<=1 || p>=0
continue
end
end
end
xo
% for Finite Difference Table
table=zeros(2*y_len-1,y_len+1);
j=1;
% to create a matrix having 1st column of values of x and 2nd column of f
% and others are zero
for a=1:2:2*y_len-1
table(a,1) = x(j);
table(a,2) = y(j);
j = j+1;
end
% to calculate foraward difference table
for col=3:1:y_len+1
for row=col-2:2:2*y_len-col
table(row+1,col) = table(row+2,col-1) - table(row,col-1);
end
end
fprintf("Finite Difference Table")
table
% to locate the position of fo
for a=1:2:2*y_len-1
if table(a,1) == xo
xo_position = a;
end
end
xo_position = xo_position + 1;
% Formula for Newton's Forward Differnce Table
A=y(1); B=p;
for k=1:y_len-1
A=A+B*table(xo_position+1,k+1);
B=(p-k)/(k+1)*B;
end
fprintf('Value of Y(%f)=%f \n',xp,A)

2
Lab report By: M.Hassan (2020-MC-274) Submitted To: Dr. Arshi Khalid

Output:
If we input
X = [0 0.25 0.5 0.75 1]
Y = [0 0.2763 0.5205 0.7112 0.8427]
Xp = 0.125
Then
Value of Y(0.125000)=0.136144

Drawbacks of above program:


Above program calculates the value of p, determines xo on the basis of p and determines the position of fo.
But there is error while applying the Interpolation formula.

You might also like