Interpolation and Polynomial Approximation I

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

Exam 2. Average: 85.6 Median: 87.0 Maximum: Minimum: 55.0 Standard Deviation: Numerical Methods Fall 2011 Lecture 20

Computational Physics

MR. YATES. Vocabulary. Quadratic Cubic Monomial Binomial Trinomial Term Leading Term Leading Coefficient

Empirical Models Interpolation Polynomial Models

!"#$%&'(&)*$%&+",#$$-$%&+./#-+ (&)*$%&+%"-$+0!#1%&

TABLE OF CONTENTS INTRODUCTION, APPROXIMATION & ERRORS 1. Chapter Introduction to numerical methods 1 Multiple-choice test 7 Problem set 9

Input: A set (x i -yy i ) data. Output: Function value at arbitrary point x. What for x = 1.2?

Curve Fitting and Interpolation

Interpolation Theory

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

Incoming Magnet Precalculus / Functions Summer Review Assignment

6. Multiple Reactions

Seventeen generic formulas that may generate prime-producing quadratic polynomials

Least squares regression

(308 ) EXAMPLES. 1. FIND the quotient and remainder when. II. 1. Find a root of the equation x* = +J Find a root of the equation x 6 = ^ - 1.

Lycée des arts Math Grade Algebraic expressions S.S.4

3.1 Interpolation and the Lagrange Polynomial

1 Piecewise Cubic Interpolation

Linear Regression Spring 2014

MathB65 Ch 4 VII, VIII, IX.notebook. November 06, 2017

November 20, Interpolation, Extrapolation & Polynomial Approximation

Summer Packet for Students Taking Introduction to Calculus in the Fall

Summer Review Packet. for students entering. IB Math SL

Chapter 3 Interpolation and Polynomial Approximation

Vector and Matrix Norms I

INTERPOLATION. and y i = cos x i, i = 0, 1, 2 This gives us the three points. Now find a quadratic polynomial. p(x) = a 0 + a 1 x + a 2 x 2.

Preliminaries Lectures. Dr. Abdulla Eid. Department of Mathematics MATHS 101: Calculus I

Vector and Matrix Norms I

Preliminary Examination in Numerical Analysis

Linear Models 1. Isfahan University of Technology Fall Semester, 2014

Some notes on Chapter 8: Polynomial and Piecewise-polynomial Interpolation

Interpolation (Shape Functions)

UNIVERSIDAD CARLOS III DE MADRID Escuela Politécnica Superior Departamento de Matemáticas

Southington High School 720 Pleasant Street Southington, CT 06489

Sequences and Series

Solving Dense Linear Systems I

Chapter 4: Interpolation and Approximation. October 28, 2005

LINEAR INEQUALITIES. Chapter Overview

Scientific Computing

Interpolation. 1. Judd, K. Numerical Methods in Economics, Cambridge: MIT Press. Chapter

Math Numerical Analysis Mid-Term Test Solutions

STAT 111 Recitation 7

Chapter 1 Numerical approximation of data : interpolation, least squares method

Polynomials and Factoring

Lecture 7. Please note. Additional tutorial. Please note that there is no lecture on Tuesday, 15 November 2011.

1. Definition of a Polynomial

Lecture 10 Polynomial interpolation

Taylor Series and Numerical Approximations

Solving simple equations, a review/primer

Polynomial expression

To Find the Product of Monomials. ax m bx n abx m n. Let s look at an example in which we multiply two monomials. (3x 2 y)(2x 3 y 5 )

Cubic Spline. s(x) = s j (x) = a j + b j (x x j ) + c j (x x j ) 2 + d j (x x j ) 3, j = 0,... n 1 (1)

Cubic Splines. Antony Jameson. Department of Aeronautics and Astronautics, Stanford University, Stanford, California, 94305

Jeff Howbert Introduction to Machine Learning Winter

1. 4 2y 1 2 = x = x 1 2 x + 1 = x x + 1 = x = 6. w = 2. 5 x

3.0 INTRODUCTION 3.1 OBJECTIVES 3.2 SOLUTION OF QUADRATIC EQUATIONS. Structure

5 Years (10 Semester) Integrated UG/PG Program in Physics & Electronics

CS 323: Numerical Analysis and Computing

CALCULUS AB/BC SUMMER REVIEW PACKET (Answers)

Thirty-Ninth Annual Columbus State Invitational Mathematics Tournament

Algebraic Expressions

5.3. Polynomials and Polynomial Functions

Q 0 x if x 0 x x 1. S 1 x if x 1 x x 2. i 0,1,...,n 1, and L x L n 1 x if x n 1 x x n

GATE Engineering Mathematics SAMPLE STUDY MATERIAL. Postal Correspondence Course GATE. Engineering. Mathematics GATE ENGINEERING MATHEMATICS

Curve Fitting. Objectives

Outline. Basic concepts: SVM and kernels SVM primal/dual problems. Chih-Jen Lin (National Taiwan Univ.) 1 / 22

BSM510 Numerical Analysis

CHAPTER 4. Interpolation

Interpolation and the Lagrange Polynomial

Lecture 27. Quadratic Formula

New Introduction to Multiple Time Series Analysis

Theory of Computation

Multiplication of Polynomials

Topic 7: Polynomials. Introduction to Polynomials. Table of Contents. Vocab. Degree of a Polynomial. Vocab. A. 11x 7 + 3x 3

Data Analysis-I. Interpolation. Soon-Hyung Yook. December 4, Soon-Hyung Yook Data Analysis-I December 4, / 1

Chapter 2 Interpolation

Lecture Note 3: Interpolation and Polynomial Approximation. Xiaoqun Zhang Shanghai Jiao Tong University

An Introduction to Probability Theory and Its Applications

I) Simplifying fractions: x x. 1) 1 1 y x. 1 1 x 1. 4 x. 13x. x y xy. x 2. Factoring: 10) 13) 12) III) Solving: x 9 Prime (using only) 11)

Introduction Linear system Nonlinear equation Interpolation

In practice one often meets a situation where the function of interest, f(x), is only represented by a discrete set of tabulated points,

MHF4U Unit 2 Polynomial Equation and Inequalities

Analysis of Ordinary Differential Equations

SECTION 7: CURVE FITTING. MAE 4020/5020 Numerical Methods with MATLAB

S56 (5.1) Polynomials.notebook August 25, 2016

Chapter 2 notes from powerpoints

Applied Numerical Analysis Homework #3

CHAPTER 1. Review of Algebra

Wiley. Methods and Applications of Linear Models. Regression and the Analysis. of Variance. Third Edition. Ishpeming, Michigan RONALD R.

BD1. Reciprocal space and Fourier transforms. IB Mineral Sciences Module B: Reciprocal Space, Symmetry and Crystallography

Interpolation APPLIED PROBLEMS. Reading Between the Lines FLY ROCKET FLY, FLY ROCKET FLY WHAT IS INTERPOLATION? Figure Interpolation of discrete data.

A polynomial expression is the addition or subtraction of many algebraic terms with positive integer powers.

MHF4U. Advanced Functions Grade 12 University Mitchell District High School. Unit 2 Polynomial Functions 9 Video Lessons

Chapter 1: Precalculus Review

King Fahd University of Petroleum and Minerals Prep-Year Math Program Math Term 161 Recitation (R1, R2)

Interpolation and extrapolation

Tutorial 1, B. Tech. Sem III, 24 July, (Root Findings and Linear System of Equations)

Mir Md. Maruf Morshed

Pattern Recognition and Machine Learning

Transcription:

Interpolation and Polynomial Approximation I If f (n) (x), n are available, Taylor polynomial is an approximation: f (x) = f (x 0 )+f (x 0 )(x x 0 )+ 1 2! f (x 0 )(x x 0 ) 2 + Example: e x = 1 + x 1! + x 2 2! + x 3 3! + Chih-Jen Lin (National Taiwan Univ.) 1 / 51

Interpolation and Polynomial Approximation II Need only information of one point If finite terms selected, only approximate points near x 0 Primal use of Taylor polynomials for numerical methods: derivation of numerical techniques but not approximation Chih-Jen Lin (National Taiwan Univ.) 2 / 51

Lagrange Polynomials I Given (x 0, f (x 0 )), (x 1, f (x 1 )),..., (x n, f (x n )), find a function passing all of them Why consider polynomials: the simplest form of functions Degree 1 polynomial passing two points: A line Chih-Jen Lin (National Taiwan Univ.) 3 / 51

Lagrange Polynomials II Given (x 0, f (x 0 )), (x 1, f (x 1 )). Define Then L 0 (x) x x 1, L 1 (x) x x 0, x 0 x 1 x 1 x 0 P(x) L 0 (x)f (x 0 ) + L 1 (x)f (x 1 ) P(x 0 ) = 1f (x 0 ) + 0f (x 1 ) = f (x 0 ) P(x 1 ) = 0f (x 1 ) + 1f (x 1 ) = f (x 1 ) Generalization: higher-degree polynomials Chih-Jen Lin (National Taiwan Univ.) 4 / 51

Lagrange Polynomials III (n + 1) points a polynomial with degree at most n (x 0, f (x 0 )), (x 1, f (x 1 )),..., (x n, f (x n )) Construct L n,k (x). We hope that { 0 i k L n,k (x i ) = 1 i = k n: degree, k: index. Then P(x) = L n,k (x)f (x k ) k=0 Chih-Jen Lin (National Taiwan Univ.) 5 / 51

Lagrange Polynomials IV Thus we have Define P(x i ) = f (x i ) L n,k (x) (x x 0) (x x k 1 )(x x k+1 ) (x x n ) (x k x 0 ) (x k x k 1 )(x k x k+1 ) (x k x n ) Assume x i x j Chih-Jen Lin (National Taiwan Univ.) 6 / 51

Spline Interpolation I Disadvantages of using polynomials Very high degrees Large fluctuation We will try piecewise polynomial approximation Different polynomials on each interval Linear: a series of straight lines joining (x 0, f (x 0 )),..., (x n, f (x n )) Example x = [ 0 1 2 3 ], y = [ 0 1 4 3 ] Chih-Jen Lin (National Taiwan Univ.) 7 / 51

Spline Interpolation II 4 3.5 3 2.5 2 1.5 1 0.5 0 0 0.5 1 1.5 2 2.5 3 Function forms: s 0 (x),..., s n 1 (x) s j (x) = x x j+1 x j x j+1 y j + x x j x j+1 x j y j+1, x j x x j+1 Chih-Jen Lin (National Taiwan Univ.) 8 / 51

Spline Interpolation III Disadvantage: not differentiable at end points Let f (x) be continuous We require s j (x j ) = f (x j ), j = 0,..., n 1, s n 1 (x n ) = f (x n ) s j+1 (x j+1 ) = s j (x j+1 ), j = 0,..., n 2 s j+1(x j+1 ) = s j(x j+1 ), j = 0,..., n 2 How many conditions: 2n + (n 1) = 3n 1 Chih-Jen Lin (National Taiwan Univ.) 9 / 51

Spline Interpolation IV Quadratic piecewise interpolation: 3n variables Each interval: a quadratic polynomial, 3 variables Most common piecewise approximation: cubic polynomials (Spline) 4n variables Chih-Jen Lin (National Taiwan Univ.) 10 / 51

Spline Interpolation V Let s j (x j ) = f (x j ), j = 0,..., n 1, (1) s n 1 (x n ) = f (x n ) s j+1 (x j+1 ) = s j (x j+1 ), j = 0,..., n 2 (2) s j+1(x j+1 ) = s j(x j+1 ), j = 0,..., n 2 s j+1(x j+1 ) = s j (x j+1 ), j = 0,..., n 2 Number of conditions n + 1 + 3(n 1) = 4n 2 Chih-Jen Lin (National Taiwan Univ.) 11 / 51

s j (x j ) = a j = f (x j ), j = 0,..., n 1 Chih-Jen Lin (National Taiwan Univ.) 12 / 51 Spline Interpolation VI Boundary conditions s 0 (x 0 ) = s n 1(x n ) = 0 or s 0(x 0 ) = f (x 0 ) and s n 1(x n ) = f (x n ) Total 4n conditions n cubic polynomials Construct cubic polynomials s j (x) a j + b j (x x j ) + c j (x x j ) 2 + d j (x x j ) 3, j = 0,..., n 1 Immediately

Spline Interpolation VII Now (2) becomes Define a j+1 = s j (x j+1 ) = a j + b j (x j+1 x j ) + c j (x j+1 x j ) 2 +d j (x j+1 x j ) 3, j = 0,..., n 2 h j x j+1 x j a n f (x n ) Earlier a j is only from 0 to n 1 Chih-Jen Lin (National Taiwan Univ.) 13 / 51

Spline Interpolation VIII We have Then a n = s n 1 (x n ) = a n 1 + b n 1 (x n x n 1 ) + c j (x n x n 1 ) 2 + d j (x n x n 1 ) 3 a j+1 = a j + b j h j + c j h 2 j + d j h 3 j, j = 0,..., n 1 (3) Chih-Jen Lin (National Taiwan Univ.) 14 / 51

Spline Interpolation IX Define Earlier b j is only 0 to n 1 Using b n s n 1(x n ) (4) s j(x) = b j + 2c j (x x j ) + 3d j (x x j ) 2 s j+1(x j+1 ) = s j(x j+1 ), j = 0,..., n 2 b j+1 = b j + 2c j h j + 3d j h 2 j, j = 0,..., n 1 (5) Chih-Jen Lin (National Taiwan Univ.) 15 / 51

c j+1 = c j + 3d j (h j ), j = 0,..., n 1 Chih-Jen Lin (National Taiwan Univ.) 16 / 51 Spline Interpolation X Define Since c n s n 1(x n )/2 we have s j+1(x j+1 ) = s j (x j+1 ), j = 0,..., n 2 s j (x) = 2c j + 6d j (x x j ) s j (x j+1 ) = 2c j + 6d j h j s j+1(x j+1 ) = 2c j+1

Spline Interpolation XI Thus so (3) becomes d j = c j+1 c j 3h j a j+1 = a j + b j h j + c j h 2 j + c j+1 c j 3h j = a j + b j h j + h2 j 3 (2c j + c j+1 ), j = 0,..., n (6) 1 h 3 j Chih-Jen Lin (National Taiwan Univ.) 17 / 51

Spline Interpolation XII (5) becomes b j+1 = b j + 2c j h j + 3d j h 2 j = b j + 2c j h j + 3 c j+1 c j hj 2 3h j = b j + 2c j h j + h j (c j+1 c j ) = b j + h j (c j + c j+1 ), j = 0,..., n 1 (7) We have known a j, unknowns: b j, c j Chih-Jen Lin (National Taiwan Univ.) 18 / 51

Spline Interpolation XIII From (6) b j = 1 h j (a j+1 a j ) h j 3 (2c j + c j+1 ), j = 0,..., n 1 That is b j 1 = 1 h j 1 (a j a j 1 ) h j 1 3 (2c j 1 + c j ), j = 1,..., n Chih-Jen Lin (National Taiwan Univ.) 19 / 51

Spline Interpolation XIV Substituting to (7) 1 h j (a j+1 a j ) h j 3 (2c j + c j+1 ) = 1 h j 1 (a j a j 1 ) h j 1 3 (2c j 1 + c j ) + h j 1 (c j 1 + c j ), j = 1,..., n 1 j cannot be zero now because b j = b j 1 +, j = 1,..., n Chih-Jen Lin (National Taiwan Univ.) 20 / 51

Spline Interpolation XV Finally so h j 1 3 c j 1 + 2(h j 1 + h j ) c j + h j 3 3 c j+1 = 1 (a j+1 a j ) 1 (a j a j 1 ) h j h j 1 h j 1 c j 1 + 2(h j 1 + h j )c j + h j c j+1 = 3 (a j+1 a j ) 3 (a j a j 1 ), j = 1,..., n (8) 1 h j h j 1 Chih-Jen Lin (National Taiwan Univ.) 21 / 51

Spline Interpolation XVI Only unknowns: c j, j = 0,..., n Once we know c j, then we can find b j and d j Boundary conditions If s 0 (x 0) = s n 1 (x n) = 0 then s 0 (x) = 2c 0 + 6d 0 (x x 0 ) s 0 (x 0 ) = 2c 0 = 0, s n 1(x n ) = 2c n = 0 (9) Solve c j, j = 0,..., n using (n + 1) equalities: (8) and (9) Chih-Jen Lin (National Taiwan Univ.) 22 / 51

Spline Interpolation XVII We can use other boundary conditions: Example: s 0(x 0 ) = f (x 0 ) and s n 1(x n ) = f (x n ) >> x = [ -2-1 0 1 2] ; >> y = [4-1 2 1 8] ; >> yy=interp1(x,y,-2:0.1:2, spline ) ; >> plot(-2:0.1:2,yy); Chih-Jen Lin (National Taiwan Univ.) 23 / 51

Spline Interpolation XVIII 8 7 6 5 4 3 2 1 0 1 2 2 1.5 1 0.5 0 0.5 1 1.5 2 Chih-Jen Lin (National Taiwan Univ.) 24 / 51

Spline Interpolation XIX >> [sp] = spline(x,y) sp = form: pp breaks: [-2-1 0 1 2] coefs: [4x4 double] pieces: 4 order: 4 dim: 1 spline: returns the spline structure interp1: 1-D interpolation and returns the approximate function value Chih-Jen Lin (National Taiwan Univ.) 25 / 51

Spline Interpolation XX Homework 8-1: Write a program which can solve general spline problems. Test your program by using some data and compare with the result of Matlab Chih-Jen Lin (National Taiwan Univ.) 26 / 51

Function Approximation I Given data points (x i, y i ), i = 1,..., n Find a function to approximate these points Why not just fitting them? That is, y i = f (x i ), i = 1,..., n. Data have noise. There are outliers Chih-Jen Lin (National Taiwan Univ.) 27 / 51

Function Approximation II Chih-Jen Lin (National Taiwan Univ.) 28 / 51

Function Approximation III If fitting all data, functions are not generalized enough for future use Generalization: Data under some distribution Given some samples, your approximate f has the trend Minimizing the error: min f (y i f (x i )) 2 (10) or min f y i f (x i ) Chih-Jen Lin (National Taiwan Univ.) 29 / 51

Function Approximation IV with f (x) = ax + b Assume x R 1, y R 1 (10): least square approximation why (10): easier calculation Chih-Jen Lin (National Taiwan Univ.) 30 / 51

Least Square Approximation I Finding a and b. Let E = (y i (ax i + b)) 2 Chih-Jen Lin (National Taiwan Univ.) 31 / 51

Least Square Approximation II Then min a,b min a,b min a,b (y i (ax i + b)) 2 y 2 i 2y i (ax i + b) + (ax i + b) 2 2y i (ax i + b) + a 2 x 2 i + 2abx i + b 2 Chih-Jen Lin (National Taiwan Univ.) 32 / 51

Least Square Approximation III ( min ( a,b +( 2y i x i )a + ( 2y i )b + ( ) 2x i )ab + nb 2 x 2 i )a 2 Chih-Jen Lin (National Taiwan Univ.) 33 / 51

Least Square Approximation IV First derivative E a = 0 ( 2y i x i ) + 2( E b = 0 ( 2y i ) + ( x 2 i )a + ( 2x i )b = 0 2x i )a + 2nb = 0 Chih-Jen Lin (National Taiwan Univ.) 34 / 51

Least Square Approximation V Rearrange terms: Define S xx = S xy = x 2 i, S x = x i y i, S y = x i y i Chih-Jen Lin (National Taiwan Univ.) 35 / 51

Least Square Approximation VI Now Then Issues: S xx a + S x b = S xy S x a + nb = S y a = ns xy S x S y ns xx S 2 x b = S xxs y S x S xy ns xx S 2 x Chih-Jen Lin (National Taiwan Univ.) 36 / 51

Least Square Approximation VII Does E = 0 imply optimality? We need secondary derivative (i.e. 2 E) to be positive semi-definite [ E ] 2 E E = a a a b E E [ b a b b] 2Sxx 2S = x 2S x 2n Chih-Jen Lin (National Taiwan Univ.) 37 / 51

Least Square Approximation VIII S xx > 0, n > 0, and determinant: = S xx n Sx 2 1 2 ( x 2 i x i ) 2 0 Remember (a 1 b 1 + + a n b n ) 2 (a 2 1 + + a 2 n)(b 2 1 + + b 2 n) Chih-Jen Lin (National Taiwan Univ.) 38 / 51

Least Square Approximation IX Nonlinear least-square min f E = m (y i f (x i )) 2 with f (x) = ax 2 + bx + c Quadratic least square Now you have three variables and three equations Homework 8-2 1 Write down the three equations of E = 0 Chih-Jen Lin (National Taiwan Univ.) 39 / 51

Least Square Approximation X 2 Write a program doing quadratic least square 3 Randomly generate some (x i, y i ) and draw a figure showing your approximation Chih-Jen Lin (National Taiwan Univ.) 40 / 51

Data in Higher Dimensional Space I If x R m, m > 1 f (x) = a T x + b, a R m Let E = (y i (a T x i + b)) 2 Chih-Jen Lin (National Taiwan Univ.) 41 / 51

Data in Higher Dimensional Space II Then n min (y i (a T x i + b)) 2 a,b min a,b min a,b min n n ( n a,b n y 2 i 2y i (a T x i + b) + (a T x i + b) 2 2y i(a T x i + b) + (a T x i ) 2 + 2ba T x i + b 2y ix i ) T a + ( n (at x i ) 2 + ( n 2y i)b + 2x i) T ab + nb 2 Chih-Jen Lin (National Taiwan Univ.) 42 / 51

Data in Higher Dimensional Space III First derivative E a = 0 ( 2y i x i ) + 2 (a T x i )x i + ( 2x i )b = 0 E b = 0 ( 2y i ) + ( 2x i ) T a + 2nb = 0 Chih-Jen Lin (National Taiwan Univ.) 43 / 51

Data in Higher Dimensional Space IV Note (a T x i )x i = x i xi T : an m by m matrix Define S xx = S xy = x i x T i, S x = y i x i, S y = x i xi T a x i y i Chih-Jen Lin (National Taiwan Univ.) 44 / 51

Data in Higher Dimensional Space V Solve a linear system of a and b [ ] [ ] Sxx S x a Sx T = n b m + 1 variables [ Sxy S y ] Chih-Jen Lin (National Taiwan Univ.) 45 / 51

Application: Time Series Prediction I Given (y 1,, y n ) as known series Predict y n+1,..., Error propagation is the usual difficulty Chih-Jen Lin (National Taiwan Univ.) 46 / 51

A Practical Example I Electricity load forecasting. Given Electricity load per half hour from 1997 to 1998 Average daily temperature from 1995 to 1998 List of holidays Goal: Predict daily maximal load of January 1999 i.e., predict 31 values Chih-Jen Lin (National Taiwan Univ.) 47 / 51

Regression for Time Series Prediction I Finding a function f (x) = a T x + b Consider (y t,, y t 1 ) as attributes (features) of x i y t as the target value y i : usually called embedding dimension Solving (a, b) using (x 1, y 1 ),..., (x n, y n ) One-step ahead prediction Chih-Jen Lin (National Taiwan Univ.) 48 / 51

Regression for Time Series Prediction II Prediction: Starting from the last segment (y n +1,..., y n ) ŷ n+1 Repeat by using newly predicted values Chih-Jen Lin (National Taiwan Univ.) 49 / 51

Evaluation of Time Series Prediction I MSE (Mean Square Error): (y i ŷ i ) 2 MAPE (Mean absolute percentage error) 1 n y i ŷ i y i Error propagation: larger error later Unfair to earlier prediction if MSE is used Chih-Jen Lin (National Taiwan Univ.) 50 / 51

Evaluation of Time Series Prediction II There are other criteria Chih-Jen Lin (National Taiwan Univ.) 51 / 51