Computational Methods in Physics PHYS 3437

Slides:



Advertisements
Similar presentations
Splines and Piecewise Interpolation
Advertisements

Lecture 10 Curves and Surfaces I
Computational Methods in Physics PHYS 3437
Chapter 3. Interpolation and Extrapolation Hui Pan, Yunfei Duan.
Computational Methods in Physics PHYS 3437
ICS 415 Computer Graphics Bézier Splines (Chapter 8)
CE33500 – Computational Methods in Civil Engineering Differentiation Provided by : Shahab Afshari
Spline Functions – An Elegant View of Interpolation Bruce Cohen David Sklar
MATH 685/ CSI 700/ OR 682 Lecture Notes
Basis Expansion and Regularization Presenter: Hongliang Fei Brian Quanz Brian Quanz Date: July 03, 2008.
Chapter 18 Interpolation The Islamic University of Gaza
1 Chapter 4 Interpolation and Approximation Lagrange Interpolation The basic interpolation problem can be posed in one of two ways: The basic interpolation.
1 Curve-Fitting Spline Interpolation. 2 Curve Fitting Regression Linear Regression Polynomial Regression Multiple Linear Regression Non-linear Regression.
EARS1160 – Numerical Methods notes by G. Houseman
ES 240: Scientific and Engineering Computation. InterpolationPolynomial  Definition –a function f(x) that can be written as a finite series of power functions.
Splines II – Interpolating Curves
Ch 5.2: Series Solutions Near an Ordinary Point, Part I
Curve-Fitting Interpolation
Engineering Computation Curve Fitting: Interpolation 1
Curve-Fitting Polynomial Interpolation
Revision.
ECIV 301 Programming & Graphics Numerical Methods for Engineers Lecture 23 CURVE FITTING Chapter 18 Function Interpolation and Approximation.
ECIV 301 Programming & Graphics Numerical Methods for Engineers Lecture 24 Regression Analysis-Chapter 17.
ECIV 301 Programming & Graphics Numerical Methods for Engineers REVIEW II.
Lecture 9 Interpolation and Splines. Lingo Interpolation – filling in gaps in data Find a function f(x) that 1) goes through all your data points 2) does.
Copyright © 2006 The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 1 Interpolation Chapter 18.
CSE Interpolation Roger Crawfis.
Chapter 6 Numerical Interpolation
CpE- 310B Engineering Computation and Simulation Dr. Manal Al-Bzoor
Computational Methods in Physics PHYS 3437 Dr Rob Thacker Dept of Astronomy & Physics (MM-301C)
Interpolation. Interpolation is important concept in numerical analysis. Quite often functions may not be available explicitly but only the values of.
Interactive Graphics Lecture 9: Slide 1 Interactive Graphics Lecture 9: Introduction to Spline Curves.
Simpson Rule For Integration.
Curve Fitting and Interpolation: Lecture (I)
V. Space Curves Types of curves Explicit Implicit Parametric.
Lecture 22 - Exam 2 Review CVEN 302 July 29, 2002.
Numerical Methods Part: Simpson Rule For Integration.
Today’s class Spline Interpolation Quadratic Spline Cubic Spline Fourier Approximation Numerical Methods Lecture 21 Prof. Jinbo Bi CSE, UConn 1.
6. Introduction to Spectral method. Finite difference method – approximate a function locally using lower order interpolating polynomials. Spectral method.
Computational Methods in Physics PHYS 3437 Dr Rob Thacker Dept of Astronomy & Physics (MM-301C)
Computational Methods in Physics PHYS 3437 Dr Rob Thacker Dept of Astronomy & Physics (MM-301C)
Numerical Methods.
CHAPTER 3 NUMERICAL METHODS
Lecture 22 Numerical Analysis. Chapter 5 Interpolation.
Lecture 16 - Approximation Methods CVEN 302 July 15, 2002.
Jump to first page Chapter 3 Splines Definition (3.1) : Given a function f defined on [a, b] and a set of numbers, a = x 0 < x 1 < x 2 < ……. < x n = b,
Introduction to Numerical Analysis I MATH/CMPSC 455 Splines.
CS 376 Introduction to Computer Graphics 04 / 25 / 2007 Instructor: Michael Eckmann.
Spline Interpolation A Primer on the Basics by Don Allen.
Principles of Extrapolation
 3.3 Hermite Interpolation Chapter 3 Interpolation and Polynomial Approximation -- Hermite Interpolation Find the osculating polynomial P(x) such that.
Maclaurin and Taylor Polynomials Objective: Improve on the local linear approximation for higher order polynomials.
Fourier Approximation Related Matters Concerning Fourier Series.
1 Chapter 4 Interpolation and Approximation Lagrange Interpolation The basic interpolation problem can be posed in one of two ways: The basic interpolation.
Real Zeros of Polynomial Functions
Copyright © Cengage Learning. All rights reserved Applications of Taylor Polynomials.
Interpolation - Introduction
Computational Methods CMSC/AMSC/MAPL 460 Polynomial Interpolation Ramani Duraiswami, Dept. of Computer Science.
NUMERICAL DIFFERENTIATION Forward Difference Formula
Curve-Fitting Spline Interpolation
Numerical Analysis Lecture 25.
Interpolation Estimation of intermediate values between precise data points. The most common method is: Although there is one and only one nth-order.
Chapter 18.
Interpolation.
Chapter 18.
Numerical Analysis Lecture 37.
5.3 Higher-Order Taylor Methods
Splines There are cases where polynomial interpolation is bad
SKTN 2393 Numerical Methods for Nuclear Engineers
Theory of Approximation: Interpolation
Presentation transcript:

Computational Methods in Physics PHYS 3437 Dr Rob Thacker Dept of Astronomy & Physics (MM-301C) thacker@ap.smu.ca

Today’s Lecture Interpolation & Approximation I Overview of ideas Interpolation vs fitting Polynomial interpolation Lagrange interpolation Hermite interpolation Cubic splines (introduction)

General idea of interpolation Suppose we are given data at discrete points only, and we wish to estimate values between these known points x1 x2 x3 x4 x5 f(x) X

Difference between interpolation & fitting Interpolation passes through each datum Fitting seeks to produce a curve that approximates the data x1 x2 x3 x4 x5 f(x)

Global versus piecewise interpolation We can fit a single polynomial of degree n to n+1 data points Alternatively we can use a series of polynomials to link points together – frequently called splines Splines will usually be cubic polynomials – I’ve used linear here to emphasize the piecewise nature x1 x2 x3 x4 x5 f(x)

Lagrange interpolation To fit a polynomial of degree n we need n+1 points Consider first interpolating between two points, f(x2),f(x3) using a function F(x) The Taylor expansion about a point x gives f(x2)=F(x)+(x2-x)F’(x)+… f(x3)=F(x)+(x3-x)F’(x)+… (I’ve highlighted what we know) If we use a polynomial of degree 1, p(x), then the Taylor series truncates after p’(x) f(x2)=p(x)+(x2-x)p’(x) --- (1) f(x3)=p(x)+(x3-x)p’(x) --- (2)

Eliminate p’(x) After a short derivation (ex) we find that eqns (1) and (2) give On varying the expansion point x, but keeping fixed end points x2,x3 this corresponds to a straightline – as expected (check the following for yourself): If x=x3 => p(x)=f(x3) If x=x2 => p(x)=f(x2) Linear fits aren’t that helpful though, and bringing in more points allows us to up the order of the interpolation

Quadratic fit using three points If we again Taylor expand put assume the function is a polymial, p(x) of degree 2, then f(x1)=p(x)+(x1-x)p’(x)+(x1-x)2p’’(x)/2 --- (3) f(x2)=p(x)+(x2-x)p’(x)+(x2-x)2p’’(x)/2 --- (4) f(x3)=p(x)+(x3-x)p’(x)+(x3-x)2p’’(x)/2 --- (5) With a bit more algebra (fairly lengthy) we can eliminate both p’(x) and p’’(x) using (3),(4),(5) to get You should see a pattern emerging here…

General (Lagrange) Polynomial fit If we have n points, a polynomial of degree n-1 can be constructed using the formula This is called the interpolation polynomial in Lagrange form, but it is frequently referred to as the Lagrange polynomial

Properties of the lj,n(x) The lj,n(x) are clearly polynomials, and a called basis polynomials since they sum to find the interpolating polynomial If we let x=xi in the formula (so that we are picking one of the interpolation points) then

Problems with polynomial interpolation As the number of points increases so does the degree of the polynomial This implies many turns and a lot of “structure” between interpolation points in high order polynomials High order polynomials will have a lot of “wiggles” and if points do not change smoothly they can “overshoot” in between datums Cubic fits tend to be about optimal 4 data points can surround x symmetrically (2 on each side) Increasing the number of points adds more data from further away from a given interpolation point This doesn’t necessarily improve the accuracy of the fit locally

Example of “wiggles” Piecewise linear fit 6th order polynomial fit From http://dmpeli.mcmaster.ca/Matlab/Math1J03/LectureNotes/Lecture3_3.htm

Segue - numerically implementing the general formula Implementing the general formula is not exactly trivial It helps to notice that the lj,n(x) can be written as a product One can then think about using a loop to do the multiplication of the terms in the product However, the best way to calculate large interpolation polynomials is to use Neville’s Algorithm

Segue - Neville’s Algorithm We won’t go into the details, however you can take a look (if you are interested) at Numerical Recipes section 3.1 Neville’s algorithm is better because it builds up the interpolation polynomial in a recursive fashion It uses a similar table idea to building up coefficients in a binomial expansion The employed recursion cuts down the total number of operations required and helps reduce concerns about rounding error

Hermite Interpolation If we have both the function value, and the derivative we can fully constrain a higher order polynomial through two points f(x) f(x2) & f’(x2) f(x1) & f’(x1) x1 x x2 (x1<x<x2)

Interpolating a cubic to two points Given the general form for a cubic So we have 4 equations with 4 unknowns to solve.

Solve for p(x) While again somewhat lengthy, we can solve for p(x) in terms of the known values (subscript denotes for x1,x2) One important property of Hermite interpolation is that if we fit a different polynomial p2,3(x) between x2 & x3 then it will have the same derivative at x2 as p1,2(x2) i.e. p’1,2(x2)=p’2,3(x2) Interpolation between successive pairs of points is continuous The derivatives are also continuous Hermite interpolation is thus considered to be smooth

Diagram of two Hermite interpolation polynomials Second polynomial fit p2,3(x) First polynomial fit p1,2(x) f(x) f(x3) & f’(x3) f(x1) & f’(x1) f(x2) & f’(x2) Derivatives match at x2 x1 x2 x3

Advantages of Hermite interpolation over Lagrange interpolation A series of H.I. polynomials will be continuous at the datums, as will the derivatives (i.e. smooth) While a series of L.I. polynomials is continuous at the datums the derivatives will not be continuous H.I. can fit a cubic to `local’ data (i.e. x1<x<x2) L.I. requires four points to fit a cubic (x1<x2<x<x3<x4) However, even if we don’t have derivatives it would be nice to fit a series of polynomials with continuous slopes at each datum

Cubic Splines Let’s examine how we can create a series of cubic polynomials with equal derivatives at the datums Choose x, such that xj<x<xj+1 where j=1,…,n Around x, we may write p(x) as

Next consider derivatives We just derived two equations (3) & (2) for the value of the cubic fit at xj and xj+1 Taking the first & second derivative of p(x) we find If we again equate at xj and xj+1 but using 2nd deriv:

Next find the cj We’ve just shown

Substitute back to get p(x) We now substitute (2),(4),(5) and (6) back into our first equation for p(x) to get To get any further we now need some information about p’’j+1 and p’’j

Setting p´´j+1 and p´´j f(x) f(x3) f(x1) f(x2) x1 x2 x3 We have no information about the derivative of f(x) though We just have the series of f(x) values What requirements can we impose? Recall we want the derivatives of neighbouring polynomials to match at the datums (xj) f(x) f(x3) f(x1) f(x2) Derivatives match at x2 x1 x2 x3

Apply continuity in the derivative We now have to consider adjacent polynomials Label: pj,j+1 to be the fit between xj and xj+1 pj-1,j to be the fit between xj-1 and xj Continuity of the derivative implies that p´j,j+1 and p´j-1,j should be equal at xj, the general p’ forms are:

Equate at xj Setting p´j,j+1(xj)=p´j-1,j(xj) the first few terms of (8) vanish, while terms in (x-xj-1) in (9) cancel with hj-1: Where j=2,3,…,n-1

Finding the p´´j values We now have a system of n-2 equations Recall limits of j=2,3,…,n-1 There are n unknown values though The p’’j values range through j=1,…,n To have enough information to solve for all the values we have to provide information about the end points – two cases Specify derivatives at end points “Clamped spline” Set p’’1=0 and p’’n=0 “Natural spline”

Summary Interpolation shouldn’t be confused with fitting, although the terms are frequently used interchangeably Lagrange interpolation will fit an order n polynomial to n+1 data points Hermite interpolation uses derivatives to solve for a cubic fit with only 2 datums Cubic spline interpolation gives a smooth piecewise interpolation scheme but requires conditions to be set for the end points

Next Lecture Matrix forms for spline fits Tridiagonal solvers Clamped spline Natural spline Tridiagonal solvers