Intro Polynomial Piecewise Cubic Spline Software Summary. Interpolation. Sanzheng Qiao. Department of Computing and Software McMaster University

Similar documents
Intro Polynomial Piecewise Cubic Spline Software Summary. Interpolation. Sanzheng Qiao. Department of Computing and Software McMaster University

Numerical Integration

Nonlinear Equations and Continuous Optimization

Solving Ordinary Differential Equations

Lecture 10 Polynomial interpolation

3.1 Interpolation and the Lagrange Polynomial

Elements of Floating-point Arithmetic

Cubic Splines MATH 375. J. Robert Buchanan. Fall Department of Mathematics. J. Robert Buchanan Cubic Splines

Elements of Floating-point Arithmetic

SPLINE INTERPOLATION

Scientific Computing

In practice one often meets a situation where the function of interest, f(x), is only represented by a discrete set of tabulated points,

Q1. Discuss, compare and contrast various curve fitting and interpolation methods

Lecture Note 3: Interpolation and Polynomial Approximation. Xiaoqun Zhang Shanghai Jiao Tong University

1 Piecewise Cubic Interpolation

Lectures 9-10: Polynomial and piecewise polynomial interpolation

CHAPTER 4. Interpolation

Curve Fitting and Interpolation

Polynomial Interpolation

University of Houston, Department of Mathematics Numerical Analysis, Fall 2005

We consider the problem of finding a polynomial that interpolates a given set of values:

1 Review of Interpolation using Cubic Splines

Input: A set (x i -yy i ) data. Output: Function value at arbitrary point x. What for x = 1.2?

Chapter 4: Interpolation and Approximation. October 28, 2005

Scientific Computing: An Introductory Survey

Chapter 1 Numerical approximation of data : interpolation, least squares method

MATH ASSIGNMENT 07 SOLUTIONS. 8.1 Following is census data showing the population of the US between 1900 and 2000:

Math 365 Homework 5 Due April 6, 2018 Grady Wright

BSM510 Numerical Analysis

Applied Math 205. Full office hour schedule:

Data Analysis-I. Interpolation. Soon-Hyung Yook. December 4, Soon-Hyung Yook Data Analysis-I December 4, / 1

Continuous Optimization

Polynomial Interpolation

Outline. 1 Interpolation. 2 Polynomial Interpolation. 3 Piecewise Polynomial Interpolation

Some notes on Chapter 8: Polynomial and Piecewise-polynomial Interpolation

Additional exercises with Numerieke Analyse

Interpolation. Chapter Interpolation. 7.2 Existence, Uniqueness and conditioning

INTERPOLATION Background Polynomial Approximation Problem:

Interpolation. 1. Judd, K. Numerical Methods in Economics, Cambridge: MIT Press. Chapter

Numerical Analysis: Interpolation Part 1

Function approximation

Interpolation Theory

Cubic Splines; Bézier Curves

x x2 2 + x3 3 x4 3. Use the divided-difference method to find a polynomial of least degree that fits the values shown: (b)

MA3457/CS4033: Numerical Methods for Calculus and Differential Equations

CHAPTER Order points and then develop a divided difference table:

Exam 2. Average: 85.6 Median: 87.0 Maximum: Minimum: 55.0 Standard Deviation: Numerical Methods Fall 2011 Lecture 20

Maria Cameron Theoretical foundations. Let. be a partition of the interval [a, b].

CS412: Introduction to Numerical Methods

Interpolation and Polynomial Approximation I

Interpolation. Escuela de Ingeniería Informática de Oviedo. (Dpto. de Matemáticas-UniOvi) Numerical Computation Interpolation 1 / 34

CS 450 Numerical Analysis. Chapter 8: Numerical Integration and Differentiation

Lösning: Tenta Numerical Analysis för D, L. FMN011,

Lecture Note 3: Polynomial Interpolation. Xiaoqun Zhang Shanghai Jiao Tong University

Physics 331 Introduction to Numerical Techniques in Physics

CS 323: Numerical Analysis and Computing

Interpolation (Shape Functions)

Eigenvalue Problems and Singular Value Decomposition

Polynomials. p n (x) = a n x n + a n 1 x n 1 + a 1 x + a 0, where

Numerical Methods I: Polynomial Interpolation

CS 323: Numerical Analysis and Computing

1 Lecture 8: Interpolating polynomials.

Numerical Methods I: Interpolation (cont ed)

Computational Physics

7. Piecewise Polynomial (Spline) Interpolation

Numerical interpolation, extrapolation and fi tting of data

There is a unique function s(x) that has the required properties. It turns out to also satisfy

Cubic B-spline Collocation Method for Fourth Order Boundary Value Problems. 1 Introduction

Interpolation and extrapolation

9.4 Cubic spline interpolation

you expect to encounter difficulties when trying to solve A x = b? 4. A composite quadrature rule has error associated with it in the following form

Engineering 7: Introduction to computer programming for scientists and engineers

Introduction Linear system Nonlinear equation Interpolation

Assignment 6, Math 575A

Empirical Models Interpolation Polynomial Models

Review I: Interpolation

CS 257: Numerical Methods

Cubic Splines. Antony Jameson. Department of Aeronautics and Astronautics, Stanford University, Stanford, California, 94305

An Introduction to Numerical Analysis. James Brannick. The Pennsylvania State University

Least squares regression

Curve Fitting. 1 Interpolation. 2 Composite Fitting. 1.1 Fitting f(x) 1.2 Hermite interpolation. 2.1 Parabolic and Cubic Splines

Preliminary Examination in Numerical Analysis

Introductory Numerical Analysis

Application of modified Leja sequences to polynomial interpolation

446 CHAP. 8 NUMERICAL OPTIMIZATION. Newton's Search for a Minimum of f(x,y) Newton s Method

LECTURE NOTES ELEMENTARY NUMERICAL METHODS. Eusebius Doedel

Finite Elements. Colin Cotter. January 18, Colin Cotter FEM

AIMS Exercise Set # 1

Department of Applied Mathematics and Theoretical Physics. AMA 204 Numerical analysis. Exam Winter 2004

Math 651 Introduction to Numerical Analysis I Fall SOLUTIONS: Homework Set 1

Lecture 1 INF-MAT3350/ : Some Tridiagonal Matrix Problems

Consider the following example of a linear system:

NUMERICAL METHODS. x n+1 = 2x n x 2 n. In particular: which of them gives faster convergence, and why? [Work to four decimal places.

In manycomputationaleconomicapplications, one must compute thede nite n

Two hours. To be provided by Examinations Office: Mathematical Formula Tables. THE UNIVERSITY OF MANCHESTER. 29 May :45 11:45

Interpolation and Approximation

Numerical Methods I Orthogonal Polynomials

Chapter 3 Interpolation and Polynomial Approximation

Numerical Marine Hydrodynamics

Simple Examples on Rectangular Domains

Transcription:

Interpolation Sanzheng Qiao Department of Computing and Software McMaster University January, 2014

Outline 1 Introduction 2 Polynomial Interpolation 3 Piecewise Polynomial Interpolation 4 Natural Cubic Spline 5 Software Packages

Outline 1 Introduction 2 Polynomial Interpolation 3 Piecewise Polynomial Interpolation 4 Natural Cubic Spline 5 Software Packages

Introduction Problem setting: Given (x 0, y 0 ),(x 1, y 1 ),...,(x n, y n ), x 0 < x 1 < x n, for example, a set of measurements, construct a function f : f(x i ) = y i, i = 0, 1,..., n Desirable properties of f : smooth: analytic and f (x) not too large (the first and second derivatives are continuous). simple: polynomial of minimum degree, easy to evaluate.

Example Measurements of the speed of sound in ocean water 5060 5040 5020 5000 speed (ft/sec) 4980 4960 4940 4920 4900 4880 4860 0 2000 4000 6000 8000 10000 12000 depth (ft)

Example Interpolation 5060 5040 5020 5000 speed (ft/sec) 4980 4960 4940 4920 4900 4880 4860 0 2000 4000 6000 8000 10000 12000 depth (ft)

Outline 1 Introduction 2 Polynomial Interpolation 3 Piecewise Polynomial Interpolation 4 Natural Cubic Spline 5 Software Packages

Polynomial Interpolation Advantages: easy to evaluate and differentiate Weierstrass Approximation Theorem: If f is any continuous function on the finite closed interval [a,b], then for every ǫ > 0 there exists a polynomial p n (x) of degree n = n(ǫ) such that max f(x) p n(x) < ǫ. x [a,b]

Polynomial Interpolation Advantages: easy to evaluate and differentiate Weierstrass Approximation Theorem: If f is any continuous function on the finite closed interval [a,b], then for every ǫ > 0 there exists a polynomial p n (x) of degree n = n(ǫ) such that max f(x) p n(x) < ǫ. x [a,b] Impractical (degree is often too high)

A straightforward approach A polynomial of degree n is determined by its n + 1 coefficients.

A straightforward approach A polynomial of degree n is determined by its n + 1 coefficients. Given (x 0, y 0 ),...,(x n, y n ) to be interpolated, we construct the linear system (Vandermonde matrix): 1 x 0 x0 n a 0 y 0 1 x 1 x1 n a 1 y 1... 1 x n xn n. a n solve for the coefficients of the polynomial =. y n p n (y)(x) = a 0 + a 1 x + + a n x n

Horner s rule Evaluating the polynomial: a 0 x 3 + a 1 x 2 + a 2 x + a 3 Horner s form: ((a 0 x + a 1 )x + a 2 )x + a 3

Horner s rule Evaluating the polynomial: a 0 x 3 + a 1 x 2 + a 2 x + a 3 Horner s form: ((a 0 x + a 1 )x + a 2 )x + a 3 v = a(0); for (i = 1:n) v = v*x + a(i); end

Horner s rule Evaluating the polynomial: a 0 x 3 + a 1 x 2 + a 2 x + a 3 Horner s form: ((a 0 x + a 1 )x + a 2 )x + a 3 v = a(0); for (i = 1:n) v = v*x + a(i); end The optimal (most efficient and accurate) way of evaluating a 0 x n +... + a n.

Vandermonde matrix When x 0,..., x n are distinct, the Vandermonde matrix is nonsingular. Thus the system has a unique solution (coefficients of the interpolating polynomial).

Vandermonde matrix When x 0,..., x n are distinct, the Vandermonde matrix is nonsingular. Thus the system has a unique solution (coefficients of the interpolating polynomial). Example. Given three points (28, 0.4695) and (30, 0.5000), (32, 0.5299) we have the system and the solution 1 28 28 2 1 30 30 2 1 32 32 2 a 0 a 1 a 2 = p 2 (31) = 0.5150 sin(30 ) a 0 a 1 a 2 = 2.050 10 2 1.960 10 2 7.500 10 5 0.4695 0.5000 0.5299.

Vandermonde matrix problem: The coefficient (Vandermonde) matrix is often ill-conditioned

Vandermonde matrix problem: The coefficient (Vandermonde) matrix is often ill-conditioned question What is the condition number of the Vandermonde matrix constructed by x i = 2000 + i, i = 0, 1,..., 7?

Vandermonde matrix problem: The coefficient (Vandermonde) matrix is often ill-conditioned question What is the condition number of the Vandermonde matrix constructed by x i = 2000 + i, i = 0, 1,..., 7? Answer: 1.87 10 37

Lagrange form (conceptually simple) Basis polynomials: {l j (x)} (j = 0, 1,..., n) of degree n such that l j (x i ) = { 1, if i = j 0, otherwise construct l j (x) = i j x x i x j x i Thus p n (y)(x) = n l j (x)y j j=0

Example Given three points: (28, 0.4695), (30, 0.5000), (32, 0.5299), construct a second degree interpolating polynomial in the Lagrange form: p 2 (x) = (x 30)(x 32) (28 30)(28 32) 0.4695 (x 28)(x 32) + (30 28)(30 32) 0.5000 (x 28)(x 30) + (32 28)(32 30) 0.5299 p 2 (31) = 0.5150 sin(31 )

Example Given three points: (28, 0.4695), (30, 0.5000), (32, 0.5299), construct a second degree interpolating polynomial in the Lagrange form: p 2 (x) = (x 30)(x 32) (28 30)(28 32) 0.4695 (x 28)(x 32) + (30 28)(30 32) 0.5000 (x 28)(x 30) + (32 28)(32 30) 0.5299 p 2 (31) = 0.5150 sin(31 ) Expensive to evaluate.

Dangers of polynomial interpolation An example. Runge s function (continuous derivatives of all order) 1 y(x) = 1 + 25x 2 on [ 1, 1] equally spaces x 0 = 1, x 1,, x n = 1 1 Equal Spacing (n = 13) 0.5 0 0.5 1 1.5 2 2.5 3 3.5 4 1 0.8 0.6 0.4 0.2 0 0.2 0.4 0.6 0.8 1

Dangers of polynomial interpolation An example. Runge s function (continuous derivatives of all order) 1 y(x) = 1 + 25x 2 on [ 1, 1] equally spaces x 0 = 1, x 1,, x n = 1 1 Equal Spacing (n = 13) 0.5 0 0.5 1 1.5 2 2.5 3 3.5 4 1 0.8 0.6 0.4 0.2 0 0.2 0.4 0.6 0.8 1 It is often best not to use global polynomial interpolation.

Outline 1 Introduction 2 Polynomial Interpolation 3 Piecewise Polynomial Interpolation 4 Natural Cubic Spline 5 Software Packages

Piecewise Polynomial Interpolation Given the partition α = x 1 < x 2 < < x n = β, interpolate on each [x i, x i+1 ] with a low degree polynomial.

Piecewise Polynomial Interpolation Given the partition α = x 1 < x 2 < < x n = β, interpolate on each [x i, x i+1 ] with a low degree polynomial. Linear L i (z) = a i + b i (z x i ), z [x i, x i+1 ] a i = y i, b i = y i+1 y i x i+1 x i, 1 i n 1

Algorithm. Piecewise linear interpolation Given vectors x and y with interpolating points, this function returns the piecewise linear interpolation coefficients in the vectors a and b. function [a,b] = pwl(x,y) n = length(x); a = y(1:n-1); b = diff(y)./diff(x);

Evaluation Given the piecewise linear interpolation L(z) represented by the coefficient vectors a, b, how do we evaluate this function at z [α,β]? First, we locate [x i, x i+1 ] such that z [x i, x i+1 ]. Then, we evaluate L(z) using L i (z). Search method: binary search, since x i are sorted.

Evaluation Given the piecewise linear interpolation L(z) represented by the coefficient vectors a, b, how do we evaluate this function at z [α,β]? First, we locate [x i, x i+1 ] such that z [x i, x i+1 ]. Then, we evaluate L(z) using L i (z). Search method: binary search, since x i are sorted. Observation: If [x i, x i+1 ] is associated with the current z, then it is likely that this subinterval will be the one for the next value.

Algorithm. Locate Idea: Use the previous subinterval as a guess. If not, do binary search. Given the vector x of breakpoints and a scalar z between x 1 and x n, this function locates i so that x i z x i+1. The optional g is a guess. function i = Locate(x,z,g) if nargin==3 % try the guess if (x(g)<=z)&(z<=x(g+1)) i = g; return % quick return end end

Algorithm. Locate (cont.) n = length(x); if z==x(n) i = n-1; % quick return else % binary search left = 1; right = n; while right > left+1 mid = floor((left + right)/2); if z < x(mid) right = mid; else left = mid; end end i = left; end

Algorithm. pwleval Given a piecewise linear interpolation coefficient vectors a and b from pwl and its breakpoints in x, this function returns the values of the interpolation evaluated at the points in z. function v = pwleval(a,b,x,z) m = length(z); v = zeros(m,1); g = 1; for j=1:m i = Locate(x,z(j),g); v(j) = a(i) + b(i)*(z(j) - x(i)); g = i; end

Example y = 1 (x 0.3) 2 + 0.01 + 1 (x 0.9) 2 + 0.04 6 100 Interpolation of humps(x) with PWL, n = 10 80 60 40 20 0 0 0.5 1 1.5 2 2.5 3

Outline 1 Introduction 2 Polynomial Interpolation 3 Piecewise Polynomial Interpolation 4 Natural Cubic Spline 5 Software Packages

Problem setting Given (x 1, y 1 ),(x 2, y 2 ),...,(x n, y n ), find s(x): in each subinterval [x i, x i+1 ], s(x) is cubic

Problem setting Given (x 1, y 1 ),(x 2, y 2 ),...,(x n, y n ), find s(x): in each subinterval [x i, x i+1 ], s(x) is cubic s(x i ) = y i, i = 1,..., n

Problem setting Given (x 1, y 1 ),(x 2, y 2 ),...,(x n, y n ), find s(x): in each subinterval [x i, x i+1 ], s(x) is cubic s(x i ) = y i, i = 1,..., n s (x) and s (x) are continuous at x 2, x 3,..., x n 1

Problem setting Given (x 1, y 1 ),(x 2, y 2 ),...,(x n, y n ), find s(x): in each subinterval [x i, x i+1 ], s(x) is cubic s(x i ) = y i, i = 1,..., n s (x) and s (x) are continuous at x 2, x 3,..., x n 1 s (x 1 ) = s (x n ) = 0 The second derivative of s(x) is zero at the end points means that s(x) is linear at the end points.

A straightforward approach Suppose a i + b i x + c i x 2 + d i x 3 on [x i, x i+1 ], i = 1,..., n 1. 4(n 1) unknowns to be determined.

A straightforward approach Suppose a i + b i x + c i x 2 + d i x 3 on [x i, x i+1 ], i = 1,..., n 1. 4(n 1) unknowns to be determined. Interpolation: a i + b i x i + c i xi 2 + d i xi 3 = y i, i = 1,..., n 1 a i + b i x i+1 + c i xi+1 2 + d ixi+1 3 = y i+1, i = 1,..., n 1

A straightforward approach Suppose a i + b i x + c i x 2 + d i x 3 on [x i, x i+1 ], i = 1,..., n 1. 4(n 1) unknowns to be determined. Interpolation: a i + b i x i + c i xi 2 + d i xi 3 = y i, i = 1,..., n 1 a i + b i x i+1 + c i xi+1 2 + d ixi+1 3 = y i+1, i = 1,..., n 1 Continuous first derivative (consider [x i 1, x i ] and [x i, x i+1 ]): b i 1 + 2c i 1 x i + 3d i 1 xi 2 = b i + 2c i x i + 3d i xi 2, i = 2,..., n 1

A straightforward approach Suppose a i + b i x + c i x 2 + d i x 3 on [x i, x i+1 ], i = 1,..., n 1. 4(n 1) unknowns to be determined. Interpolation: a i + b i x i + c i xi 2 + d i xi 3 = y i, i = 1,..., n 1 a i + b i x i+1 + c i xi+1 2 + d ixi+1 3 = y i+1, i = 1,..., n 1 Continuous first derivative (consider [x i 1, x i ] and [x i, x i+1 ]): b i 1 + 2c i 1 x i + 3d i 1 xi 2 = b i + 2c i x i + 3d i xi 2, i = 2,..., n 1 Continuous second derivative: 2c i 1 + 6d i 1 x i = 2c i + 6d i x i, i = 2,..., n 1

A straightforward approach Suppose a i + b i x + c i x 2 + d i x 3 on [x i, x i+1 ], i = 1,..., n 1. 4(n 1) unknowns to be determined. Interpolation: a i + b i x i + c i xi 2 + d i xi 3 = y i, i = 1,..., n 1 a i + b i x i+1 + c i xi+1 2 + d ixi+1 3 = y i+1, i = 1,..., n 1 Continuous first derivative (consider [x i 1, x i ] and [x i, x i+1 ]): b i 1 + 2c i 1 x i + 3d i 1 xi 2 = b i + 2c i x i + 3d i xi 2, i = 2,..., n 1 Continuous second derivative: 2c i 1 + 6d i 1 x i = 2c i + 6d i x i, i = 2,..., n 1 Two end conditions: 2c 1 + 6d 1 x 1 = 0 and 2c n 1 + 6d n 1 x n = 0

A straightforward approach Suppose a i + b i x + c i x 2 + d i x 3 on [x i, x i+1 ], i = 1,..., n 1. 4(n 1) unknowns to be determined. Interpolation: a i + b i x i + c i xi 2 + d i xi 3 = y i, i = 1,..., n 1 a i + b i x i+1 + c i xi+1 2 + d ixi+1 3 = y i+1, i = 1,..., n 1 Continuous first derivative (consider [x i 1, x i ] and [x i, x i+1 ]): b i 1 + 2c i 1 x i + 3d i 1 xi 2 = b i + 2c i x i + 3d i xi 2, i = 2,..., n 1 Continuous second derivative: 2c i 1 + 6d i 1 x i = 2c i + 6d i x i, i = 2,..., n 1 Two end conditions: 2c 1 + 6d 1 x 1 = 0 and 2c n 1 + 6d n 1 x n = 0 Total of 4(n 1) equations, a dense system.

A clever approach: Constructing s(x) In the subinterval [x i, x i+1 ], let h i = x i+1 x i and introduce new variables: w = (x x i )/h i, w = 1 w. Note: w(x i ) = 0, w(x i+1 ) = 1 and w(x i ) = 1, w(x i+1 ) = 0, (linear Lagrange polynomials). Thus wy i+1 + wy i is the (linear) Lagrange interpolation on [x i, x i+1 ].

A clever approach: Constructing s(x) In the subinterval [x i, x i+1 ], let h i = x i+1 x i and introduce new variables: w = (x x i )/h i, w = 1 w. Note: w(x i ) = 0, w(x i+1 ) = 1 and w(x i ) = 1, w(x i+1 ) = 0, (linear Lagrange polynomials). Thus wy i+1 + wy i is the (linear) Lagrange interpolation on [x i, x i+1 ]. Construct s(x) = wy i+1 + wy i + h 2 i [(w 3 w)σ i+1 + ( w 3 w)σ i ] where σ i to be determined, so that the properties (the first and second derivatives are continuous) are satisfied.

Properties of s(x) Using w = 1/h i and w = 1/h i, we can verify 1 s(x i ) = y i, s(x i+1 ) = y i+1, independent of σ, that is, s(x) interpolates (x i, y i ). 2 s (x) = 6wσ i+1 + 6 wσ i, linear Lagrange interpolation at the points (x i, 6σ i ) and (x i+1, 6σ i+1 ). Clearly s (x i ) = 6σ i, which implies that s (x) is continuous.

Properties of s(x) Using w = 1/h i and w = 1/h i, we can verify 1 s(x i ) = y i, s(x i+1 ) = y i+1, independent of σ, that is, s(x) interpolates (x i, y i ). 2 s (x) = 6wσ i+1 + 6 wσ i, linear Lagrange interpolation at the points (x i, 6σ i ) and (x i+1, 6σ i+1 ). Clearly s (x i ) = 6σ i, which implies that s (x) is continuous. Is s (x) continuous?

Properties of s(x) (cont.) It remains to determine σ i so that s (x) is continuous.

Properties of s(x) (cont.) It remains to determine σ i so that s (x) is continuous. Consider, on [x i, x i+1 ], s (x) = y i+1 y i h i + h i [(3w 2 1)σ i+1 (3 w 2 1)σ i ] Let i = (y i+1 y i )/h i. On [x i, x i+1 ], w(x i ) = 0 and w(x i ) = 1, s +(x i ) = i + h i ( σ i+1 2σ i ).

Properties of s(x) (cont.) On [x i 1, x i ], s (x) = y i y i 1 h i 1 + h i 1 [(3w 2 1)σ i (3 w 2 1)σ i 1 ] and w(x i ) = 1, w(x i ) = 0. Thus s (x i) = i 1 + h i 1 (2σ i + σ i 1 ).

Making s (x) continuous Setting we get n 2 equations: s +(x i ) = s (x i ), i = 2, 3,..., n 1, h i 1 σ i 1 + 2(h i 1 + h i )σ i + h i σ i+1 = i i 1 for i = 2, 3,..., n 1. Solve for σ 2,...,σ n 1, recalling that σ 1 = σ n = 0 (natural cubic spline).

Matrix form diagonal: [2(h 1 + h 2 ),, 2(h n 2 + h n 1 )] supper/subdiagonal: [h 2,, h n 2 ] unknowns: [σ 2,,σ n 1 ] T right-hand side: [ 2 1,, n 1 n 2 ] T

Matrix form diagonal: [2(h 1 + h 2 ),, 2(h n 2 + h n 1 )] supper/subdiagonal: [h 2,, h n 2 ] unknowns: [σ 2,,σ n 1 ] T right-hand side: [ 2 1,, n 1 n 2 ] T The matrix is symmetric tridiagonal diagonally dominant ( a i,i > j i a i,j ), when x 1 < x 2 < < x n, postive definite Can apply the Cholesky factorization, working on two vectors with O(n) operations.

Modeling a problem Note. Had we taken the straightforward approach to determining the coefficients of the piecewise cubic polynomials, four coefficients for each of n 1 cubic polynomials, we would have ended up with a large (4(n 1) 4(n 1)) and dense system requiring O(n 3 ) operations. Now we have an O(n) method.

Evaluating s(x) If s(x) is evaluated many times, arrange s(x) so that s(x) = y i + b i (x x i ) + c i (x x i ) 2 + d i (x x i ) 3 and rearrange it in the Horner s form, for x i x x i+1 and calculate and store b i, c i, d i (instead of σ i ) b i = y i+1 y i h i h i (σ i+1 + 2σ i ) for i = 1, 2,..., n 1 c i = 3σ i d i = σ i+1 σ i h i

Algorithm. Natural cubic spline ncspline Given a vector x with breakpoints and vector y with function values, this algorithm computes the coefficients b, c, d of natural spline interpolation. 1 Compute h i and i ; 2 Form the tridiagonal matrix (two arrays) and the right hand side; 3 Solve for σ i ; 4 Compute the coefficients b, c, and d.

Outline 1 Introduction 2 Polynomial Interpolation 3 Piecewise Polynomial Interpolation 4 Natural Cubic Spline 5 Software Packages

Software packages IMSL csint, csdec, csher, csval MATLAB polyfit, spline, ppval NAG e01aef, e01baf, e01bef, e02bbf, e01bff Octave interp1

Summary Polynomial interpolation: General idea and methods, Lagrange interpolation Piecewise polynomial interpolation: Construction of piecewise polynomial (linear and cubic), evaluation of a piecewise function, ncspline, seval

References [1 ] George E. Forsyth and Michael A. Malcolm and Cleve B. Moler. Computer Methods for Mathematical Computations. Prentice-Hall, Inc., 1977. Ch 4.