34
Interpolation Escuela de Ingeniería Informática de Oviedo (Dpto. de Matemáticas-UniOvi) Numerical Computation Interpolation 1 / 34

Escuela de Ingeniería Informática de Oviedo...Introduction Motivation Often, when solving mathematical problems, we need to get the value of a function in several points. But: it

  • Upload
    others

  • View
    0

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Escuela de Ingeniería Informática de Oviedo...Introduction Motivation Often, when solving mathematical problems, we need to get the value of a function in several points. But: it

Interpolation

Escuela de Ingeniería Informática de Oviedo

(Dpto. de Matemáticas-UniOvi) Numerical Computation Interpolation 1 / 34

Page 2: Escuela de Ingeniería Informática de Oviedo...Introduction Motivation Often, when solving mathematical problems, we need to get the value of a function in several points. But: it

Outline

1 Introduction

2 Lagrange interpolation

3 Piecewise polynomial interpolation

(Dpto. de Matemáticas-UniOvi) Numerical Computation Interpolation 2 / 34

Page 3: Escuela de Ingeniería Informática de Oviedo...Introduction Motivation Often, when solving mathematical problems, we need to get the value of a function in several points. But: it

Introduction

Outline

1 Introduction

2 Lagrange interpolation

3 Piecewise polynomial interpolation

(Dpto. de Matemáticas-UniOvi) Numerical Computation Interpolation 3 / 34

Page 4: Escuela de Ingeniería Informática de Oviedo...Introduction Motivation Often, when solving mathematical problems, we need to get the value of a function in several points. But: it

Introduction

Motivation

Often, when solving mathematical problems, we need to get the value of afunction in several points.

But:

it can be expensive in terms of processor use or machine time (forinstance, a complicated function which we need to evaluate many times).possibly, we only have the function values in few points (for instance, ifthey come from data trials).

A possible solution is to replace the complicated function by another similarbut simpler to evaluate.

These simpler functions are polynomials, trigonometric functions, ...

(Dpto. de Matemáticas-UniOvi) Numerical Computation Interpolation 4 / 34

Page 5: Escuela de Ingeniería Informática de Oviedo...Introduction Motivation Often, when solving mathematical problems, we need to get the value of a function in several points. But: it

Introduction

Interpolation

Data:n + 1 different points x0,x1, . . . , xn

n + 1 values ω0,ω1, . . . , ωn

Problem:

Find a (simple) function f̃ verifying f̃ (xi ) = yi with i = 0,1, . . . ,n.

Remarks:x0,x1, . . . , xn are called interpolation nodesω0,ω1, . . . , ωn can be the values of a function f in the nodes:

ωi = f (xi ) i = 0,1, . . . ,n

(Dpto. de Matemáticas-UniOvi) Numerical Computation Interpolation 5 / 34

Page 6: Escuela de Ingeniería Informática de Oviedo...Introduction Motivation Often, when solving mathematical problems, we need to get the value of a function in several points. But: it

Introduction

ExampleHere, f̃ ≡ P5 is a polynomial of degree 5:

(x0,ω

0)

(x1,ω

1)

(x2,ω

2)

(x3,ω

3)

(x4,ω

4)

(x5,ω

5)

(xi,ω

i)

P5

(Dpto. de Matemáticas-UniOvi) Numerical Computation Interpolation 6 / 34

Page 7: Escuela de Ingeniería Informática de Oviedo...Introduction Motivation Often, when solving mathematical problems, we need to get the value of a function in several points. But: it

Introduction

Polynomial interpolation

If f̃ is a polynomial or a piecewise polynomial function we speak ofpolynomic interpolation.

Main examples:1 Lagrange interpolation.2 Piecewise polynomial interpolation.

(Dpto. de Matemáticas-UniOvi) Numerical Computation Interpolation 7 / 34

Page 8: Escuela de Ingeniería Informática de Oviedo...Introduction Motivation Often, when solving mathematical problems, we need to get the value of a function in several points. But: it

Lagrange interpolation

Outline

1 Introduction

2 Lagrange interpolation

3 Piecewise polynomial interpolation

(Dpto. de Matemáticas-UniOvi) Numerical Computation Interpolation 8 / 34

Page 9: Escuela de Ingeniería Informática de Oviedo...Introduction Motivation Often, when solving mathematical problems, we need to get the value of a function in several points. But: it

Lagrange interpolation

Lagrange interpolation

Data:n + 1 different points x0,x1, . . . , xn

n + 1 values ω0,ω1, . . . , ωn

Problem: We seek for a polynomial Pn of degree at most n verifying

Pn (x0) = ω0 Pn (x1) = ω1 Pn (x2) = ω2 . . . P(n)n (xn) = ωn

(Dpto. de Matemáticas-UniOvi) Numerical Computation Interpolation 9 / 34

Page 10: Escuela de Ingeniería Informática de Oviedo...Introduction Motivation Often, when solving mathematical problems, we need to get the value of a function in several points. But: it

Lagrange interpolation

Lagrange linear interpolation (n = 1)

Data:2 different points x0,x1

2 values ω0,ω1

Problem: Find a polynomial Pn of degree at most 1 verifying

P1 (x0) = ω0 P1 (x1) = ω1

y = P1 (x) is the straight line joining (x0, ω0) and (x1, ω1)

P1 (x) = ω0 +ω1 − ω0

x1 − x0(x1 − x0)

(Dpto. de Matemáticas-UniOvi) Numerical Computation Interpolation 10 / 34

Page 11: Escuela de Ingeniería Informática de Oviedo...Introduction Motivation Often, when solving mathematical problems, we need to get the value of a function in several points. But: it

Lagrange interpolation

Lagrange interpolation (for any n)

Problem: Find a polynomial

Pn (x) = a0 + a1x + a2x2 + · · ·+ anxn

satisfying

Pn (x0) = ω0 Pn (x1) = ω1 Pn (x2) = ω2 . . . Pn (xn) = ωn (1)

Conditions (1) imply that coefficients solve1 x0 x2

0 · · · xn0

1 x1 x21 · · · xn

1...

......

. . ....

1 xn x2n · · · xn

n

a0a1...

an

=

ω0ω1...ωn

(Dpto. de Matemáticas-UniOvi) Numerical Computation Interpolation 11 / 34

Page 12: Escuela de Ingeniería Informática de Oviedo...Introduction Motivation Often, when solving mathematical problems, we need to get the value of a function in several points. But: it

Lagrange interpolation

The coefficient matrix is of Vandermonde type:

A =

1 x0 x2

0 · · · xn0

1 x1 x21 · · · xn

1...

......

. . ....

1 xn x2n · · · xn

n

,

withdet (A) =

∏0≤l≤k≤n

(xk − xl ) 6= 0.

Therefore, the system has a unique solution which determines Pn.

Pn is the Lagrange interpolation polynomial at x0,x1, . . . , xn relative to thevalues ω0,ω1, . . . , ωn.

(Dpto. de Matemáticas-UniOvi) Numerical Computation Interpolation 12 / 34

Page 13: Escuela de Ingeniería Informática de Oviedo...Introduction Motivation Often, when solving mathematical problems, we need to get the value of a function in several points. But: it

Lagrange interpolation

An example of Lagrange interpolation

(xi,ω

i)

P1(x)

(xi,ω

i)

P2(x)

(xi,ω

i)

P3(x)

(xi,ω

i)

P4(x)

(Dpto. de Matemáticas-UniOvi) Numerical Computation Interpolation 13 / 34

Page 14: Escuela de Ingeniería Informática de Oviedo...Introduction Motivation Often, when solving mathematical problems, we need to get the value of a function in several points. But: it

Lagrange interpolation Computing the Lagrange’s interpolation polynomial

Computing the Lagrange’s interpolationpolynomial

Motivation:Solving the Vandermonde system of equations is not efficient and large errorsmay arise due to bad conditioning.

Two ways of computing:

Using fundamental Lagrange polynomials.Using divided differences.

(Dpto. de Matemáticas-UniOvi) Numerical Computation Interpolation 14 / 34

Page 15: Escuela de Ingeniería Informática de Oviedo...Introduction Motivation Often, when solving mathematical problems, we need to get the value of a function in several points. But: it

Lagrange interpolation Computing the Lagrange’s interpolation polynomial

Fundamental Lagrange polynomialsFundamental polynomials:For each i = 0,1, . . . ,n there exists an unique polynomial `i of degree at mostn such that `i (xk ) = δik (zero if i 6= k , one if i = k ):

`i (x) =n∏

j = 0j 6= i

x − xj

xi − xj,

`0, `1, . . . , `n are the fundamental Lagrange polynomials of degree n.

Lagrange formula:Lagrange’s polynomial at x0,x1, . . . , xn relative to ω0,ω1, . . . , ωn is

Pn (x) = ω0`0 (x) + ω1`1 (x) + · · ·+ ωn`n (x) .

Remark: If we want to add new nodes, we need to re-compute all thefundamental polynomials.

(Dpto. de Matemáticas-UniOvi) Numerical Computation Interpolation 15 / 34

Page 16: Escuela de Ingeniería Informática de Oviedo...Introduction Motivation Often, when solving mathematical problems, we need to get the value of a function in several points. But: it

Lagrange interpolation Computing the Lagrange’s interpolation polynomial

Example

0 1 2 3 4−2

−1

0

1

2

3

l0(x)

0 1 2 3 4−2

−1

0

1

2

3

l1(x)

0 1 2 3 4−2

−1

0

1

2

3

l2(x)

0 1 2 3 4−2

−1

0

1

2

3

ω0 l

0(x)

0 1 2 3 4−2

−1

0

1

2

3

ω1 l

1(x)

0 1 2 3 4−2

−1

0

1

2

3

ω2 l

2(x)

0 1 2 3 4−2

−1

0

1

2

3

P2(x)

(Dpto. de Matemáticas-UniOvi) Numerical Computation Interpolation 16 / 34

Page 17: Escuela de Ingeniería Informática de Oviedo...Introduction Motivation Often, when solving mathematical problems, we need to get the value of a function in several points. But: it

Lagrange interpolation Computing the Lagrange’s interpolation polynomial

Divided differences

Divided differences of 0-order

[ωi ] = ωi , i = 0,1, . . . ,n.

Divided differences of order 1

[ωi , ωi+1] =ωi+1 − ωi

xi+1 − xi, i = 0,1, . . . ,n − 1.

Divided differences of order 2

[ωi , ωi+1, ωi+2] =[ωi+1, ωi+2]− [ωi , ωi+1]

xi+2 − xi, i = 0,1, . . . ,n − 2.

Divided differences of order k (k = 1, . . . ,n)

[ωi , ωi+1, . . . , ωi+k ] =[ωi+1, . . . , ωi+k ]− [ωi , ωi+1, . . . , ωi+k−1]

xi+k − xi,

i = 0,1, . . . ,n − k .

(Dpto. de Matemáticas-UniOvi) Numerical Computation Interpolation 17 / 34

Page 18: Escuela de Ingeniería Informática de Oviedo...Introduction Motivation Often, when solving mathematical problems, we need to get the value of a function in several points. But: it

Lagrange interpolation Computing the Lagrange’s interpolation polynomial

Newton’s formula:Lagrange polynomial at x0,x1, . . . , xn relative to ω0,ω1, . . . , ωn is

Pn (x) = [ω0] + [ω0, ω1] (x − x0) + [ω0, ω1, ω2] (x − x0) (x − x1) + · · ·++ [ω0, ω1, . . . , ωn] (x − x0) (x − x1) · · · (x − xn−1) .

Consequence:P0,P1, . . . ,Pn may be computed recursively, adding in each iteration a newterm,

Pn (x) = Pn−1 (x) + [ω0, ω1, . . . , ωn] (x − x0) (x − x1) · · · (x − xn−1) .

Notation:If ωi = f (xi ), with i = 0,1, . . . ,n,

f [xi , . . . , xi+k ] = [ωi , . . . , ωi+k ] .

(Dpto. de Matemáticas-UniOvi) Numerical Computation Interpolation 18 / 34

Page 19: Escuela de Ingeniería Informática de Oviedo...Introduction Motivation Often, when solving mathematical problems, we need to get the value of a function in several points. But: it

Lagrange interpolation Computing the Lagrange’s interpolation polynomial

Example

P1(x) P

2(x)

P3(x) P

4(x)

(Dpto. de Matemáticas-UniOvi) Numerical Computation Interpolation 19 / 34

Page 20: Escuela de Ingeniería Informática de Oviedo...Introduction Motivation Often, when solving mathematical problems, we need to get the value of a function in several points. But: it

Lagrange interpolation Error

Error

Hypothesis:f : [a,b]→ R is n + 1 times differentiable in [a,b] with continuousderivatives.x0, x1, . . . , xn ∈ [a,b] .

ωi = f (xi ) for i = 0,1, . . . ,n.

Error estimate: The absolute error satisfies

|f (x)− Pn (x)| ≤ supy∈[a,b]

∣∣∣f (n+1) (y)∣∣∣ |(x − x0) (x − x1) · · · (x − xn)|

(n + 1)!.

(Dpto. de Matemáticas-UniOvi) Numerical Computation Interpolation 20 / 34

Page 21: Escuela de Ingeniería Informática de Oviedo...Introduction Motivation Often, when solving mathematical problems, we need to get the value of a function in several points. But: it

Piecewise polynomial interpolation

Outline

1 Introduction

2 Lagrange interpolation

3 Piecewise polynomial interpolation

(Dpto. de Matemáticas-UniOvi) Numerical Computation Interpolation 21 / 34

Page 22: Escuela de Ingeniería Informática de Oviedo...Introduction Motivation Often, when solving mathematical problems, we need to get the value of a function in several points. But: it

Piecewise polynomial interpolation

Piecewise polynomial interpolation

Motivation:If we increase the number of nodes

The Lagrange’s interpolation polynomial degree increases as well,generating oscillations.

Often, when increasing the number of nodes the error also increases (notintuitive).

Estrategy:Use low degree piecewise polynomials.

(Dpto. de Matemáticas-UniOvi) Numerical Computation Interpolation 22 / 34

Page 23: Escuela de Ingeniería Informática de Oviedo...Introduction Motivation Often, when solving mathematical problems, we need to get the value of a function in several points. But: it

Piecewise polynomial interpolation

Example: oscillations of Lagrange polynomials

e−x

2

(xi,ω

i)

P10

(x)

(Dpto. de Matemáticas-UniOvi) Numerical Computation Interpolation 23 / 34

Page 24: Escuela de Ingeniería Informática de Oviedo...Introduction Motivation Often, when solving mathematical problems, we need to get the value of a function in several points. But: it

Piecewise polynomial interpolation

Example: piecewise linear interpolation

e−x

2

(xi,ω

i)

s

(Dpto. de Matemáticas-UniOvi) Numerical Computation Interpolation 24 / 34

Page 25: Escuela de Ingeniería Informática de Oviedo...Introduction Motivation Often, when solving mathematical problems, we need to get the value of a function in several points. But: it

Piecewise polynomial interpolation

Constantwise polynomial interpolation

Interpolation by degree zero piecewise polynomials is that in which thepolynomials are constant between nodes. For instance,

f̃ (x) =

ω0 if x ∈ [x0, x1),ω1 if x ∈ [x1, x2),. . .ωn−1 if x ∈ [xn−1, xn),ω0 if x = xn.

Observe that if ωi 6= ωi+1 then f̃ is discontinuous at xi+1.

(Dpto. de Matemáticas-UniOvi) Numerical Computation Interpolation 25 / 34

Page 26: Escuela de Ingeniería Informática de Oviedo...Introduction Motivation Often, when solving mathematical problems, we need to get the value of a function in several points. But: it

Piecewise polynomial interpolation

Linearwise polynomial interpolation

The degree one piecewise polynomial interpolation is that in which thepolynomials are straight lines joining two consecutive nodes,

f̃ (x) = ωi + (ωi+1 − ωi )x − xi

xi+1 − xiif x ∈ [xi , xi+1],

for i = 0, . . . ,n − 1.

In this case, f̃ is continuous, but its first derivative is, in general, discontinuousat the nodes.

(Dpto. de Matemáticas-UniOvi) Numerical Computation Interpolation 26 / 34

Page 27: Escuela de Ingeniería Informática de Oviedo...Introduction Motivation Often, when solving mathematical problems, we need to get the value of a function in several points. But: it

Piecewise polynomial interpolation

Spline interpolation

Data:n + 1 points x0 < x1 < . . . < xn.

n + 1 values ω0, ω1, . . . , ωn.

Problem: Interpolating by splines of order p (or degree p) consists on findinga function f̃ such that:

1 f̃ is p − 1 times continuously differentiable in [x0, xn].2 f̃ is a piecewise function given by the polynomials f̃0, f̃1, . . . , f̃n−1 defined,

respectively, in [x0, x1] , [x1, x2] , . . . , [xn−1, xn], and of degree lower orequal to p.

3 Interpolation condition: f̃0 (x0) = ω0, . . . , f̃n (xn) = ωn.

(Dpto. de Matemáticas-UniOvi) Numerical Computation Interpolation 27 / 34

Page 28: Escuela de Ingeniería Informática de Oviedo...Introduction Motivation Often, when solving mathematical problems, we need to get the value of a function in several points. But: it

Piecewise polynomial interpolation

The problem has solution!Each solution f̃ is called spline interpolator of order p at x0,x1, . . . , xnrelative to ω0,ω1, . . . , ωn.

The most used spline is that ot third order, known as cubic spline.

(Dpto. de Matemáticas-UniOvi) Numerical Computation Interpolation 28 / 34

Page 29: Escuela de Ingeniería Informática de Oviedo...Introduction Motivation Often, when solving mathematical problems, we need to get the value of a function in several points. But: it

Piecewise polynomial interpolation Cubic spline

Example

sin(x)

Lineal

Spline

(Dpto. de Matemáticas-UniOvi) Numerical Computation Interpolation 29 / 34

Page 30: Escuela de Ingeniería Informática de Oviedo...Introduction Motivation Often, when solving mathematical problems, we need to get the value of a function in several points. But: it

Piecewise polynomial interpolation Cubic spline

Cubic spline

Definition:A Cubic spline is a function f̃ such that

1 f̃ is twice continuously differentiable in [x0, xn].2 f̃0, f̃1, . . . , f̃n−1 are of degree at most 3.3 f̃ (x0) = ω0 f̃ (x1) = ω1 . . . f̃ (xn) = ωn

Remarks:

In each sub-interval [xi , xi+1], the interpolant f̃ is determined from thevalues of f̃ ′′ at xi and xi+1.Such values (f̃ ′′(xi ) and f̃ ′′(xi+1)) are obtained by solving a linear systemof equations.

(Dpto. de Matemáticas-UniOvi) Numerical Computation Interpolation 30 / 34

Page 31: Escuela de Ingeniería Informática de Oviedo...Introduction Motivation Often, when solving mathematical problems, we need to get the value of a function in several points. But: it

Piecewise polynomial interpolation Cubic spline

Computing the cubic spline

Task: Deduce an algorithm to compute the cubic spline.

By definition, f̃ ′′ is continuous in [x0, xn]. Therefore

ω′′0 = f̃ ′′0 (x0)

ω′′1 = f̃ ′′0 (x1) = f̃ ′′1 (x1)

ω′′2 = f̃ ′′1 (x2) = f̃ ′′2 (x2)· · · · · · · · ·ω′′n−1 = f̃ ′′n−2 (xn−1) = f̃ ′′n−1 (xn−1)

ω′′n = f̃ ′′n−1 (xn)

(Dpto. de Matemáticas-UniOvi) Numerical Computation Interpolation 31 / 34

Page 32: Escuela de Ingeniería Informática de Oviedo...Introduction Motivation Often, when solving mathematical problems, we need to get the value of a function in several points. But: it

Piecewise polynomial interpolation Cubic spline

Integrating twice, we get

f̃i (x) = ω′′i(xi+1 − x)3

6hi+ ω′′i+1

(x − xi )3

6hi+ ai (xi+1 − x) + bi (x − xi ) ,

whereai =

ωi

hi− ω′′i

hi

6, bi =

ωi+1

hi− ω′′i+1

hi

6.

Therefore, once ω′′i are known, the cubic spline is fully determined.

Using that f̃ is twice continuously differentiable gives the n−1 linear equations

hi

6ω′′i +

hi+1 + hi

3ω′′i+1 +

hi+1

6ω′′i+2 =

ωi

hi−( 1

hi+1+

1hi

)ωi+1 +

ωi+2

hi+1.

For full determination of the n + 1 values ω′′i we need two additional equations.

(Dpto. de Matemáticas-UniOvi) Numerical Computation Interpolation 32 / 34

Page 33: Escuela de Ingeniería Informática de Oviedo...Introduction Motivation Often, when solving mathematical problems, we need to get the value of a function in several points. But: it

Piecewise polynomial interpolation Cubic spline

Natural cubic spline:There are several options to determine uniquely the cubic spline, for instance

adding two equations to close the system,fix the value of two unknowns.

If the values of ω′′0 and ω′′n are fixed, we talk about natural splines. In this case,ω′′in = (ω1, . . . , ωn) are solution of Hω′′in = 6d, where

d = (∆1 −∆0, . . . ,∆n−1 −∆n−2), with ∆i = (ωi+1 − ωi )/hi ,

H =

2 (h0 + h1) h1 0 · · · 0 0

h1 2 (h1 + h2) h2 · · · 0 0...

......

. . ....

...0 0 0 · · · 2 (hn−3 + hn−2) hn−20 0 0 · · · hn−2 2 (hn−2 + hn−1)

.

(Dpto. de Matemáticas-UniOvi) Numerical Computation Interpolation 33 / 34

Page 34: Escuela de Ingeniería Informática de Oviedo...Introduction Motivation Often, when solving mathematical problems, we need to get the value of a function in several points. But: it

Piecewise polynomial interpolation Error

Error

Hypothesis:f : [a,b]→ R is four times continuously differentiable in [a,b] .

x0, x1, . . . , xn ∈ [a,b] .

Error estimation:Let h̃ = max

i=0,...,nhi . Then, for all x ∈ [a,b] we have

∣∣∣f (x)− f̃ (x)∣∣∣ ≤ ch̃p+1 max

y∈[a,b]

∣∣∣f (p+1) (y)∣∣∣ ,

where c is a constant independent of f , x and h̃.

(Dpto. de Matemáticas-UniOvi) Numerical Computation Interpolation 34 / 34