Joseph-Louis Lagrange (1736-1813) Charles Hermite (1822-1901)
Transcript of Joseph-Louis Lagrange (1736-1813) Charles Hermite (1822-1901)
Summary of Lagrange/Hermite Interpolation1) Find a โgoodโ polynomial basis
ร Lagrange Basis: ๐ฟ",$(๐ฅ)ร (Newton) Divided-difference basis:
๐ฅ โ ๐ฅ) โฆ (๐ฅ โ ๐ฅ$+,)รHermite Basis: ๐ป",$ ๐ฅ , .๐ป",$ ๐ฅร (Newton) Divided-difference basis for Hermite:
๐ฅ โ ๐ง) โฆ ๐ฅ โ ๐ง$+,2) Interpolation formula
๐" ๐ฅ = 2$3)
"
๐(๐ฅ$)๐ฟ",$(๐ฅ)
๐ป" ๐ฅ = 2$3)
"
๐ ๐ฅ$ ๐ป",$ ๐ฅ +2$3)
"
๐โฒ ๐ฅ$ .๐ป",$ ๐ฅ
2
Lagrange form V.S. Newton form
4
https://en.wikipedia.org/wiki/Newton_polynomial
Quoted from wiki:
Lagrange is sometimes said to require less work, and is sometimes recommended for problems in which it's known, in advance, from previous experience, how many terms are needed for sufficient accuracy.
The divided difference methods have the advantage that more data points can be added, for improved accuracy, without re-doing the whole problem. The terms based on the previous data points can continue to be used. With the ordinary Lagrange formula, to do the problem with more data points would require re-doing the whole problem.โฆ..
Problems with High Order Polynomial Interpolation
โข 20th degree Lagrange interpolant for
๐ ๐ฅ = ,,789:;
on the interval [-1,1] using 21 equal-spaced nodes. โข The Lagrange interpolating polynomial oscillates
between interpolation points. [Rungeโs phenomenon]6
-1 -0.5 0 0.5 1
0
0.2
0.4
0.6
0.8
1
Remedy 1: use non-uniform nodes
โข 20th degree Lagrange interpolant for
๐ ๐ฅ = ,,789:;
on the interval [-1,1] using n=21 Chebyshev nodes:
๐ฅ$ = โcos๐๐๐, ๐ = 0,โฆ , ๐
7
-1 -0.5 0 0.5 1
0
0.2
0.4
0.6
0.8
1
8
% function and interpolation nodesf = @(x) 1./(1+25*x.*x);n = 21; % degree 20 interpolation%xNodes = linspace(-1,1,n+1);xNodes = -cos([0:n]/n*pi); % chebyshev nodesyNodes = f(xNodes);
% evaluate function at 1001 uniform pointsm = 1001;xGrid = linspace(-1,1,m);pGrid = zeros(size(xGrid));
for k = 0:n yk = yNodes(k+1); phi_k = lagrange_basis(xGrid, xNodes, k); % k-th basis eval @ xGrid pGrid = pGrid + yk*phi_k;end
plot(xGrid, f(xGrid),'b', xGrid, pGrid, 'r', xNodes, yNodes, 'ko',... 'LineWidth', 4,'MarkerSize',10)set(gca, 'FontSize',24)axis([-1,1,-0.1,1.1])shgsaveas(gcf, 'cheb.eps','epsc')%saveas(gcf, 'uniform.eps','epsc')
1
lagrange_interp_cheby.mscript .m file for Lagrange interp. with Cheb. nodes
Remedy 2: use smooth piecewise polynomials
โข n=21 equal-spaced interpolation nodes
๐ฅ$ = โ1 +2๐๐, ๐ = 0,โฆ , ๐
โข On each small interval [๐ฅF, ๐ฅF7,], ๐(๐ฅ) is a polynomial of degree 3
โข ๐(๐ฅ) has continuous first and second derivatives at internal nodes ๐ฅF for ๐ = 1,โฆ , ๐ โ 1 9
(smooth) piecewise polynomial interpolation [splines]
10
โข Spline: A spline consists of a long strip of wood (a lath) fixed in position at a number of points. The lath will take the shape which minimizes the energy required for bending it between the fixed points, and thus adopt the smoothest possible shape.
Cubic Splinesโข Idea: Use piecewise polynomial interpolation, i.e,
divide the interval into smaller sub-intervals, and construct different low degree polynomial approximations (with small oscillations) on the sub-intervals.
11
Example. Piecewise-linear interpolation
โข In mathematics, a spline is a function that is piecewise-defined by polynomial functions, and which possesses a high degree of smoothness at the places where the polynomial pieces connect.
โข Example. Irwin-Hall distribution. Nodes are -2, -1, 0, 1, 2.
๐ ๐ฅ =
14๐ฅ + 2 K โ 2 โค ๐ฅ โค โ1
143 ๐ฅ K โ 6๐ฅ8 + 4 โ 1 โค ๐ฅ โค 1142 โ ๐ฅ K 1 โค ๐ฅ โค 2
Notice: ๐ โ ๐ถ8 โ2,2 , ๐. ๐. ๐, ๐T, ๐TT are all continuous:
๐T โ1 =34, ๐T 1 = โ
34, ๐TT โ1 =
64, ๐TT 1 =
64.
12
cubic spline interpolation is a piecewise-polynomial approximation thata) use cubic polynomials between each successive
pair of nodes.b) has both continuous first and second derivatives
at the internal nodes
13
Definition 3.10. Given a function ๐ on [๐, ๐] and nodes ๐ =๐ฅ) < โฏ < ๐ฅ" = ๐, a cubic spline interpolant ๐ for ๐ satisfies:(a) ๐(๐ฅ) is a cubic polynomial ๐F(๐ฅ) on [๐ฅF, ๐ฅF7,] with:
๐F ๐ฅ = ๐F + ๐F ๐ฅ โ ๐ฅF + ๐F ๐ฅ โ ๐ฅF8 + ๐F ๐ฅ โ ๐ฅF
K
โ๐ = 0,1, โฆ , ๐ โ 1.(b) [interpolation property]
๐F ๐ฅF = ๐(๐ฅF) and ๐F ๐ฅF7, = ๐ ๐ฅF7, , โ๐ = 0,1, โฆ , ๐ โ 1.(c) [continuous first derivative]
๐TF ๐ฅF7, = ๐TF7, ๐ฅF7, , โ๐ = 0,1, โฆ , ๐ โ 2.(d) [continuous second derivative]
๐TTF ๐ฅF7, = ๐TTF7, ๐ฅF7, , โ๐ = 0,1, โฆ , ๐ โ 2.(e) [One of the following boundary conditions]:(i) ๐TT ๐ฅ) = ๐TT ๐ฅ" = 0 (called free or natural boundary)(ii) ๐T ๐ฅ) = ๐โฒ(๐ฅ)) and ๐T ๐ฅ" = ๐โฒ(๐ฅ") (called clamped
boundary) 14
The spline segment ๐F(๐ฅ) is on ๐ฅF, ๐ฅF7, . The spline segment ๐F7,(๐ฅ) is on ๐ฅF7,, ๐ฅF78 . Things to match at interior point ๐ฅF7,:โข Their function values: ๐F ๐ฅF7, = ๐F7, ๐ฅF7, =๐ ๐ฅF7,
โข First derivative values: ๐TF ๐ฅF7, = ๐TF7, ๐ฅF7,โข Second derivative values: ๐TTF ๐ฅF7, = ๐TTF7, ๐ฅF7,
15
The Cubic spline interpolation problemGiven data ๐ฅ), ๐ ๐ฅ) , โฆ , (๐ฅ", ๐ ๐ฅ" ), find the coefficients ๐F, ๐F, ๐F, ๐F for ๐ = 0,โฆ , ๐ โ 1 of the Cubic spline interpolant ๐ ๐ฅ :
๐ ๐ฅ =
๐) ๐ฅ ๐ฅ) โค ๐ฅ โค ๐ฅ,
โฆ โฆ๐F(๐ฅ) ๐ฅF โค ๐ฅ โค ๐ฅF7,
โฆ โฆ๐"+,(๐ฅ) ๐ฅ"+, โค ๐ฅ โค ๐ฅ"
Where ๐F ๐ฅ = ๐F + ๐F ๐ฅ โ ๐ฅF + ๐F ๐ฅ โ ๐ฅF8 + ๐F ๐ฅ โ ๐ฅF
K,
such that conditions in (b)-(e) of Definition 3.10holds.
16
Building Cubic Splinesโข Define: ๐F ๐ฅ = ๐F + ๐F ๐ฅ โ ๐ฅF + ๐F(๐ฅ โ ๐ฅF)8+๐F(๐ฅ โ ๐ฅF)K
and โF = ๐ฅF7, โ ๐ฅF, โ๐ = 0,1, โฆ , (๐ โ 1).โข Also define ๐" = ๐ ๐ฅ" ; ๐" = ๐T ๐ฅ" ; ๐" = ๐TT(๐ฅ")/2.From Definition 3.10:1) ๐F ๐ฅF = ๐F = ๐ ๐ฅF for ๐ = 0,1, โฆ , (๐ โ 1).2) ๐F ๐ฅF7, = ๐F7, = ๐F + ๐FโF + ๐F(โF )8+๐F(โF )K
for ๐ = 0,1, โฆ , (๐ โ 1).
3) ๐TF ๐ฅF = ๐TF7, ๐ฅF : ๐F7, = ๐F + 2๐FโF + 3๐F(โF )8for ๐ = 0,1, โฆ , (๐ โ 1).
4) ๐TTF ๐ฅF = ๐TTF7, ๐ฅF : ๐F7, = ๐F + 3๐FโFfor ๐ = 0,1, โฆ , ๐ โ 1 .
5) Natural or clamped boundary conditions18
Solve ๐F, ๐F, ๐F, ๐F by substitution:1. Solve Eq. 4) for ๐F =
cdef+cdKgd
(3.17) , and substitute into Eqs. 2) and 3) to get:
2. ๐F7, = ๐F + ๐FโF +gd;
K2๐F + ๐F7, ; (3.18)
๐F7, = ๐F + โF ๐F + ๐F7, . (3.19)3. Solve for ๐F in Eq. (3.18) to get:
๐F =,gd
๐F7, โ ๐F โ gdK2๐F + ๐F7, . (3.20)
Reduce the index by 1 to get:
๐F+, =,
gdjf๐F โ ๐F+, โ
gdjfK
2๐F+, + ๐F .
4. Substitute ๐F and ๐F+, into Eq. (3.19) [reduce index by 1]:โF+,๐F+, + 2 โF+, + โF ๐F + โF๐F7, = (3.21)
3โF
๐F7, โ ๐F โ3โF+,
(๐F โ ๐F+,)
for ๐ = 1,2, โฆ , ๐ โ 1 . 19
Solving the Resulting Equations for ๐โ๐ = 1,2, โฆ , (๐ โ 1)
โF+,๐F+, + 2 โF+, + โF ๐F + โF๐F7,
=3โF
๐F7, โ ๐F โ3โF+,
๐F โ ๐F+, (3.21)
Remark: (n-1) equations for (n+1) unknowns {๐F}F3)" . Eq. (3.21) is solved with boundary conditions. โข Once compute ๐F, we then compute:
๐F =mdef+md
gdโ gd 8cd7cdef
K(3.20)
and
๐F =cdef+cdKgd
(3.17) for ๐ = 0,1,2, โฆ , (๐ โ 1)20
Building Natural Cubic Spline โข Natural boundary condition: 1. 0 = ๐TT) ๐ฅ) = 2๐) โ ๐) = 02. 0 = ๐TT" ๐ฅ" = 2๐" โ ๐" = 0
Step 1. Solve Eq. (3.21) together with ๐) = 0 and ๐" = 0 to obtain {๐F}F3)" .
Step 2. Solve Eq. (3.20) to obtain {๐F}F3)"+,.
Step 3. Solve Eq. (3.17) to obtain {๐F}F3)"+,.
21
Building Natural Cubic Spline โข Natural boundary condition: 1. 0 = ๐TT) ๐ฅ) = 2๐) โ ๐) = 02. 0 = ๐TT" ๐ฅ" = 2๐" โ ๐" = 0
Step 1. Solve Eq. (3.21) together with ๐) = 0 and ๐" = 0 to obtain {๐F}F3)" .
Step 2. Solve Eq. (3.20) to obtain {๐F}F3)"+,.
Step 3. Solve Eq. (3.17) to obtain {๐F}F3)"+,.
22
Building Clamped Cubic Splineโข Clamped boundary condition: a) ๐T) ๐ฅ) = ๐) = ๐โฒ(๐ฅ))b) ๐T"+, ๐ฅ" = ๐"+, + โ"+,(๐"+, + ๐") = ๐โฒ(๐ฅ")Remark: a) and b) gives additional equations:2โ)๐) + โ)๐, =
Kgq
๐, โ ๐) โ 3๐T ๐ฅ) (๐)
โ"+,๐"+, + 2โ"+,๐" = โ3
โ"+,๐" โ ๐"+, + 3๐T ๐ฅ" (๐)
Step 1. Solve Eq. (3.21) together with Eqs. (a) and (b) to obtain {๐F}F3)" .Step 2. Solve Eq. (3.20) to obtain {๐F}F3)"+,.Step 3. Solve Eq. (3.17) to obtain {๐F}F3)"+,.
23
Building Cubic Splines: SummaryStep 0: Obtain ๐-vector and โ-vector:
Step 1: solve tri-diagonal linear system ๐ด๐ = ๐น to obtain ๐-vector ๐ = [๐), ๐,,โฏ , ๐"]โฒ, where
24
Natural:
Clamped:
Step 2: Recover ๐-vector ๐ = [๐), ๐,,โฏ , ๐"+,]โฒ:
๐F =mdef+md
gdโ
gd 8cd7cdefK
(3.20)
Step 3: Recover ๐-vector ๐ = [๐), ๐,,โฏ , ๐"+,]โฒ:
๐F =cdef+cdKgd
(3.17)
Building Cubic Splines: Summary
25
Remark: Main computational cost is the linear system solve in Step 1. In MATLAB, we simply use the โbackslashโ \command to solve the system:
๐ = ๐ด\F;
Example 2. (MATLAB) Use data points (0,1), (1, ๐), (2, ๐8), (3, ๐K) to form a) a natural cubic spline ๐ ๐ฅ that approximates ๐ ๐ฅ = ๐:.
b) a clamped cubic spline ๐ ๐ฅ that approximates ๐ ๐ฅ = ๐: with derivative information ๐โ(0) =1, ๐โ(3) = ๐K.
26
27
% input: data pointsf = @(x) exp(x);xNodes = [0:3]'; % column vectoryNodes = f(xNodes);
%--- STEP 0: obtain the a-vectora = yNodes;
%--- STEP 1: form linear system, solve for c-vectorn = length(xNodes)-1;% mesh size, vector of size nh = xNodes(2:n+1)-xNodes(1:n);% form the matrixA = zeros(n+1,n+1);A(1,1) =1;for j = 2:n A(j,j-1) = h(j-1); A(j,j) = 2*(h(j-1)+h(j)); A(j,j+1) = h(j);endA(n+1,n+1)=1;% form the right hand sideF = zeros(n+1,1);for j = 2:n F(j) = 3/h(j)*(a(j+1)-a(j))... - 3/h(j-1)*(a(j)-a(j-1));end
% solve for c [backslash]c = A\F;
%--- STEP 2: solve for b-vectorb = zeros(n,1);for j = 1:n b(j) = 1/h(j)*(a(j+1)-a(j))... -h(j)/3*(2*c(j)+c(j+1));end
%--- STEP 3: solve for d-vectord = zeros(n,1);for j=1:n d(j) = (c(j+1)-c(j))/3/h(j);end
%--- STEP 4: plot solution% loop over subintervalsxGrid = []; sGrid = [];for j = 1:n x0 = xNodes(j); x1 = xNodes(j+1); xTemp = linspace(x0,x1,20); sTemp = a(j)+b(j)*(xTemp-x0)+c(j)*(xTemp-x0).^2+d(j)*(xTemp-x0).^3;
1
% input: data pointsf = @(x) exp(x);xNodes = [0:3]'; % column vectoryNodes = f(xNodes);
%--- STEP 0: obtain the a-vectora = yNodes;
%--- STEP 1: form linear system, solve for c-vectorn = length(xNodes)-1;% mesh size, vector of size nh = xNodes(2:n+1)-xNodes(1:n);% form the matrixA = zeros(n+1,n+1);A(1,1) =1;for j = 2:n A(j,j-1) = h(j-1); A(j,j) = 2*(h(j-1)+h(j)); A(j,j+1) = h(j);endA(n+1,n+1)=1;% form the right hand sideF = zeros(n+1,1);for j = 2:n F(j) = 3/h(j)*(a(j+1)-a(j))... - 3/h(j-1)*(a(j)-a(j-1));end
% solve for c [backslash]c = A\F;
%--- STEP 2: solve for b-vectorb = zeros(n,1);for j = 1:n b(j) = 1/h(j)*(a(j+1)-a(j))... -h(j)/3*(2*c(j)+c(j+1));end
%--- STEP 3: solve for d-vectord = zeros(n,1);for j=1:n d(j) = (c(j+1)-c(j))/3/h(j);end
%--- STEP 4: plot solution% loop over subintervalsxGrid = []; sGrid = [];for j = 1:n x0 = xNodes(j); x1 = xNodes(j+1); xTemp = linspace(x0,x1,20); sTemp = a(j)+b(j)*(xTemp-x0)+c(j)*(xTemp-x0).^2+d(j)*(xTemp-x0).^3;
1
natural cubic spline (script .m file)natural_cubic_spline.m
xGrid = [xGrid, xTemp]; sGrid = [sGrid, sTemp];endplot(xGrid, f(xGrid),'b', xGrid, sGrid, 'r', xNodes, yNodes, 'ko',... 'LineWidth', 4,'MarkerSize',10)legend('F(x)', 'S(x)','Nodes','Location','best')set(gca, 'FontSize', 24)
Published with MATLABยฎ R2019a
2
28
natural cubic spline (script .m file continued)natural_cubic_spline.m
%--- STEP 4: plot solution% loop over subintervalsxGrid = []; sGrid = [];for j = 1:n x0 = xNodes(j); x1 = xNodes(j+1); xTemp = linspace(x0,x1,20); sTemp = a(j)+b(j)*(xTemp-x0)... +c(j)*(xTemp-x0).^2+d(j)*(xTemp-x0).^3; xGrid = [xGrid, xTemp]; sGrid = [sGrid, sTemp];endplot(xGrid, f(xGrid),'b', ... xGrid, sGrid, 'r', ... xNodes, yNodes, 'ko',... 'LineWidth', 4,'MarkerSize',10)legend('F(x)', 'S(x)','Nodes','Location','best')set(gca, 'FontSize', 24)
Published with MATLABยฎ R2019a
1
****clamped cubic spline code is given in course webpage
Theorem 3.11 If ๐ is defined at the nodes: ๐ =๐ฅ) < โฏ < ๐ฅ" = ๐, then ๐ has a unique natural spline interpolant ๐ on the nodes; that is a spline interpolant that satisfied the natural boundary conditions ๐TT ๐ = 0, ๐TT ๐ = 0.
Theorem 3.12 If ๐ is defined at the nodes: ๐ =๐ฅ) < โฏ < ๐ฅ" = ๐ and differentiable at ๐ and ๐, then ๐ has a unique clamped spline interpolant ๐on the nodes; that is a spline interpolant that satisfied the clamped boundary conditions ๐T ๐ = ๐โฒ(๐), ๐T ๐ = ๐โฒ(๐).
29
Existence and Uniqueness
Error BoundTheorem 3.13 If ๐ โ ๐ถw[๐, ๐], let ๐ =maxm{:{|
|๐w(๐ฅ)|. If ๐ is the unique clamped cubic spline interpolant to ๐ with respect to the nodes: ๐ = ๐ฅ) < โฏ < ๐ฅ" = ๐, then with
โ = max){F{"+,
๐ฅF7, โ ๐ฅF
maxm{:{|
|๐ ๐ฅ โ ๐(๐ฅ)| โค 9~g๏ฟฝ
K๏ฟฝw.
30