Curve Fitting: Splines

Slides:



Advertisements
Similar presentations
Splines and Piecewise Interpolation
Advertisements

Mark Trew CT Halfway Down Halfway down the stairs Is a stair Where I sit. There isn't any Other stair Quite like It. I'm not at the bottom, I'm.
Numerical Methods.  Polynomial interpolation involves finding a polynomial of order n that passes through the n+1 points.  Several methods to obtain.
CS 445/645 Fall 2001 Hermite and Bézier Splines. Specifying Curves Control Points –A set of points that influence the curve’s shape Knots –Control points.
Engineering Analysis ENG 3420 Fall 2009 Dan C. Marinescu Office: HEC 439 B Office hours: Tu-Th 11:00-12:00.
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.
Dr. S.M. Malaek Assistant: M. Younesi
CITS2401 Computer Analysis & Visualisation
Computational Methods in Physics PHYS 3437
EARS1160 – Numerical Methods notes by G. Houseman
Slide 127 October 1999CS Computer Graphics (Top Changwatchai) Review of Spline Concepts Sections 10-6 to in Hearn & Baker Splines can be 2D.
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
Curve-Fitting Interpolation
Spline Interpretation ABC Introduction and outline Based mostly on Wikipedia.
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,
Engineering Computation Curve Fitting: Interpolation 1
Spline Interpretation ABC Introduction and outline Based mostly on Wikipedia.
ECIV 301 Programming & Graphics Numerical Methods for Engineers Lecture 22 CURVE FITTING Chapter 18 Function Interpolation and Approximation.
Copyright © 2006 The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Chapter 181 Interpolation Chapter 18 Estimation of intermediate.
Modelling: Curves Week 11, Wed Mar 23
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.
Chapter 6 Numerical Interpolation
CMPS1371 Introduction to Computing for Engineers NUMERICAL METHODS.
Scientific Computing Linear and Quadratic Splines.
V. Space Curves Types of curves Explicit Implicit Parametric.
Regression analysis Control of built engineering objects, comparing to the plan Surveying observations – position of points Linear regression Regression.
Curves.
CISE301_Topic41 CISE301: Numerical Methods Topic 4: Least Squares Curve Fitting Lectures 18-19: KFUPM Read Chapter 17 of the textbook.
1 Dr. Scott Schaefer Coons Patches and Gregory Patches.
Today’s class Spline Interpolation Quadratic Spline Cubic Spline Fourier Approximation Numerical Methods Lecture 21 Prof. Jinbo Bi CSE, UConn 1.
Polynomial Interpolation You will frequently have occasions to estimate intermediate values between precise data points. The function you use to interpolate.
Quadratic Surfaces. SPLINE REPRESENTATIONS a spline is a flexible strip used to produce a smooth curve through a designated set of points. We.
Splines and applications
Curves. First of all… You may ask yourselves “What did those papers have to do with computer graphics?” –Valid question Answer: I thought they were cool,
Computers in Civil Engineering 53:081 Spring 2003 Lecture #15 Spline Interpolation.
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,
Mohiuddin Ahmad SUNG-BONG JANG Interpolation II (8.4 SPLINE INTERPOLATION) (8.5 MATLAB’s INTERPOLATION Functions)
L5 – Curves in GIS NGEN06 & TEK230: Algorithms in Geographical Information Systems by: Sadegh Jamali (source: Lecture notes in GIS, Lars Harrie) 1 L5-
Spline Interpolation A Primer on the Basics by Don Allen.
 3.3 Hermite Interpolation Chapter 3 Interpolation and Polynomial Approximation -- Hermite Interpolation Find the osculating polynomial P(x) such that.
Engineering Analysis ENG 3420 Fall 2009 Dan C. Marinescu Office: HEC 439 B Office hours: Tu-Th 11:00-12:00.
By: Mark Coose Joetta Swift Micah Weiss. What Problems Can Interpolation Solve? Given a table of values, find a simple function that passes through the.
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 1 Part 4 Chapter 17 and 18 Interpolation.
Interpolation - Introduction
Lecture 29: Modeling Data. Data Modeling Interpolate between data points, using either linear or cubic spline models Model a set of data points as a polynomial.
Computational Methods CMSC/AMSC/MAPL 460 Polynomial Interpolation Ramani Duraiswami, Dept. of Computer Science.
EEE 244-7: Curve Fitting.
Chapter 10-2: Curves.
Curve-Fitting Spline Interpolation
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 Methods
Chapter 15 Curve Fitting : Splines
Chapter 18.
Spline Interpolation Class XVII.
Splines and Piecewise Interpolation
Interpolation Methods
Coons Patches and Gregory Patches
MATH 174: Numerical Analysis I
Splines There are cases where polynomial interpolation is bad
INTERPOLATION For both irregulary spaced and evenly spaced data.
SKTN 2393 Numerical Methods for Nuclear Engineers
Theory of Approximation: Interpolation
Presentation transcript:

Curve Fitting: Splines Chapter 16 Curve Fitting: Splines

Spline Interpolation There are cases where polynomial interpolation is bad Noisy data Sharp Corners (slope discontinuity) Humped or Flat data Overshoot Oscillations

Example: f(x) = sqrt(abs(x)) Interpolation at 4, 3, 2, 1, 0, 1, 2, 3, 4

Spline Interpolation Cubic interpolation 7th-order 5th-order Linear spline

Spline Interpolation Idea behind splines Use lower order polynomials to connect subsets of data points Make connections between adjacent splines smooth Lower order polynomials avoid oscillations and overshoots

Spline Interpolation Use “piecewise” polynomials instead of a single polynomial Spline -- a thin, flexible metal or wooden lath Bent the lath around pegs at the required points Spline curves -- curves of minimum strain energy Piecewise Linear Interpolation Piecewise Quadratic Interpolation Piecewise Cubic Interpolation (cubic splines)

Zero curvatures at end points Drafting Spline Continuous function and derivatives Zero curvatures at end points

Splines There are n-1 intervals and n data points si(x) is a piecewise low-order polynomial

Spline fits of a set of 4 points

Example: Ship Lines waterline

Bow Stern

Spline interpolation for submerged hull (below waterline) Original database Spline interpolation for submerged hull (below waterline)

Linear Splines b is the slope between points Connect each two points with straight line functions connecting each pair of points b is the slope between points

Linear Splines si (x) = ai + bi (x  xi) x1 x2 x3 x4

Identical to Lagrange interpolating polynomials Linear Splines Identical to Lagrange interpolating polynomials

Linear splines Connect each two points with straight line Functions connecting each pair of points are slope

Linear splines are exactly the same as linear interpolation! Example:

Linear Splines Problem with linear splines -- not smooth at data points (or knots) First derivative (slope) is not continuous Use higher-order splines to get continuous derivatives Equate derivatives at neighboring splines Continuous functional values and derivatives

Quadratic Splines Quadratic splines - continuous first derivatives May have discontinuous second and higher derivatives Derive second order polynomial between each pair of points For n points (i=1,…,n): (n-1) intervals & 3(n-1) unknown parameters (a’s, b’s, and c’s) Need 3(n-1) equations

Quadratic Splines 3(n-1) unknowns si(x) = ai + bi (xxi) + ci(xxi)2 f(x5) s2 (x) f(x2) s4 (x) f(x3) s1 (x) s3 (x) f(x4) f(x1) Interval 1 Interval 2 Interval 3 Interval 4 x1 x2 x3 x4 x5 3(n-1) unknowns si(x) = ai + bi (xxi) + ci(xxi)2

Piecewise Quadratic Splines Example with n = 5 The functional must pass through all the points xi (continuity condition) The function values of adjacent polynomials must be equal at all nodes (identical to condition 1.) 2(n-2) + 2 = 2(n-1) The 1st derivatives are continuous at interior nodes xi, (n-2) Assume that the second derivatives is zero at the first points 3(n1) equations for 3(n1) unknowns 2(n1) + (n2) + (1) = 3(n1)

Piecewise Quadratic Splines Function must pass through all the points x = xi (2n  2 eqns) This also ensure the same function values of adjacent polynomials at the interior knots (hi = xi+1 – xi) Apply to every interval (4 intervals, 8 equations)

Piecewise Quadratic Splines Continuous slope at interior knots x = xi (n2 equations) Apply to interior knots x2 , x3 and x4 (3 equations) Zero curvatures at x = x1 (1 equation)

Example: Quadratic Spline

Quadratic Spline Interpolation function [A, b] = quadratic(x, f) % exact solution f(x)=x^3-5x^2+3x+4 % x=[-1 0 2 5 6]; f=[-5 4 -2 19 58]; h1=x(2)-x(1); h2=x(3)-x(2); h3=x(4)-x(3); h4=x(5)-x(4); f1=f(1); f2=f(2); f3=f(3); f4=f(4); f5=f(5); A=[1 0 0 0 0 0 0 0 0 0 0 0 0 h1 h1^2 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 h2 h2^2 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 h3 h3^2 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 h4 h4^2 0 1 2*h1 0 -1 0 0 0 0 0 0 0 0 0 0 0 1 2*h2 0 -1 0 0 0 0 0 0 0 0 0 0 0 1 2*h3 0 -1 0 0 0 1 0 0 0 0 0 0 0 0 0]; b=[f1; f2-f1; f2; f3-f2; f3; f4-f3; f4; f5-f4; 0; 0; 0; 0];

Quadratic Spline Interpolation >> x=[-1 0 2 5 6]; f=[-5 4 -2 19 58]; >> [A,b]=quadratic(x,f) p = A\b -5.0000 9.0000 4.0000 -6.0000 -2.0000 -15.0000 7.3333 19.0000 29.0000 10.0000 dx = 0.1; z1=x(1):dx:x(2); s1=p(1)+p(2)*(z1-x(1))+p(3)*(z1-x(1)).^2; z2=x(2):dx:x(3); s2=p(4)+p(5)*(z2-x(2))+p(6)*(z2-x(2)).^2; z3=x(3):dx:x(4); s3=p(7)+p(8)*(z3-x(3))+p(9)*(z3-x(3)).^2; z4=x(4):dx:x(5); s4=p(10)+p(11)*(z4-x(4))+p(12)*(z4-x(4)).^2; H=plot(z1,s1,'r',z2,s2,'b',z3,s3,'m',z4,s4,'g'); xx=-1:0.1:6; fexact=xx.^3-5*xx.^2+3*xx+4; hold on; G=plot(xx,fexact,'c',x,f,'ro'); set(H,'LineWidth',3); set(G,'LineWidth',3,'MarkerSize',8); H1=xlabel('x'); set(H1,'FontSize',15); H2=ylabel('f(x)'); set(H2,'FontSize',15); H3=title('f(x)=x^3-5x^2+3x+4'); set(H3,'FontSize',15);

Quadratic Spline s4(x) Exact function s2(x) s1(x) s3(x)

Cubic Splines Cubic splines avoid the straight line and the over-swing Can develop method like we did for quadratic – 4(n–1) unknowns – 4(n–1) equations interior knot equality end point fixed interior knot first derivative equality assume derivative value if needed

Piecewise Cubic Splines s2 (x) sn-1 (x) s1 (x) Continuous slopes and curvatures x1 x2 x3 xn-1 xn 4(n1) unknowns

Piecewise Cubic Splines s2”(x) Sn-1”(x) s1”(x) s3”(x) x0 x1 x2 xn-1 xn si (x) - piecewise cubic polynomials si’(x) - piecewise quadratic polynomials (slope) si”(x) - piecewise linear polynomials (curvatures) Reduce to (n-1) unknowns and (n-1) equations for si’’

Cubic Splines Piecewise cubic polynomial with continuous derivatives up to order 2 The function must pass through all the data points gives 2(n-1) equations i = 1,2,…, n-1

Cubic Splines 2. First derivatives at the interior nodes must be equal: (n-2) equations 3. Second derivatives at the interior nodes must be equal:

Cubic Splines The last two equations 4. Two additional conditions are needed (arbitrary) The last two equations Total equations: 2(n-1) + (n-2) + (n-2) +2 = 4(n-1)

Cubic Splines Solve for (ai, bi, ci, di) – see textbook for details Tridiagonal system with boundary conditions c1 = cn= 0

Cubic Splines Tridiagonal matrix

Hand Calculations

Hand Calculations can be further simplified since c1 = c4 = 0 (natural spline)

Cubic Spline Interpolation

Cubic Splines Piecewise cubic splines (cubic polynomials)

Cubic Spline Interpolation The exact solution is a cubic function Why cubic spline interpolation does not give the exact solution for a cubic polynomial? Because the conditions on the end knots are different! In general, f (x0)  0 and f (xn)  0 !!

Cubic Spline Interpolation

>> xx=[-1 0 2 5 6]; f = [-5 4 -2 19 58]; >> Cubic_spline(xx,f); Resulting piecewise function: s1 = (-5.000000)+(11.081218)*(x-(-1.000000)) s2 = (0.000000)*(x-(-1.000000)).^2+(-2.081218)*(x-(-1.000000)).^3 (4.000000)+(4.837563)*(x-(0.000000)) (-6.243655)*(x-(0.000000)).^2+(1.162437)*(x-(0.000000)).^3 (-2.000000)+(-6.187817)*(x-(2.000000)) (0.730964)*(x-(2.000000)).^2+(1.221658)*(x-(2.000000)).^3 (19.000000)+(31.182741)*(x-(5.000000)) (11.725888)*(x-(5.000000)).^2+(-3.908629)*(x-(5.000000)).^3 (i = 1) (i = 2) (i = 3) (i = 4)

Cubic Spline Interpolation Piecewise cubic Continuous slope Continuous curvature zero curvatures at end knots exact solution

End Conditions of Splines Natural spline : zero second derivative (curvature) at end points Clamped spline: prescribed first derivative (clamped) at end points Not-a-Knot spline: continuous third derivative at x2 and xn-1

Continuous third derivatives at x2 and xn-1 >> x = linspace(-1,1,9); y = 1./(1+25*x.^2); >> xx = linspace(-1,1,100); yy = spline(x,y,xx); >> yr=1./(1+25*xx.^2); >> H=plot(x,y,'o',xx,yy,xx,yr,'--'); Continuous third derivatives at x2 and xn-1 Comparison of Runge’s function (dashed red line) with a 9-point not-a-knot spline fit generated with MATLAB (solid green line)

Clamped End Spline - Use 11 values including slopes at end points >> yc = [1 y –4]; % 1 and -4 are the 1st-order derivatives (or slopes)at 1st & last point, respectively. >> yyc = spline(x,yc,xx); >> >> H=plot(x,y,'o',xx,yyc,xx,yr,'--'); Note that first derivatives of 1 and 4 are specified at the left and right boundaries, respectively.

MATLAB Functions One-dimensional interpolations yy = spline (x, y, xx) yi = interp1 (x, y, xi, ‘method’) yi = interp1 (x, y, xi, ‘linear’) yi = interp1 (x, y, xi, ‘spline’) – not-a-knot spline yi = interp1 (x, y,, xi, ‘pchip’) – cubic Hermite yi = interp1 (x, y,, xi, ‘cubic’) – cubic Hermite yi = interp1 (x, y,, xi, ‘nearest’) – nearest neighbor

MATLAB Function: interp1 Piecewise polynomial interpolation on velocity time series for an automobile

Spline Interpolations >> x=[1 2 4 7 9 10] x = 1 2 4 7 9 10 >> y=[3 -2 5 4 9 2] y = 3 -2 5 4 9 2 >> xi=1:0.1:10; >> y1=interp1(x,y,xi,'linear'); >> y2=interp1(x,y,xi,'spline'); >> y3=interp1(x,y,xi,'cubic'); >> plot(x,y,'ro',xi,y1,xi,y2,xi,y3,'LineWidth',2,'MarkerSize',12) >> print -djpeg spline00.jpg

Spline Interpolations Linear Not-a-knot Cubic

MATLAB’s Functions Two-dimensional interpolations zi = interp2 (x, y, z, xi, yi)

MATLAB Function: interp2 >> [x,y,z]=peaks(100); [xi,yi]=meshgrid(-3:0.1:3,-3:0.1:3); >> zi = interp2(x,y,z,xi,yi); surf(xi,yi,zi) >> print -djpeg075 peaks1.jpg >> [x,y,z]=peaks(10); [xi,yi]=meshgrid(-3:0.1:3,-3:0.1:3); >> print -djpeg075 peaks2.jpg 10  10 data base 100 100 data base

CVEN 302-501 Homework No. 11 Chapter 16 Chapter 19 Problem 16.1(a) (30) – Hand Calculation Problem 16.1(b) (20)– MATLAB program not-a-knot spline: yy = spline(x, y, xx) Problem 16.1(c)(20) – MATLAB program Chapter 19 Problem 19.2 (20)– Hand Calculation Problem 19.4 (20)– Hand Calculation Due on Wed. 11/05/08 at the beginning of the period