Schema on read is obsolete. Welcome metaprogramming..pdf
Newton Forward Interpolation
1. PRACTICAL
Name- Saloni Singhal
M.Sc. (Statistics) II-Sem.
Roll No: 2046398
Course- MATH-409 L
Numerical Analysis Lab
Submitted To: Dr. S.C. Pandey
2. OBJECTIVE
1. Create an M-file to implement
Newton Gregory Forward Interpolation.
1. Curve Fitting- Least Square nth order
polynomial to data.
3. Theory
Then the process of knowing the value of f(x ) for some unknown
value of x not explicitly given in the interval [a, b] is called
interpolation. The value thus, determined is known as Interpolated
value.
This Newton Gregory Forward Interpolation formula is particularly
useful for interpolating the values of f(x) near the beginning of the
set of values given. h is called the interval of difference and u = (
x – a ) / h, Here a is the first term.
Error term of the formula:
4. Program
clear;
%input number of data points
n= input('enter number of data points=');
%input abscissa and ordinate value
for a=1:n
X(a)= input('enter X'+string(a));
end
for b=1:n
Y(b)= input('enter Y'+string(b));
end %enter the value to be interpolated using
forward interpolation
x=input('enter value of x to be interpolated');
%step size h and d gives the forward difference
table
h=X(2)-X(1);
for i=1:n-1
d(i,1)=Y(i+1)-Y(i);
end
for j=2:n-1
for i=1:n-j
d(i,j)=d(i+1,j-1)-d(i,j-1);
end
end
6. Time Complexity
6
For the given program it is calculated as:
For line 14= 2(n-1) since loop
For line 16= (n-1)+1 since loop from 1:n-1
For line 18= 2(n-1)(n-2) for nested loop
For line 24= 51(6n-3) since linspace generates 51
values(given) and min/max has time complexity n
For line 36= (6n-3) since loop is from i to n-1
on adding the above dominant value is =O(n2)
Big O notation is the most common metric for calculating time complexity. It
describes the execution time of a task in relation to the number of steps
required to complete it.
We calculate the
no of operations in
respective loops
and function.
Big ‘O’ notation
takes its dominant
value
8. Plot of the given data points and interpolated curve
Reference:
— Data Points
plot
—Interpolated
curve
9. Curve Fitting
Syntax:
p = polyfit(x,y,n)
returns the coefficients
for a polynomial p(x) of
degree n that is a best
fit (in a least-squares
sense) for the data in y.
The coefficients in p are
in descending powers,
and the length of p is
n+1
10. Conclusion
• The interpolated value of the point is as shown
in figure.
• Polyfit (order 3) verifies the actual cubic
formula for the given set of data points i.e. y=
x³+2x-3.
11. Caveats
It can be observed that this formula is appropriate when
the value to be interpolated (xs) lie almost in the beginning
of the data table. More explicitly, when xs lies almost in the
end of the data table then only first two or three terms of
(1) can be taken into consideration to keep | s | < 1.
and hence the result will not be sufficiently accurate.
To overcome this problem, we go for next formula named
Newton’s Backward difference formula.