![]() |
|
Course notes by Dr. Joseph M. Maubach.
See also the textbook by Kreyszig, 17.3.
In all of the interpolation material, at times
function values
.
are sampled (measured). Hence, in all
sections, we use
sample times and start
with index 0. The reason is that a polynomial
of degree
(example: degree 2:
)
has
associated degrees of freedom,
of which the first one (constant) has index 0.
This section discusses the problems described next.
Problem: A function f is know in sampled form:
| 0 | 1 | 2 | 3 | 4 | |
| -2 | -1 | 0 | 1 | 2 | |
| 18 | 0 | 0 | 0 | 6 |
Determine
Proposed solution: Find a degree 4 polynomial
(5 sample points) which
approximates (resembles)
. Because
Reconsider the problem of interpolating
| 0 | 1 | 2 | 3 | 4 | |
| -2 | -1 | 0 | 1 | 2 | |
| 18 | 0 | 0 | 0 | 6 |
![]() |
(3) |
![]() |
(4) |
A = [1, -2, 4, -8, 16; 1, -1, 1, -1, 1; 1, 0, 0, 0, 0; 1, 1, 1, 1, 1; 1, 2, 4, 8, 16] b = [18; 0; 0; 0; 6] c = A \ bThis gives:
Solution to the original problems 1
and 2 are:
Instead of the separate steps, one can call a polynomial fit routine
polyfit([-2, -1, 0, 1, 2], [18, 0, 0, 0, 6], 4)The returned answer is
1.0000 -1.0000 -1.0000 1.0000 0.0000,
i.e., the coefficients are in the reverse order.
The commands
c = polyfit([-2, -1, 0, 1, 2], [18, 0, 0, 0, 6], 4) t = -2:0.01:2 f = polyval(c,t) plot(t, f)also plot the polynomial. The arguments of polyval are the computed sequence of coefficients, and a sequence of sample data
syms x solve(x^5 - 15*x^4 + 85*x^3 -225*x^2 + 274*x -120)and be approximated with the command roots:
c = [1, -15, 85, -225, 274, -120] roots(c)The roots turn out to be
![]() |
(6) |
| (7) |
x = [1, 2, 3, 4]are indexed with
x(1) x(2) x(3) x(4)This notebook indexes
|
|
0 | 1 | 2 | 3 | 4 |
|
|
-1 | -1/2 | 0 | 1/2 | 1 |
|
|
1/26 | 4/29 | 0 | 4/29 | 1/26 |
![]() |
(10) |
In order to see how good polynomial interpolation
works, because we know
from equation 8,
we compute the exact answers first.
With matlab
syms x int(1 / (1 + 25*x^2), x)As an alternative, with mathematica
F[x_] = 1 / (1 + 25x^2)
Integrate[F[x], {x, -1, 1}] = 2/5 *ATan[5]
which is approximately ![]() |
(11) |
![]() |
(12) |
The interpolant based on all 5 sample points is unique. It doesn't
matter whether it has been calculated with the use of the monomial,
Lagrangian or Newton's basis:
In matlab:
c = polyfit([-1, -1/2, 0, 1/2, 1], [1/26, 4/29, 1, 4/29, 1/26], 4) x = -1:0.01:1 y = polyval(c,x) plot(x, y)In mathematica:
Expand[InterpolatingPolynomial[{{-1, 1/26}, {-1/2, 4/29}, {0, 1}, {1/2, 4/29}, {1, 1/26}}, x]]
is:
![]() |
(13) |
![]() |
(14) |
We find
![]() |
(15) |
Integrate[p_4[x], {x, -1, 1}]
Integrate[p_2[x], {x, -1, 1}]
Note: The mathematica command
N[Solve[D[p[x], x] == 0, x]])can be used to compute the minima of
Instead of the monomial and Lagrange basis we can construct our interpolant with the use of a Newton basis.
![]() |
(16) |
| (17) |
![]() |
(19) |
The computation of the interpolant with the use of a monomial
basis costs a lot of computations, which must be redone for different function
.
With the use of a special basis this can be avoided.
![]() |
(21) |
![]() |
(23) |
![]() |
(24) |
Proof:
Due to the Kronecker property, for all
:
![]() |
(25) |
![]() |
(26) |
![]() |
(27) |
![]() |
(28) |
We have seen that the different manners (different bases) for the computation of the interpolant have different characteristics. Here is an overview:
| Type of basis | monomial | Newton | Lagrange |
| Linear system of equations | full - bad | triangular | none |
| Basis functions | simple | less simple | complex |
| Polynomial evaluation | cheap | less cheap | expensive |
Here, bad stands for badly conditioned.
However, polynomial interpolants based on equi-distant grid-points
can perform in a poor manner, as the next example shows.
x = -1:0.01:1; y = 1 ./ (1 + 25*x.^2); plot(x, y)Section 7 presents different interpolation techniques (non-equidistributed points
The interpolant can be computed with the use of bases different from the ones we have seen. To mention a few widely used ones:
Let
. The computation of
costs
operations,
the computation of
costs
operations and
the evaluation of
| (30) |
![]() |
(31) |
![]() |
(32) |
But it is possible to eliminate common subexpressions,
or factor out common subexpressions.
For instance, after
is computed with the use of
one multiplication,
can be computed with one
additional multiplication:
![]() |
(33) |
![]() |
(34) |
![]() |
(35) |
0.57 0.91 0.12
1.01 0.79 0.16
1.57 0.71 0.25
2.02 0.69 0.38
2.48 0.60 0.41
3.05 0.51 0.52
4.01 0.41 0.59
4.98 0.34 0.62
5.50 0.31 0.65
6.02 0.29 0.69
7.04 0.25 0.71
7.49 0.23 0.76
8.03 0.19 0.78
8.49 0.16 0.77
This file contains two concentrations, measured in time.
The first column is the time (seconds), the other two columns are the
concentrations. Visualize the measured concentrations
in matlab:
load reacdata.prn t = reacdata(:,1); c1 = reacdata(:,2); c2 = reacdata(:,3); plot(t,c1,'o',t,c2,'x')Interpolate the first concentration data, first with a polynomial of degree
c = polyfit(t, c1, 4) x = 0:0.01:9 y = polyval(c,x) plot(x, y, '-', t, c1, 'o')Next, interpolate it with a polynomial of degree 13 (fourteen samples):
c = polyfit(t, c1, 13) x = 0:0.01:9 y = polyval(c,x) plot(x, y, '-', t, c1, 'o')
Also interpolate the second concentration with
a polynomial of degree
and degree
.
|
|
0 | 1 | 2 | 3 | 4 |
|
|
-2 | -1 | 0 | 1 | 2 |
|
|
4 | 1 | 0 | 1 | 4 |
|
|
0 | 1 | 2 |
|
|
1 | -1 | 0 |
|
|
0 | 0 | 1 |