U9-Newton Interpolation
U9-Newton Interpolation
Study the content and do the excercises in this document. Read all the comments for the instructions. It will help
you to use Matlab more optimally.
Lesson Outcomes
At the end of this lesson the student should be able to:
1. Introduction
With the determination of Lagrange-interpolating polynomials, the Lagrange functions have to be recalculated
every instance when a data pair is added. Newton interpolating polynomials are based on divided differences
and only a term is added to the existing interpolating polynomial for each data pair that is added.
2. Divided differences
Suppose that is the Lagrange polynomial that agrees with the function f at the distinct numbers
Although this polynomial is unique, alternate algebraic representations are useful in certain
situations. The divided differences of f with respect to are used to express in the form
so
• The zeroth divided difference of the function f with respect to is denoted by , which is just the
value of f at :
1
• The first divided difference of fwith respect to and is denoted by and is defined as
Take note that can be rewritten as . Therefore the interpolating takes the form
2
Example 1
Consider the data in the given table.
Determine divided differences for the data by executing the instructions below.
Check the calculations by hand to make sure you know how it is calculated.
3
Exercise 1
Consider the data in the given table.
Determine divided differences for the data by copying, changing and executing the instructions above. Check
the calculations per hand to make sure you know how it is calculated.
Example 2
Consider the data in the given table.
Determine divided differences for the data by executing the instructions below.
Check the calculations per hand to make sure you know how it is calculated.
Exercise 2
Consider the data in the given table.
Determine divided differences for the data by copying, changing and executing the instructions above. Check
the calculations per hand to make sure you know how it is calculated.
4
Exercise 3
Consider the data in the given table.
Determine divided differences for the data by copying, changing and executing the instructions above. Check
the calculations per hand to make sure you know how it is calculated.
Example 3
When working with big data sets, this kind of working becomes unpractical. Determine the divided differences
for the given data in the table by executing the instructions below.
Exercise 4
Determine the divided differences for the data in the given table by copying, changing and executing the
instructions above.
5
Example 4
Determine the Newton interpolating polynomial with least degree of one which will generate the data in
the given table and the straight line through the points. Simplify both. Determine approximate values in the
points 2, 3 and 4. Sketch the data pairs and interpolating polynomial on the same set of axes.
Compare it with Example 1 of Lesson 8. It is the same according to the existence and uniqueness theorem for
interpolating polynomials.
P1=@(x)D(1,2)+D(1,3)*(x-D(1,1));
P1(2)
P1(3)
P1(4)
% Coefficients of the polynomial with constant term first
syms q
eval(coeffs(P1(q)))
6
fplot(P1,[1 5])
hold off
Exercise 5
Determine the Newton interpolating polynomial with least degree of one which will generate the data in
the given table and the straight line through the points by following the above steps. Simplify both. Determine
approximate values in the points -2, -1 and 0. Sketch the data pairs and interpolating polynomial on the same
set of axes.
Compare it with Exercise 1 of Lesson 8. It is the same according to the existence and uniqueness theorem for
interpolating polynomials.
Example 5
Determine the Newton interpolating polynomial with least degree of two which will generate the data
in the given table. Determine approximate values in the points 2, 3, 4, 4.5 and 5. Sketch the data pairs and
interpolating polynomial on the same set of axis.
7
% Coefficients of the polynomial with constant term first
syms q
eval(coeffs(PN2(q)))
Compare it with Example 2 of Lesson 8. The polynomial is the same according to the existence and uniquenes
theorem for interpolating polynomials.
Determine the absolute difference between the approximate value for the data for according to the
Lagange- and Newton interpolating polynomials.
PL2 = lagrangepol(D)
PN2(4.7352)
PL2(4.7352)
abs(PN2(4.7352)-PL2(4.7352))
According to the existence and uniqueness theorem for interpolation polynomials, there should be no difference
between these values. As already indicated, the two polynomials are equal. The difference between the values
in the order of is due to machine rounding (rounding done by Matlab itself due to limited calculation ability
of computers).
Note that the values displayed, 1.464940480000000, are values rounded to 15 decimals.
Exercise 6
Determine the Newton interpolating polynomial with least degree of two which will generate the data in the
given table by following the above steps. Determine approximate values in the points -2, -1, 0, 0.5 and 1. Give
the values rounded off to four decimals. Sketch the data and interpolating polynomial on the same set of axes.
8
N2(0.5)
N2(1)
Compare it with Exercise 2 of Lesson 8. It is the same according to the existence and uniqueness theorem for
interpolating polynomials.
Exercise 7
Determine the Newton interpolating polynomial with least degree of three which will generate the data in
the given table by following the above steps. Determine approximate values in the points -2, -1, 0, 0.5 and 1.
Give the values rounded off to four decimals. Sketch the data and interpolating polynomial on the same set of
axes.
Compare it with Exercise 3 of Lesson 8. It is the same according to the existence and uniqueness theorem for
interpolating polynomials.
Example 6
When working with big data sets, this kind of working becomes unpractical. A Matlab fuction which determines
a Newton interpolating polynomial from a given data set is given at the end of this document. To determine
a Newton interpolating polynomial with leasst degree of nine that will generate the given data set, the Matlab
function can be called by executing the instructions below. Study the code in the Matlab function and execute
the instructions below. Determine approximate values in the points 1, 3, 6, 7.25, 8.5, 11 and 13. Give the values
rounded off to four decimals. Sketch the data and interpolating polynomial on the same set of axes.
9
fplot(P9,[2 12])
hold off
Compare it with Example 3 of Lesson 8. It is the same according to the existence and uniqueness theorem for
interpolating polynomials.
Exercise 8
Determine the Newton interpolating polynomial with least degree of seven which will generate the data
in the given table by copying, changing and executing the instructions above. Determine approximate values in
the points -1.5, 2, 4 and 5.5. Give the values rounded off to four decimals. Sketch the data and interpolating
polynomial on the same set of axes. Which of the approximate values are reliable?
Compare it with Exercise 4 of Lesson 8. It is the same according to the existence and uniqueness theorem for
interpolating polynomials.
4. Exercising
Exercise 9
Show that the interpolating polynomial which will generate the data in the given table, is of third degree.
10
% Give the instructions and execute them.
Exercise 10
Show that the two interpolating polynomials both generates the data in the given table and adhere to the
conditions of the existence and uniqueness theorem for interpolating polynomials.
Exercise 11
For a function the Newton interpolating polynomial is given by
at nodes
Determine .
Exercise 12
Complete the missing elements in the divided differences table.
11
5. Can you do the following in Matlab?
1. Newton interpolating polynomial define and approximate values in points determine.
Function
Copy and save the code of the function in a new "script" as name.m where "name" is the name of the function.
You can then call and execute it directly from the "Command Window" if it is saved in the "Current Folder", the
folder as indicated just below the toolbar. You can change the "Current Folder" by clicking on it. The function
can also be copied in a "script" or "live script" together with other instructions, including the instruction calling
the function. It just has to be at the end of the document as done here.
function P=lagrangepol(D)
12
% Determine Lagrange interpolating polynomials
% D: data with x values in column 1 and y values in column 2 [x0 y0; x1 y1; x2
y2; ...]
% Lagrange interpolating polynomial is saved in P.
format long
[n c]=size(D);
P=@(x)0;
for k=1:n
L=@(x)1;
for j=1:k-1
L=@(x)L(x).*(x-D(j,1))./(D(k,1)-D(j,1));
end
for j=k+1:n
L=@(x)L(x).*(x-D(j,1))./(D(k,1)-D(j,1));
end
P=@(x)P(x)+D(k,2).*L(x);
end
end
13