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.

Slides:



Advertisements
Similar presentations
Numerical Integration
Advertisements

Environmental Data Analysis with MatLab Lecture 21: Interpolation.
Partial Differential Equations
Lecture 15 Orthogonal Functions Fourier Series. LGA mean daily temperature time series is there a global warming signal?
1 MA 1128: Lecture 19 – 4/19/11 Quadratic Formula Solving Equations with Graphs.
Numerical Methods.  Polynomial interpolation involves finding a polynomial of order n that passes through the n+1 points.  Several methods to obtain.
Interpolation A method of constructing a function that crosses through a discrete set of known data points. .
Solving Systems of Equations. Rule of Thumb: More equations than unknowns  system is unlikely to have a solution. Same number of equations as unknowns.
Spline Functions – An Elegant View of Interpolation Bruce Cohen David Sklar
Data mining and statistical learning - lecture 6
MATH 685/ CSI 700/ OR 682 Lecture Notes
Selected from presentations by Jim Ramsay, McGill University, Hongliang Fei, and Brian Quanz Basis Basics.
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.
Computational Methods in Physics PHYS 3437
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.
1Notes  Assignment 0 is due today!  To get better feel for splines, play with formulas in MATLAB!
Notes Assignment questions… cs533d-winter-2005.
1cs533d-term Notes  Assignment 2 is up. 2cs533d-term Modern FEM  Galerkin framework (the most common)  Find vector space of functions that.
1cs542g-term Notes  Make-up lecture tomorrow 1-2, room 204.
1cs542g-term Notes  Added required reading to web (numerical disasters)
Lecture 5 A Priori Information and Weighted Least Squared.
Infinite Sequences and Series
Curve-Fitting Interpolation
1cs426-winter-2008 Notes  Ian Mitchell is running a MATLAB tutorial, Tuesday January 15, 5pm-7pm, DMP 110 We won’t be directly using MATLAB in this course,
Lecture 3 Review of Linear Algebra Simple least-squares.
Engineering Computation Curve Fitting: Interpolation 1
Lecture 4: Practical Examples. Remember this? m est = m A + M [ d obs – Gm A ] where M = [G T C d -1 G + C m -1 ] -1 G T C d -1.
Curve-Fitting Polynomial Interpolation
Human Growth: From data to functions. Challenges to measuring growth We need repeated and regular access to subjects for up to 20 years. We need repeated.
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.
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
ECIV 301 Programming & Graphics Numerical Methods for Engineers Lecture 21 CURVE FITTING Chapter 18 Function Interpolation and Approximation.
Differential Equations and Boundary Value Problems
Finite element method 1 Finite Elements  Basic formulation  Basis functions  Stiffness matrix  Poisson‘s equation  Regular grid  Boundary conditions.
A quadratic equation is a second degree polynomial, usually written in general form: The a, b, and c terms are called the coefficients of the equation,
Human Growth: From data to functions. Challenges to measuring growth We need repeated and regular access to subjects for up to 20 years. We need repeated.
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)
Solving Systems of Equations. Rule of Thumb: More equations than unknowns  system is unlikely to have a solution. Same number of equations as unknowns.
Simpson Rule For Integration.
Curve Fitting and Interpolation: Lecture (I)
Curves.
1 Interpolation. 2 What is Interpolation ? Given (x 0,y 0 ), (x 1,y 1 ), …… (x n,y n ), find the value of ‘y’ at a.
Today’s class Spline Interpolation Quadratic Spline Cubic Spline Fourier Approximation Numerical Methods Lecture 21 Prof. Jinbo Bi CSE, UConn 1.
Interpolation and Approximation To the question, "Why approximate?", we can only answer, "Because we must!" Mathematical models of physical or natural.
1 Lecture 3: March 6, 2007 Topic: 1. Frequency-Sampling Methods (Part I)
6. Introduction to Spectral method. Finite difference method – approximate a function locally using lower order interpolating polynomials. Spectral method.
Numerical Methods.
CHAPTER 3 NUMERICAL METHODS
Lecture 22 Numerical Analysis. Chapter 5 Interpolation.
Polynomials, Curve Fitting and Interpolation. In this chapter will study Polynomials – functions of a special form that arise often in science and engineering.
Interactive Graphics Lecture 10: Slide 1 Interactive Computer Graphics Lecture 10 Introduction to Surface Construction.
Spline Interpolation A Primer on the Basics by Don Allen.
Application: Multiresolution Curves Jyun-Ming Chen Spring 2001.
 3.3 Hermite Interpolation Chapter 3 Interpolation and Polynomial Approximation -- Hermite Interpolation Find the osculating polynomial P(x) such that.
1 Chapter 4 Interpolation and Approximation Lagrange Interpolation The basic interpolation problem can be posed in one of two ways: The basic interpolation.
Interpolation - Introduction
Computational Methods CMSC/AMSC/MAPL 460 Polynomial Interpolation Ramani Duraiswami, Dept. of Computer Science.
Curve-Fitting Spline Interpolation
Interpolation.
Chapter 15 Curve Fitting : Splines
Numerical Analysis Lecture 26.
SKTN 2393 Numerical Methods for Nuclear Engineers
Presentation transcript:

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 something sensible in between

Lingo Splines – a broad class of ways of performing interpolation (we’ll get to the details, eventually)

Find a function f(x) that 1) goes through all your data points (observations) 2) does something sensible in between (prior information) Why not just use least-squares?

Remember this? m est = m A + M [ d obs – Gm A ] where M = [G T C d -1 G + C m -1 ] -1 G T C d -1

m – a vector of all the points at which you want to estimate the function, including the points for which you have observations d – a vector of just those points where you have observations So the equation Gm=d is very simple, a model parameter equals the data when the corresponding observation is available: … 0 … … 0 … …mi……mi… …dj……dj… = Just a single “1” per row

You then implement a smoothness constraint through minimizing |Dm| 2, where D is some measure of the non-smoothness of m Thus m A = 0 and C m -1 =  2 D T D and C d =I … 0 … … 0 … D = One possibility is to use the finite- difference approximation of the second derivative

First derivative [dm/dx] i  (1/  x) m i – m i-1  m i – m i-1 Second derivative [d 2 m/dx 2 ] i  [dm/dx] i+1 - [dm/dx] i = m i+1 – m i – m i + m i-1 = m i+1 – 2m i + m i-1

example 101 equally spaced along the x-axis So 101 values of the function f(x) 40 of these values measured (the data, d) the rest are unknown Two prior information minimize 2 nd derivative for interior 99 x’s minimize 1 st derivative at left and right x’s (nice to have the same number of priors as unknowns, but not required)

 = data result f(x) x

 can be chosen by trail and error but usually the result fairly insensitive to , as long as its small

 varying over six orders of magnitude log 10 (Total Error) log 10 (  ) x f(x)

A purist might say that this is not really interpolation, because the curve goes through the data only in the limit  but for small  ’s the error is extremely small

an aside Construct an equation F m = h as follows: G  D d  m = then note [F T F] -1 F T h = [G T G+  2 D T D] -1 G T d so if you want, you can just append  D to the bottom of G and solve by simple least-squares

solved via solved via [F T F] -1 F T h [G T G+  2 D T D] -1 G T d exactly the same!

another reason to work with F m = h G  D d  m = both G and D, and therefore F, too, are mostly zero (that is, they’re sparse matrices) very efficient algorithms are available for solving Fm=h in the least-squares sense when F is a sparse matrix (note G T G and D T D are not as sparse as G or D and [G T G and D T D] -1 is not sparse at all)

2D Example (here a sparse solver would really be useful, for the number of unknowns is very large)

21 unknowns 21  21=441 unknowns 44 observed data

Prior information:  2 f = d 2 f/dx 2 + d 2 f/dy 2 = 0 in interior of the box n  f = 0 on edges of box … a generalization of the 1D case

results

comparison

one limitation of this method is that it is discrete it only gives the unknown function at specific, prescribed values of x i one might prefer to have an analytic formula for the value of the function at any x

LINGO an analytic formula that gives the value of the function at any x is called an interpolant

high order polynomial something that sound like a good idea but isn’t even though an N-1 polynomal can computed to pass through any N points

example: 10 th order polynomial fit to 11 points Big swings not what we hoped for

solution simple function e.g. a low order polynomial that is valid in some interval near x i obviously, we need many such polynomials to over the whole x-axis This approach is called a spline

we’ve all used one already - linear splines x xixi x i+1 yiyi y i+1 y in this interval y(x) = y i + (y i+1 -y i )  (x-x i )/(x i+1 -x i )

cubic splines – somewhat more complicated but a lot nicer … x xixi x i+1 yiyi y i+1 y cubic a+bx+cx 2 +dx 3 in this interval a different cubic in this interval

counting up unknowns … x xixi x i+1 yiyi y i+1 y four coefficients a, b, c, d in every interval unknowns N data N-1 intervals 4 coefficients per interval 4(N-1)=4N-4 coefficients total=4N-4 unknowns constraints curve goes thru point at end of its interval 2(N-1)=2N-2 dy/dx match at interior points N-2 constraints d 2 y/dx 2 match at interior points N-2 constraints d 2 y/dx 2 =0 at end points 2 constraints total: 4N-4 constraints

formulating the cubic spline problem in an efficient manner f(x) with N observations (x i, f i ) let h i =  x i = x i+1 - x i and  f i = f i+1 -f i S i (x) are cubic polynomials, one for each interval

Let the 2 nd derivatives have values d 2 S i /dx 2 =y” i at the left hand end of its interval But since the second derivative is presumed continuous across intervals, d 2 S i /dx 2 =y” i+1 on the right hand side of its interval too. since S i (x) is a cubic, its second derivative is a linear function So within an interval d 2 S i /dx 2 varies linearly d 2 S i /dx 2 = y” i (x j+1 -x)/h j + y” i+1 (x-x j )/h j we’ll wind up solving for these y” i ’s

now integrate twice to get S i (x) d 2 S i /dx 2 = y” i (x j+1 -x)/h j + y” i+1 (x-x j )/h j S i (x) = y” i (x j+1 -x) 3 /(6h j ) + y” i+1 (x-x j ) 3 /(6h j ) + c i (x-x i ) + d i (x i+1 -x) where c i and d i are integration constants

now choose the integration constants c i and d i such that the the cubic goes through the data points. That is, S i (x i )=f i and S i (x i+1 )=f i+1 this leads to c i = f i+1 /h i – y” i+1 h i /6 d i = f i /h i – y” i h i /6

so S i (x) = y” i (x j+1 -x) 3 /(6h j ) + y” i+1 (x-x j ) 3 /(6h j ) + {f j+1 /h i – y” i+1 h i /6}(x-x i ) + {f i /h i – y” i h i /6}(x i+1 -x) where c i and d i are integration constants but we still haven’t implemented the continuity of dS/dx condition …

so we compute the derivative S’ i (x) = dS i /dx = y” i (x i+1 -x) 2 /(2h i ) + y” i+1 (x-x i ) 2 /(2h i ) + {f i+1 /h i – y” i+1 h i /6} - {f i /h i – y” i h i /6} = ½y” i (x i+1 -x) 2 h i + ½y” i+1 (x-x i ) 2 /h i +  f i+1 /h i – (y” i+1 -y” i )h i /6

now require the first derivative match across intervals: S i-1 ’(x i )=S i ’(x i ) this leads to an equation for the unknown y” i h i-1 y” i-1 + 2(h i +h i-1 )y” i + h i y” i+1 = b j with b j = 6  f i /h i – 6  f i-1 /h i-1

the equation for the unknown y” i h i-1 y” i-1 + 2(h i +h i-1 )y” i + h i y” i+1 = b i is just a matrix equation i=1: h 0 y” 0 + 2(h 1 +h 0 )y” 1 + h 1 y” 2 = b 1 i=2: h 1 y” 1 + 2(h 2 +h 1 )y” 2 + h 2 y” 2 = b 2 i=2: h 2 y” 2 + 2(h 3 +h 2 )y” 3 + h 3 y” 3 = b 3 … i=N-1 h N-2 y” N-2 + 2(h N-1 +h N-2 )y” N-1 + h N-1 y” N = b N-1 i=N h N-1 y” N-1 + 2(h N +h N-1 )y” N + h N y” N+1 = b N = we’ll discuss the issue raise by y” 0 and y” N+1 in a moment

the matrix equation, with g i =2(h i +h i-1 ), is h 0 g 1 h 1 h 1 g 2 h 2 h 2 g 3 h 3 … h N-2 g N-1 h N-1 h N-1 g N h N y” 0 y” 1 y” 2 y” 3 … y” N y” N+1 b 0 b 1 b 2 b 3 … b N b N+1 = A Tridiagonal Matrix, by the way. Very fast solvers are available …

the matrix equation, with g i =2(h i +h i-1 ), is h 0 g 1 h 1 h 1 g 2 h 2 h 2 g 3 h 3 … h N-2 g N-1 h N-1 h N-1 g N h N y” 0 y” 1 y” 2 y” 3 … y” N y” N+1 b 0 b 1 b 2 b 3 … b N b N+1 = I’ve written this as if there were two extra points, one to the left of the first point and one to the right of the last point. Of course, there aren’t. The way to handle this is to prescribe y” 0 and y” N+1 and move them to the r.h.s. of the equation. N N+2

moving over these two now-specified unknowns g 1 h 1 h 1 g 2 h 2 h 2 g 3 h 3 … h N-1 g N h N h N g N y” 1 y” 2 y” 3 … y” N b 1 – h 0 y” 0 b 2 b 3 … b N – h N+1 y” N+1 = we can set y” 0 and y” N to whatever we want. A simple choice is zero, in which case the splines are called natural cubic splines N N

example of cubic spline interpolation

very easy in MatLab new_y = spline(x,y,new_x);