Top Banner
1 Joseph-Louis Lagrange (1736-1813) Charles Hermite (1822-1901)
30

Joseph-Louis Lagrange (1736-1813) Charles Hermite (1822-1901)

Mar 22, 2022

Download

Documents

dariahiddleston
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Joseph-Louis Lagrange (1736-1813) Charles Hermite (1822-1901)

1

Joseph-Louis Lagrange (1736-1813) Charles Hermite (1822-1901)

Page 2: 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

Page 3: Joseph-Louis Lagrange (1736-1813) Charles Hermite (1822-1901)

3

Joseph-Louis Lagrange (1736-1813) Sir Isaac Newton (1642-1726)

Page 4: Joseph-Louis Lagrange (1736-1813) Charles Hermite (1822-1901)

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.โ€ฆ..

Page 5: Joseph-Louis Lagrange (1736-1813) Charles Hermite (1822-1901)

3.5 Cubic Spline Interpolation

5

Page 6: Joseph-Louis Lagrange (1736-1813) Charles Hermite (1822-1901)

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

Page 7: Joseph-Louis Lagrange (1736-1813) Charles Hermite (1822-1901)

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

Page 8: Joseph-Louis Lagrange (1736-1813) Charles Hermite (1822-1901)

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

Page 9: Joseph-Louis Lagrange (1736-1813) Charles Hermite (1822-1901)

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

Page 10: Joseph-Louis Lagrange (1736-1813) Charles Hermite (1822-1901)

(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.

Page 11: Joseph-Louis Lagrange (1736-1813) Charles Hermite (1822-1901)

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

Page 12: Joseph-Louis Lagrange (1736-1813) Charles Hermite (1822-1901)

โ€ข 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

Page 13: Joseph-Louis Lagrange (1736-1813) Charles Hermite (1822-1901)

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

Page 14: Joseph-Louis Lagrange (1736-1813) Charles Hermite (1822-1901)

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

Page 15: Joseph-Louis Lagrange (1736-1813) Charles Hermite (1822-1901)

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

Page 16: Joseph-Louis Lagrange (1736-1813) Charles Hermite (1822-1901)

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

Page 17: Joseph-Louis Lagrange (1736-1813) Charles Hermite (1822-1901)

Example 1. Construct a natural cubic spline ๐‘† ๐‘ฅthrough (1,2), (2,3) and (3,5).

17

Page 18: Joseph-Louis Lagrange (1736-1813) Charles Hermite (1822-1901)

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

Page 19: Joseph-Louis Lagrange (1736-1813) Charles Hermite (1822-1901)

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

Page 20: Joseph-Louis Lagrange (1736-1813) Charles Hermite (1822-1901)

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

Page 21: Joseph-Louis Lagrange (1736-1813) Charles Hermite (1822-1901)

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

Page 22: Joseph-Louis Lagrange (1736-1813) Charles Hermite (1822-1901)

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

Page 23: Joseph-Louis Lagrange (1736-1813) Charles Hermite (1822-1901)

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

Page 24: Joseph-Louis Lagrange (1736-1813) Charles Hermite (1822-1901)

Building Cubic Splines: SummaryStep 0: Obtain ๐‘Ž-vector and โ„Ž-vector:

Step 1: solve tri-diagonal linear system ๐ด๐‘ = ๐น to obtain ๐‘-vector ๐‘ = [๐‘), ๐‘,,โ‹ฏ , ๐‘"]โ€ฒ, where

24

Natural:

Clamped:

Page 25: Joseph-Louis Lagrange (1736-1813) Charles Hermite (1822-1901)

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;

Page 26: Joseph-Louis Lagrange (1736-1813) Charles Hermite (1822-1901)

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

Page 27: Joseph-Louis Lagrange (1736-1813) Charles Hermite (1822-1901)

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

Page 28: Joseph-Louis Lagrange (1736-1813) Charles Hermite (1822-1901)

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

Page 29: Joseph-Louis Lagrange (1736-1813) Charles Hermite (1822-1901)

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

Page 30: Joseph-Louis Lagrange (1736-1813) Charles Hermite (1822-1901)

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