Fitting a Natural Spline to Samples of the Form (t, f(t))

Similar documents
The Laplace Expansion Theorem: Computing the Determinants and Inverses of Matrices

A Relationship Between Minimum Bending Energy and Degree Elevation for Bézier Curves

Distance Between Ellipses in 2D

Least-Squares Fitting of Data with Polynomials

Perspective Projection of an Ellipse

Solving Systems of Polynomial Equations

Reconstructing an Ellipsoid from its Perspective Projection onto a Plane

Information About Ellipses

Interpolation of Rigid Motions in 3D

Intersection of Ellipsoids

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

Intersection of Rectangle and Ellipse

Distance from Line to Rectangle in 3D

Cubic Splines; Bézier Curves

Intersection of Objects with Linear and Angular Velocities using Oriented Bounding Boxes

1 Piecewise Cubic Interpolation

MA 323 Geometric Modelling Course Notes: Day 07 Parabolic Arcs

Intersection of Infinite Cylinders

SPLINE INTERPOLATION

Matrix Basic Concepts

Learning Module 1 - Basic Algebra Review (Appendix A)

Moving Along a Curve with Specified Speed

Converting Between Coordinate Systems

Intersection of Ellipses

Low-Degree Polynomial Roots

College Algebra. Course Text. Course Description. Course Objectives. StraighterLine MAT101: College Algebra

Chapter 7. Tridiagonal linear systems. Solving tridiagonal systems of equations. and subdiagonal. E.g. a 21 a 22 a A =

Piecewise Polynomial Interpolation

Computing Orthonormal Sets in 2D, 3D, and 4D

Global polynomial interpolants suffer from the Runge Phenomenon if the data sites (nodes) are not chosen correctly.

Numerical Analysis Fall. Gauss Elimination

Lecture 1 INF-MAT : Chapter 2. Examples of Linear Systems

MTH5112 Linear Algebra I MTH5212 Applied Linear Algebra (2017/2018)

Question: Given an n x n matrix A, how do we find its eigenvalues? Idea: Suppose c is an eigenvalue of A, then what is the determinant of A-cI?

Linear Algebra Practice Problems

Linear Algebra I Lecture 8

Notes on Row Reduction

1 - Systems of Linear Equations

and let s calculate the image of some vectors under the transformation T.

Eigenvalues and Eigenvectors: An Introduction

Empirical Models Interpolation Polynomial Models

An overview of key ideas

LECTURES 4/5: SYSTEMS OF LINEAR EQUATIONS

Math 4377/6308 Advanced Linear Algebra

Distance to Circles in 3D

Polyhedral Mass Properties (Revisited)

Elementary maths for GMT

Algebra 2 Matrices. Multiple Choice Identify the choice that best completes the statement or answers the question. 1. Find.

Lecture 12: Solving Systems of Linear Equations by Gaussian Elimination

Something that can have different values at different times. A variable is usually represented by a letter in algebraic expressions.

The Area of Intersecting Ellipses

Quaternion Algebra and Calculus

Least Squares Fitting of Data by Linear or Quadratic Structures

Linear Algebra Section 2.6 : LU Decomposition Section 2.7 : Permutations and transposes Wednesday, February 13th Math 301 Week #4

How to (Almost) Square a Circle

Calculating determinants for larger matrices

Eigenvalue and Eigenvector Homework

An Approximation for the Inverse Square Root Function

Principal Curvatures of Surfaces

Distance from a Point to an Ellipse, an Ellipsoid, or a Hyperellipsoid

MA 138 Calculus 2 with Life Science Applications Matrices (Section 9.2)

System of Linear Equations

Dynamic Collision Detection using Oriented Bounding Boxes

Definition of Equality of Matrices. Example 1: Equality of Matrices. Consider the four matrices

Linear Algebra and Matrix Inversion

Chapter 4 Systems of Linear Equations; Matrices

GEOMETRY OF MATRICES x 1

B-Spline Interpolation on Lattices

Elementary Matrices. MATH 322, Linear Algebra I. J. Robert Buchanan. Spring Department of Mathematics

Lecture 1 Systems of Linear Equations and Matrices

Three-Dimensional Coordinate Systems. Three-Dimensional Coordinate Systems. Three-Dimensional Coordinate Systems. Three-Dimensional Coordinate Systems

A Review of Matrix Analysis

chapter 12 MORE MATRIX ALGEBRA 12.1 Systems of Linear Equations GOALS

Math 1314 Week #14 Notes

Lecture 1 INF-MAT3350/ : Some Tridiagonal Matrix Problems

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

Check boxes of Edited Copy of Sp Topics (was 261-pilot)

Lesson U2.1 Study Guide

Solving Consistent Linear Systems

LINEAR SYSTEMS, MATRICES, AND VECTORS

7.5 Operations with Matrices. Copyright Cengage Learning. All rights reserved.

Hani Mehrpouyan, California State University, Bakersfield. Signals and Systems

(Linear equations) Applied Linear Algebra in Geoscience Using MATLAB

Applied Linear Algebra in Geoscience Using MATLAB

ANALYTICAL MATHEMATICS FOR APPLICATIONS 2018 LECTURE NOTES 3

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

Derivation of the Kalman Filter

The Essentials of CAGD

Linear Algebra. The analysis of many models in the social sciences reduces to the study of systems of equations.

CS123 INTRODUCTION TO COMPUTER GRAPHICS. Linear Algebra 1/33

MATH10212 Linear Algebra B Homework Week 5

Math Matrix Theory - Spring 2012

Finish section 3.6 on Determinants and connections to matrix inverses. Use last week's notes. Then if we have time on Tuesday, begin:

Lecture 1: Systems of linear equations and their solutions

Matrix notation. A nm : n m : size of the matrix. m : no of columns, n: no of rows. Row matrix n=1 [b 1, b 2, b 3,. b m ] Column matrix m=1

x n -2.5 Definition A list is a list of objects, where multiplicity is allowed, and order matters. For example, as lists

A FIRST COURSE IN LINEAR ALGEBRA. An Open Text by Ken Kuttler. Matrix Arithmetic

Physics 6303 Lecture 3 August 27, 2018

LS.1 Review of Linear Algebra

Conceptual Questions for Review

Transcription:

Fitting a Natural Spline to Samples of the Form (t, f(t)) David Eberly, Geometric Tools, Redmond WA 9852 https://wwwgeometrictoolscom/ This work is licensed under the Creative Commons Attribution 4 International License To view a copy of this license, visit http://creativecommonsorg/licenses/by/4/ or send a letter to Creative Commons, PO Box 1866, Mountain View, CA 9442, USA Created: January 5, 28 Last Modified: January 5, 215 Contents 1 Introduction 2 11 Constraints for Free Splines 2 12 Constraints for Clamped Splines 3 13 Constraints for Periodic Splines 3 2 Constructing Free Splines 3 3 Constructing Clamped Splines 5 4 Constructing Periodic Splines 6 41 Three Samples 6 42 Four Samples 7 43 The General Case 9 1

1 Introduction Consider a function f : D IR m, whose domain is D = [t min, t max ] and whose range consists of m-tuples with m 1 The only information we have about the function is a set of samples, {(t i, f i )} n i=, f i = f(t i ) and t min t < t 1 < < t n < t n t max We want to fit the function with a piecewise cubic polynomial spline S (t), t [t, t 1 ] S 1 (t), t [t 1, t 2 ] S(t) = S n 2 (t), t [t n 2, t n ] S n (t), t [t n, t n ] S i (t) = a i + b i (t t i ) + c i (t t i ) 2 + d i (t t i ) 3 (2) for i n 1 Moreover, we want S(t) to be a C 2 function; that is, S(t), S (t), and S (t) must be continuous functions of t on the interval [t, t n ] Each of S i (t) is a C 2 function on the open interval (t i, t i+1 ), so the only points of concern to be C 2 every are the sample points We have n polynomials to determine, each having 4 unknown coefficients Thus, we have 4n unknowns Imposing the C 2 condition leads to linear constraints on the unknowns We need the polynomials, their first derivatives, and their second derivatives to match at the sample points t 1 through t n Specifically, S i (t i+1 ) = S i+1 (t i ), S i(t i+1 ) = S i+1(t i ), S i (t i+1 ) = S i+1(t i ), i n 2 (3) This is a set of 3(n 1) constraints on the unknowns We also need the polynomials to pass through the sample points, so S i (t i ) = f i, i n 1, and S n (t n ) = f n (4) This is a set of n + 1 constraints on the unknowns Equations (3) and (4) represent 4n 2 constraints on the 4n unknowns We have two degrees of freedom Three standard choices are the following (1) 11 Constraints for Free Splines We may allow the endpoints to have whatever slope necessary by specifying the second derivatives at those points to be zero: S (t ) =, S n(t n ) = (5) The resulting curve is said to be a free spline These two constraints and the previously mentioned ones give us 4n linear equations in 4n unknowns; that is, the coefficients of the cubic polynomials are obtained by solving a linear system of equations It turns out that the system is tridiagonal, so a specialized linear solver may be used that is O(n) General linear solvers are O(n 3 ), so the specialized solver saves computational time for a large number of sample points 2

12 Constraints for Clamped Splines We may clamp the endpoints in the sense that we specify the first derivatives at those points: S (t ) = σ, S n(t n ) = σ 1 (6) for user-specified constants σ and σ 1 The resulting curve is said to be a clamped spline These two constraints and the previously mentioned ones give us 4n linear equations in 4n unknowns As for the case of free splines, the linear system is tridiagonal and may be solved by a specialized linear solver 13 Constraints for Periodic Splines We may require that the first and last samples have the same function values, namely, that f n = f Moreover, the C 2 condition requires us to impose the derivative equality constraints S (t ) = S n(t n ), S (t ) = S n(t n ) (7) The resulting curve is said to be a periodic spline These two constraints and the previously mentioned ones produce a system of 4n linear equations in 4n unknowns, but this system is not tridiagonal However, the system may be solved by a specialized linear solver that is O(n) 2 Constructing Free Splines This section describes how to set up and solve the tridiagonal linear system of equations for the polynomial coefficients when the endpoints are required to have zero second-order derivatives The ratio of differences of function values and time values occurs often in the derivation, so let us first define q i = f i+1 f i i (8) Define i = t i+1 t i for all relevant i The conditions S i (t i+1 ) = S i+1 (t i ) and S i (t i ) = f i are equivalent to The conditions S i (t i+1) = S i+1 (t i) are equivalent to The conditions S i (t i+1) = S i+1 (t i) are equivalent to i b i + 2 i c i + 3 i d i = f i+1 f i (9) 2 i c i + 3 2 i d i = b i+1 b i (1) 3 i d i = c i+1 c i (11) Substitute Equation (11) into Equations (9) and (1) to obtain ( ) i b i + 2 ci+1 + 2c i i = f i+1 f i (12) 3 and i (c i+1 + c i ) = b i+1 b i (13) 3

Increment the index in Equation (12) to obtain ( ) i+1 b i+1 + 2 ci+2 + 2c i+1 i+1 = f i+2 f i+1 (14) 3 Compute i times Equation (14) and subtract from it i+1 times Equation (12) to obtain ( ) i i+1 (b i+1 b i ) + i 2 ci+2+2c i+1 i+1 3 i+1 2 i = i (f i+2 f i+1 ) i+1 (f i+1 f i ) ( ) ci+1+2c i 3 (15) Substitute Equation (13) into Equation (15), collect terms, and divide by i i+1 to obtain i+1 c i+2 + 2( i+1 + i )c i+1 + i c i = 3(q i+1 q i ) (16) which is defined for i n 3 We know that the constraint S (t ) = in Equation (5) implies c = The constraint S n(t n ) in Equation (5) implies n c n + 3 2 nd n = If we define c n =, this constraint fits into the construction here and Equation (16) also holds for i = n 2 Essentially, we are thinking of the spline curve having one additional segment S n (t) = f n + b n (t t n ), a line segment, so that c n = d n = Equation (16) and boundary conditions c = c n = may be solved by setting up a linear system Mc = p (17) the (n 1) (n 1) matrix M is tridiagonal, symmetric, and diagonally dominant: 2( + 1 ) 1 1 2( 1 + 2 ) 2 2 2( 2 + 3 ) 3 M = n 4 2( n 4 + n 3 ) n 3 n 3 2( n 3 + n 2 ) n 2 n 2 2( n 2 + n ) (18) The (n 1) 1 column vector c has components c 1 through c n and the (n 1) 1 column vector p has components p 1 through p n p i = 3(q i q i ) (19) The matrix M and vector p may be computed and then used as input to a linear system solver that is specialized for tridiagonal systems The solver computes c 1 through c n, and we already know that c = The d-terms are computed from Equation (11), d i = c i+1 c i 3 i (2) and the b-terms are computed from Equation (12), b i = q i i ( ci+1 + 2c i 3 ) (21) The a-terms are already known, a i = f i (22) 4

3 Constructing Clamped Splines This section describes how to set up and solve the tridiagonal linear system of equations for the polynomial coefficients when the endpoints are required to have user-specified first-order derivatives Multiply Equation (9) by 3/ i and subtract from it Equation (1) to obtain Increment the index in Equation (23) to obtain 3b i + i c i = 3q i (b i+1 b i ) (23) 3b i+1 + i+1 c i+1 = 3q i+1 (b i+2 b i+1 ) (24) Multiply Equation (23) by i+1, multiply Equation (24) by i and add the two together to obtain 3( i+1 b i + i b i+1 ) + i+1 i (c i+1 + c i ) = 3( i+1 q i + i q i+1 ) i+1 (b i+1 b i ) i (b i+2 b i+1 ) (25) In the left-hand side of Equation (25), substitute Equation (13) to eliminate the c-terms Some algebra simplifies this to i b i+1 + 2( i + i+1 )b i+1 + i+1 b i = 3( i+1 q i + i q i+1 ) (26) which is defined for i n 3 We know that the constraint S (t ) = σ in Equation (6) implies b = σ The constraint S n(t n ) = σ 1 in Equation (6) implies n b n +2 2 nc n +3 3 nd n = σ 1 If we define b n = σ 1, this constraint fits into the construction here and Equation (26) also holds for i = n 2 Essentially, we are thinking of the spline curve having one additional segment S n (t) = f n + b n (t t n ) + c n (t t n ) 2, a parabolic arc, so that 2c n = 2 n c n + 6 2 nd n and d n = Equation (26) and boundary conditions b = σ and b n = σ 1 may be solved by setting up a linear system Nb = r (27) the (n 1) (n 1) matrix N is tridiagonal, symmetric, and diagonally dominant: 2( + 1 ) 2 2( 1 + 2 ) 1 3 2( 2 + 3 ) 2 N = n 3 2( n 4 + n 3 ) n 4 n 2 2( n 3 + n 2 ) n 3 n 2( n 2 + n ) (28) The (n 1) 1 column vector b has components b 1 through b n and the (n 1) 1 column vector r has components r 1 through r n r 1 = 3( 1 q + q 1 ) 1 σ r i = 3( i q i + i q i ), 2 i n 2 (29) r n = 3( n q n 2 + n 2 q n ) n 2 σ 1 The matrix N and vector r may be computed and then used as input to a linear system solver that is specialized for tridiagonal systems The solver computes b 1 through b n The c-terms are computed from Equation (23), c i = 3q i b i+1 2b i i (3) 5

and the d-terms are computed from Equation (1), d i = b i+1 b i 2 i c i 3 2 i (31) The a-terms are already known, a i = f i (32) 4 Constructing Periodic Splines This section describes how to set up and solve the linear system of equations for the polynomial coefficients when the endpoints are required to have the same function value, same first-order derivative, and same second-order derivative 41 Three Samples Consider the simplest case of three samples: (t, f ), (t 1, f 1 ), and (t 2, f ) The two cubic polynomials are S (t) = a + b (t t ) + c (t t ) 2 + d (t t ) 3 and S 1 (t) = a 1 + b 1 (t t 1 ) + c 1 (t t 1 ) 2 + d 1 (t t 1 ) 3 The eight constraints are f = S (t ) = S 1 (t 2 ) S (t ) = S 1(t 2 ) S (t ) = S 1 (t 2 ) f 1 = S (t 1 ) = S 1 (t 1 ) S (t 1 ) = S 1(t 1 ) S (t 1 ) = S 1 (t 1 ) Define = t 1 t and 1 = t 2 t 1 In terms of the polynomial coefficients, the constraints are (33) a + b + c 2 + d 3 = a 1 = f 1 b + 2c + 3d 2 = b 1 2c + 6d = 2c 1 a 1 + b 1 1 + c 1 2 1 + d 1 3 1 = a = f b 1 + 2c 1 1 + 3d 1 2 1 = b (34) 2c 1 + 6d 1 1 = 2c The linear system of equations is 1 1 2 3 1 2 3 2 1 3 1 1 1 2 1 3 1 1 2 1 3 2 1 1 3 1 a b c d a 1 b 1 c 1 d 1 = f f 1 (35) 6

In block matrix form, M L K = f U (36) L M 1 K 1 f 1 U 1 1 M i = i 2 i 3 i 1 1 2 i 3 2, L =, K i = i 1 1 3 1 Notice that M i is invertible a i b i c i d i 1, U = The linear system may be solved by row-reducing the augmented block matrix as shown next The matrix I is the 4 4 identity matrix M L f U I M f M L M 1 f 1 U L M 1 f 1 U (37) I I M L f M U M 1 LM L (f 1I + f LM )U M L f M U I (M 1 LM L) (f 1 I + f LM )U I [f M + M 1 LM (f 1 I + f LM I (M 1 LM (f 1 I + f LM (38) = I K I K 1 K 1 = (M 1 LM L) (f 1 I + f LM ), K = f M U + M LK 1 (39) 42 Four Samples Similar to the case of three samples, the constraints may be formulated as a block-matrix system, M L K f U M 1 L K 1 = f 1 U L M 2 K 2 f 2 U (4) 7

The linear system may be solved by row-reducing the augmented block matrix, M L f U M 1 L f 1U L M 2 f 2U I M L fm U I M 1 L f1m1 L M 2 f 2U I M L fm U I M 1 L f1m1 U LM L M2 (f2i + flm )U I M L fm U I M 1 L f1m1 M 2 LM LM1 L [f2i + LM (fi + f1lm1 I M L fm U I M 1 L f1m1 I K 2 (41) K 2 = (M 2 LM LM1 L) [f 2 I + LM (f I + f 1 LM1 )]U (42) Back substitution may now be used to compute K and K 1 The first back substitution is I M L f M U I M L f M U I M 1 L f 1M1 U I K 1 I K 2 I K 2 (43) K 1 = f 1 M 1 U + M 1 LK 2 (44) The second back substitution is I M M I K I K 1 I K 1 I K 2 I K 2 (45) K = f M U + M LK 1 (46) Equations (46), (44), and (42) are the polynomial coefficients for the spline 8

43 The General Case In general, the constraints may be formulated as a block-matrix system, M L K M 1 L K 1 M n 2 L L M n K n = f U f 1 U f n U (47) whose solution is obtained by row reducing the augmented block matrix M L f U M 1 L f 1 U M n 2 L f n 2 U L M n f n U (48) Inverting the M i matrices in the first n 1 block rows leads to I M L f M U I M1 L f 1M1 U I Mn 2 L f n 2Mn 2 U L M n f n U Forward elimination by the first n 1 block rows leads to I M L f M U I M1 L f 1M1 U I Mn 2 L f n 2Mn 2 U P Q (49) (5) and Q = [ f n I + f LM + f 1 LM = f n U + LM P = M n ( LM LM1 LMn 2) L (51) ( LM1 + + f n 2 LM LM1 LMn 2)] U [ f U + LM1 (f 1 U + ) ] (52) 9

The last expression shows that Q may be computed efficiently in a nested manner Inverting P in the last row of the reduced augmented block matrix, I M L f M U I M1 L f 1M1 U I Mn 2 L f n 2Mn 2 U I K n (53) K n = P Q (54) Back substitution may be applied n 1 times to solve for the other coefficients Generally, these are K i = f i M i U + M i LK i+1, n 2 i (55) In the calculations, we need the inverses of the M i matrices These are 1 3 3 M i = i i 2 i 3 3 3 2 i 2 i i 2 3 i 1 3 i 2 i 1 i (56) 1