Introduction to Scientific Computing - - A Matrix Vector Approach Using Matlab Written by Charles F.Van Loan 陈 文 斌 复旦大学.

Slides:



Advertisements
Similar presentations
Splines and Piecewise Interpolation
Advertisements

Polynomial Approximation PSCI 702 October 05, 2005.
Computer Programming (TKK-2144) 13/14 Semester 1 Instructor: Rama Oktavian Office Hr.: M.13-15, W Th , F
Interpolation A method of constructing a function that crosses through a discrete set of known data points. .
Cubic Curves CSE167: Computer Graphics Instructor: Steve Rotenberg UCSD, Fall 2006.
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.
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.
Engineering Analysis ENG 3420 Fall 2009 Dan C. Marinescu Office: HEC 439 B Office hours: Tu-Th 11:00-12:00.
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.
Curve Fitting: Splines
Chapter 3, Interpolation and Extrapolation. Interpolation & Extrapolation (x i,y i ) Find an analytic function f(x) that passes through given N points.
Lecture 29 of 42 Bezier Curves and Splines Wednesday, 02 April 2008
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
Lecture 11 Chap. 15. Outline Interpolation – Linear Interpolation – Cubic Spline Interpolation – Extrapolation 15.2 Curve.
MATLAB EXAMPLES Interpolation and Integration 58:111 Numerical Calculations Department of Mechanical and Industrial Engineering.
ECIV 301 Programming & Graphics Numerical Methods for Engineers Lecture 23 CURVE FITTING Chapter 18 Function Interpolation and Approximation.
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.
Root Finding The solution of nonlinear equations and systems Vageli Coutsias, UNM, Fall ‘02.
Scientific Computing Linear and Quadratic Splines.
Polynomial Interpolation You will frequently have occasions to estimate intermediate values between precise data points. The function you use to interpolate.
Chapter 14 Curve Fitting : Polynomial Interpolation Gab Byung Chae.
Scientific Computing Interpolation – Divided Differences Efficiency and Error Analysis.
1. Interpolating polynomials Polynomial of degree n,, is a linear combination of Definitions: (interval, continuous function, abscissas, and polynomial)
By Adam Mallen.  What is it?  How is it different from regression?  When would you use it?  What can go wrong?  How do we find the interpolating.
41 - 4/24/2000AME 150L1 Solving Engineering Problems, Integrating Equations.
Splines IV – B-spline Curves based on: Michael Gleicher: Curves, chapter 15 in Fundamentals of Computer Graphics, 3 rd ed. (Shirley & Marschner) Slides.
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,
Introduction to Numerical Analysis I MATH/CMPSC 455 Splines.
CS 376 Introduction to Computer Graphics 04 / 25 / 2007 Instructor: Michael Eckmann.
Mohiuddin Ahmad SUNG-BONG JANG Interpolation II (8.4 SPLINE INTERPOLATION) (8.5 MATLAB’s INTERPOLATION Functions)
Interpolating Solutions to IVPs Douglas Wilhelm Harder, M.Math. LEL Department of Electrical and Computer Engineering University of Waterloo Waterloo,
Cubic Spline Interpolation. Cubic Splines attempt to solve the problem of the smoothness of a graph as well as reduce error. Polynomial interpolation.
Spline Interpolation A Primer on the Basics by Don Allen.
Parametric Curves CS 318 Interactive Computer Graphics John C. Hart.
Engineering Analysis ENG 3420 Fall 2009 Dan C. Marinescu Office: HEC 439 B Office hours: Tu-Th 11:00-12:00.
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. A Concise Introduction to MATLAB ® William J. Palm III.
1 Chapter 4 Interpolation and Approximation Lagrange Interpolation The basic interpolation problem can be posed in one of two ways: The basic interpolation.
MA4229 Lectures 15, 16 Week 13 Nov 1, Chapter 18 Interpolation by piecewise polynomials.
CS552: Computer Graphics Lecture 19: Bezier Curves.
Introduction to Parametric Curve and Surface Modeling.
CSCI480/582 Lecture 9 Chap.2.2 Cubic Splines – Hermit and Bezier Feb, 11, 2009.
Computational Methods CMSC/AMSC/MAPL 460 Polynomial Interpolation Ramani Duraiswami, Dept. of Computer Science.
Introduction to Programming for Mechanical Engineers
Chapter 4, Integration of Functions
EEE 244-7: Curve Fitting.
Curve-Fitting Spline Interpolation
Numerical Analysis Lecture 25.
Interpolation.
Interpolation Methods
Chapter 15 Curve Fitting : Splines
Spline Interpolation Method
Spline Interpolation Method
CS U540 Computer Graphics Prof. Harriet Fell Spring 2007
Spline Interpolation Method
Spline Interpolation Class XVII.
Splines and Piecewise Interpolation
Interpolation Methods
Why Splines ?
Splines There are cases where polynomial interpolation is bad
Assignment 3 Questions 1 and 2 Stephen Adams CS 4MN3
INTERPOLATION For both irregulary spaced and evenly spaced data.
Introduction to Parametric Curve and Surface Modeling
Theory of Approximation: Interpolation
Presentation transcript:

Introduction to Scientific Computing - - A Matrix Vector Approach Using Matlab Written by Charles F.Van Loan 陈 文 斌 复旦大学

Chapter3 Piecewise Polynomial Interpolation Piecewise Linear Interpolation Piecewise Cubic Hermite Interpolation Cubic Splines

Piecewise Linear Interpolation

Piecewise Linear

function [a,b] = pwL(x,y) n = length(x); a = y(1:n-1); b = diff(y)./ diff(x); z=linspace(0,1,9); [a,b]=pwL(z,sin(2*pi*z)); for i=1:n-1 b(i)=(y(i+1)- y(i))/ (x(i+1)- x(i)); end b=(y(2:n)-y(1:n-1))./(x(2:n)-x(1:n- 1)) b=diff(y)./diff(x) Test code

Evalution Problem: if z==x(n) i =n-1; else i=sum(x<=z); end

Binary search mid = floor((Left+Right)/2); If z<x(mid) Right=mid; Else Left =mid; end

function i = Locate(x,z,g) % g (1<=g<=n-1) is an optional input parameter % search for i begins, the value i=g is tried. if nargin==3 if (x(g)<=z) & (z<=x(g+1)) i = g; return end;end n = length(x); if z = = x(n) i = n-1; else Left = 1; Right = n; while Right > Left+1 Binary_search end g: guss

function LVals = pwLEval(a,b,x,zVals) % Evaluates the piecewise linear polynomial defined by the column %(n-1)-vectors m = length(zVals); LVals = zeros(m,1); g = 1; for j=1:m i = Locate(x,zVals(j),g); LVals(j) = a(i) + b(i)*(zVals(j)-x(i)); g = i; end m-vector

A priori determination of breakpoints Static

Adaptive Piecewise Linear Interpolation Problem

Adaptive Piecewise Linear Interpolation acceptable or

Piecewise Cubic Hermit Interpolation

Hermit cubic interpolant

Piecewise cubic polynomial For i=1:n-1 [a(i),b(i), c(i), d(i)=Hcubic(x(i),y(i),s(i),x(i+1),y(i+1),s(i+1)) End

function [a,b,c,d] = pwC(x,y,s) % Piecewise cubic Hermite interpolation. n = length(x); a = y(1:n-1); b = s(1:n-1); Dx = diff(x); Dy = diff(y); yp = Dy./ Dx; c = (yp - s(1:n-1))./ Dx; d = (s(2:n) + s(1:n-1) - 2*yp)./ (Dx.* Dx); x,y,s: vector

Evaluation function Cvals = pwCEval(a,b,c,d,x,zVals) m = length(zVals); Cvals = zeros(m,1); g=1; for j=1:m i = Locate(x,zVals(j),g); Cvals(j) = d(i)*(zVals(j)-x(i+1)) + c(i); Cvals(j) = Cvals(j)*(zVals(j)-x(i)) + b(i); Cvals(j) = Cvals(j)*(zVals(j)-x(i)) + a(i); g = i; end Locate Cubic version of HornerN

Cubic spline interpolant Given with find a piecewise cubic interpolant with the property that S, S' and S'' are continuous. Why need spline?

Continuity at the interior knots

tridiagonal

choice

n=length(x); Dx=diff(x); yp=diff(y)./Dx; T=zeros(n-2,n-2); r=zeros(n-2,1); for i=2:n-3 T(i,i)=2(Dx(i)+Dx(i+1)); T(i,i-1)=Dx(i+1); T(i,i+1)=Dx(i); r(i)=3(Dx(i+1)*yp(i)+Dx(i)*yp(i+1)); end Help diag

The complete spline

T(1,1)=2*(Dx(1)+Dx(2)); T(1,2)=Dx(1); r(1)=3*(Dx(2)*yp(1)+Dx(1)*yp(2))-Dx(2)*muL; T(n-2,n-2)=2*(Dx(n-2)+Dx(n-1)); T(n-2,n-3)=Dx(n-1); r(n-2)=3*(Dx(n-1)*yp(n-2)+Dx(n-2)*yp(n-1))-Dx(n-2)*muR; s=[muL;T\r(1:n-2);muR];

The Natural Spline

T(1,1) = 2*Dx(1) + 1.5*Dx(2); T(1,2) = Dx(1); r(1) = 1.5*Dx(2)*yp(1) + 3*Dx(1)*yp(2) + Dx(1)*Dx(2)*muL/4; T(n-2,n-2) = 1.5*Dx(n-2)+2*Dx(n-1); T(n-2,n-3) = Dx(n-1); r(n-2) = 3*Dx(n-1)*yp(n-2) + 1.5*Dx(n-2)*yp(n-1)- … Dx(n-1)*Dx(n-2)*muR/4; stilde = T\r; s1 = (3*yp(1) - stilde(1) - muL*Dx(1)/2)/2; sn = (3*yp(n-1) - stilde(n-2) + muR*Dx(n-1)/2)/2; s = [s1;stilde;sn];

The Not-a-Knot Spline

q = Dx(1)*Dx(1)/Dx(2); T(1,1) = 2*Dx(1) +Dx(2) + q; T(1,2) = Dx(1) + q; r(1) = Dx(2)*yp(1) + Dx(1)*yp(2)+2*yp(2)*(q+Dx(1)); q = Dx(n-1)*Dx(n-1)/Dx(n-2); T(n-2,n-2) = 2*Dx(n-1) + Dx(n-2)+q; T(n-2,n-3) = Dx(n-1)+q; r(n-2) = Dx(n-1)*yp(n-2) + Dx(n-2)*yp(n-1) … +2*yp(n-2)*(Dx(n-1)+q); stilde = T\r; s1 = -stilde(1)+2*yp(1); s1 = s1 + ((Dx(1)/Dx(2))^2)*(stilde(1)+stilde(2)-2*yp(2)); sn = -stilde(n-2) +2*yp(n-1); sn = sn+((Dx(n-1)/Dx(n-2))^2)*(stilde(n-3) … +stilde(n-2)-2*yp(n-2)); s = [s1;stilde;sn];

function [a,b,c,d] = CubicSpline(x,y,derivative,muL,muR) % Cubic spline interpolation with prescribed end conditions. % Usage: % [a,b,c,d] = CubicSpline(x,y,1,muL,muR) % S'(x(1)) = muL, S'(x(n)) = muR % [a,b,c,d] = CubicSpline(x,y,2,muL,muR) % S''(x(1)) = muL, S''(x(n)) = muR % [a,b,c,d] = CubicSpline(x,y) % S'''(z) continuous at x(2) and x(n-1)

Knot Spacing = Not-a-knot spline error

Bad end conditions

n = 9 Spline Interpolant of atan(x) Matlab Spline Tools z=linspace(-5,5); x=linspace(-5,5,9); y=atan(x); Svals=spline(x,y,z); plot(z,Svals) Not-a-knot spline

pp-representation x=linspace(-5,5,9); y=atan(x); S=spline(x,y); z=linspace(-5,5); Svals=ppval(S,z) plot(z,Svals) pp-representation [x, rho,L,k]=unmkpp(S) The coefficients of the local polynomials are assembled in an L-by-k matrix rho

drho = [3*rho(:,1) 2*rho(:,2) rho(:,3)]; dS = mkpp(x,drho); V = PPVAL(PP,XX) returns the value at the points XX of the piecewise polynomial contained in PP, as constructed by SPLINE or the spline utility z = linspace(-5,5); Svals = ppval(S,z); dSvals = ppval(dS,z);

Derivative of n = 9 Spline Interpolant of atan(x)

n = 9;x = linspace(-5,5,n);y = atan(x);S = spline(x,y); [x,rho,L,k] = unmkpp(S); drho = [3*rho(:,1) 2*rho(:,2) rho(:,3)]; dS = mkpp(x,drho); z = linspace(-5,5); Svals = ppval(S,z); dSvals = ppval(dS,z); atanvals = atan(z); Figure;plot(z,atanvals,z,Svals,x,y,'*'); title(sprintf('n = %2.0f Spline Interpolant of atan(x)',n)) datanvals = ones(size(z))./(1 + z.*z); figure plot(z,datanvals,z,dSvals) title(sprintf('Derivative of n = %2.0f Spline Interpolant of atan(x)',n))