You are on page 1of 60

Chapter 4

Interpolating polynomial and curve fitting


V . interpolate
Notations.
N .

Interpolation
1. Πn = set of all single-variable polynomials of degree n or less.
e .

g . T1
=

(ax b/a
+

,
be (R3
ex+ 1 Te
·
x Te
1G Te To ? T T2 ...

2. pn (or qn, or rn) = a single-variable polynomial of degree n or

less. 8,
=

2 x +

1
e .
g .

I 1
10
=

2
X
r2
=

Review. The system of linear equations

A!x = !b
I- )(ii)=(]
or invertible
has exactly one solution if and only if A is non-singular.
.

Note. A is non-singular if and only if det A != 0

1
1. Polynomial interpolation

Examples

1. Find a polynomial p through (1, 3) satisfying the following

conditions. y (1 , 3)
-
-

(a) p is of degree 0. - Po
- Pi
Po(X)
=

3 I >X

(b) p is of degree 1. Let P ,(x)


=
ax +
b
p , x) passes through (1 31
, .

P , (X) =

ax +
(3 -
a)
Therefore 3 =
all + b
I a GIR a F
O
= b = 3 -
a ,

2. Find a polynomial q through (1, 3) and (2, 5) satisfying the

following conditions.

(a) q is of degree 0.

No solution .

g , (x) ax b
(b) q is of degree 1. Let
+
=

a(l) b 3 b b
[2a
a
=

a
E
3
+ + =

2 1
=

=
=

=> =>
,

a(2) 1 +
b 5
5
=
+ =

Therefore , G (x)
=

2x +
1
2
,
-
* (2 5)
(1 , 3) ,

(c) q is of degree 2.
Let & ,(x)
=
ax bx + +
c
b c 3b =
2 -

39
E
a
=
+ +

[
a(1) b() c 3
[4a
= =
+ +

c =

1 29
2b
=> +

=>
+
c =
5
a(22) +
b(z) +
c
=
5

ax (2 3a) x (1 2a) , a + 0 AGIR


q2(x)
+
=
+ +
-

3. Find a polynomial r through (1, 3), (2, 5), and (4, 7) satisfying

the following conditions.

(a) r is of degree 0.

N solution

(b) r is of degree 1.
(1 , 31 , (2 , 5) (4 , 7)
solution
,
No

Let ax bx c
(c) r is of degree 2. 82(x)
= + +

b c 3 *
=

=
a + +

E 4a 2b + 5
=

r(x) x
3x+
+
= -
=
= +

169 +

4b +
c =

7 c =

3
(d) r is of degree 3.

((x)
=

ax +

(-Exa)x2 +

(3 +

14a) x +

(1 )
a =O a G IR
3 ,
Questions. Suppose there are n+1 points (x0, y0), (x1, y1), . . . , (xn, yn)

where x0, x1, . . . , xn are distinct.

1. Can we find a polynomial of degree less than n through all

these points?

No
,
except special case .

2. How many polynomial of degree n that passes through all

these points? ↓ of them .

3. How many polynomials of degree n + 1 or more that passes

through all these points?


Infinitely many .

4
Definitions.

Interpolation = the process of finding a function that goes through

a set of distinct points.

Polynomial interpolation = the process of finding


polynomial goes through a
a
that set

Interpolation methods.
of distinct points .

Te
Find a polynomial in P
X3 that goes through (0, 5), (1, 1), (2, −3), (3, −1).
1. Method I. Use direct approach. Let

p3(x) = ax3 + bx2 + cx + d.

0 a 0 b 0 c d 5 a 1

E
=
. =
+

S
+ +
. .

7 a +

b +
c d =

1 b = -
3
I
+

C = 2
+b
-

8a +
+
22 +
d = -
3
a =
5
27a +
ab +
3c + d =
-
1

so
, Py(X)
=

x -
3x2 -
2x +
5

5
10, 5) (1 , 1) (2 -3) [3 -1)
, , , , ,

2. Method II. Use a more convenient form. Consider

q3(x) = γ0 +γ1(x−0)+γ2(x−0)(x−1)+γ3(x−0)(x−1)(x−2).

Then, we can solve for γ0, γ1, γ2, γ3 as following:

(a) Plug-in (0, 5) to get Wo 5


=

(b) Plug-in (1, 1) to get Vo


+
8-(1 0) - =
1

U
-
4
W 1
= =

- 1
=

5
+

(c) Plug-in (2, −3) to get 00


+
8 , (2 -0) +

02(2 0)(2-1)
-
=
-

5 +

( -
4)(2) +

We(2)(1) = -

=>

U2 =
0
iy

(d) Plug-in (3, −1) to get + " +


ris"(-1)
+ U
,
(3 0)(3 1)(3 2)
-
- -
=
-

Uz 1
=
=>

=>
Gz(x) =

5 +
( 4)(X 0)
-
- +

0(x 0)(X 1) - -
+
(1)(X 0)(X 1)(X 2)
-
- -

Question. Is q3(x) = p3(x)?


Yes , 1, show
:

Ps .
can
by
expanding i ,
and simplify
to ge P3 .

(See next page)


6
qz(x) =

5 +
( 4)(X 0)
-
- +

0(X 0)(X 1)
- -
+
(1)(X 0)(X 1)(X 2)
-
- -

5 -

4x
+
x(x2 -

3x +

2)
5 x3 3x2
=

4X +

2x
-
- +

x3 -
3x2 -

2x +
5

4 (4)
=

,
Points (0, 5) 11 1) (2 -3) (3 1)
-

:
, , , , , ,
(40s Y0) , <41 , 31) 33) , (X2 , %2) , (Xs ,

3. Method III. Use a combination of some special polynomials.


Y0 0
X 1 X2
=

2 xz =
3
Consider
=

, , , ,

Yo 5 y, 3, 43 1
1 y
-
= -

, =

, =

r3(x) = 5#0(x) + 1#1(x) + (−3)#2(x) + (−1)#3(x)


Y((x0) x1
50x0) 1
20) 320) ex
=

+ . -
-

where
lo(Xo) 1
2 Xo) =
0 - 5
= ,

#0(0) = 1, #1(0) = 0, #2(0) = 0, #3(0) = 0,

#0(1) = 0, #1(1) = 1, #2(1) = 0, #3(1) = 0,

#0(2) = 0, #1(2) = 0, #2(2) = 1, #3(2) = 0,

#0(3) = 0, #1(3) = 0, #2(3) = 0, #3(3) = 1.

If we can find #0, #1, #2, #3 that satisfy the properties above,

locx) =
then we are done. X-3)
Yo 0

(o -
1)(0 -

2) (0-3)
x, 1
(i) Find #0(x) satisfying
=

xe = 2

(I) #0(0) = 1,
From (I)-(IE) we get
x= =

3 ,

(I) #0(1) = 0, le(x) = k(x 1)(X 2)(X - -


-

3)

From (I) k (0-1)(0-2)(0-3)


(I) #0(2) = 0, 7
=

(E) #0(3) = 0. => k = --


(0-1)(0-2) (0- 3)

7
(ii)
Yo 0
(x − 0)(x − 2)(x − 3)
#1(x) = ,
x, =

1 (1 − 0)(1 − 2)(1 − 3)
(x − 0)(x − 1)(x − 3)
xe = 2 #2(x) = ,
(2 − 0)(2 − 1)(2 − 3)
x3 =

3 (x − 0)(x − 1)(x − 2)
#3(x) = .
(3 − 0)(3 − 1)(3 − 2)

ans r3(x) = 5#0(x) + 1#1(x) + (−3)#2(x) + (−1)#3(x).

Question. Is r3(x) = p3(x)?

Ans Yes, we can expand is


and
simplify to show that B =

P .

conclusion

bet same answer for any


method .

8
Conclusion.

Given n+1 points (x0, y0), (x1, y1), . . . , (xn, yn) where x0, x1, . . . , xn

are distinct, we can find the polynomial of degree n through these

point using the following methods:

1. Solve full system of linear equations for the coef-

ficients (Method I).

Write

pn(x) = anxn + an−1xn−1 + . . . + a1x + a0.

Then, we can solve for an, an−1, . . . , a1, a0 from

y0 = anxn0 + an−1xn−1
0 + . . . + a1x0 + a0,

y1 = anxn1 + an−1xn−1
1 + . . . + a1x1 + a0,

...

yn = anxnn + an−1xn−1
n + . . . + a1 x n + a0 .

We point out that this method is not recommended especially

for large n. However, the approach is useful for theoretical

results.

9
2. Newton’s method (Method II).

Write pn(x) as

pn(x) = γ0 + γ1(x − x0) + γ2(x − x0)(x − x1)

+ γ3(x − x0)(x − x1)(x − x2) + . . . + γn(x − x0) · · · (x − xn−1),

then solve for γ0, …, γn in that order by plugging-in (x0, y0), . . . , (xn, yn),

one point at a time.

Note: the system is lower triangular, so we can solve for the

unknown coefficients using forward substitution.

Fox-y) xi)(e) ...


x-

10
3. Lagrange’s method (Method III).

Write pn(x) in the form Text :


lox)
pn(x) = y0#n,0(x) + y1#n,1(x) + . . . + yn#n,n (x),

where

(x − x0)(x − x1) . . . (x − xi−1)(x − xi+1) . . . (x − xn)


#n,i(x) = .
(xi − x0)(xi − x1) . . . (xi − xi−1)(xi − xi+1) . . . (xi − xn)

We will get that

#n,i(xi) = 1,

#n,i(xj ) = 0, j != i.

The properties of #n,i above allow pn(x) to interpolate all of

the given points.

11
-> 83
Ex Find
polynomial that
goes through
1-2 , 11 10, 3) (4 , 7) (5 , 3)
, , ,

-in q , (x) 00 U (x 2) ((X 2)(X 0)


+ +
= + +

, -

+
v(x +

2)(X -

0)(X -

4)

①(x , y) =
( -
2 1) = Vo
=

1
,

② (X , y) =
(0 3) =
0 +
U (0 +
2) =

3 =
1 +
20 =
3
, x
, ,
=>
W =

, 1

③ (X , y) =
(4 , 7) =
8 +
2 (4
,
+

2) +

82(4 2)(4 0) +
-
=

7
1(6) Uz(b)(4)
=>

1 7
+ +

= U2 =
0

④ (X, y) =

(5 3) =
Vo +
0
, (5 +
2) +

02 (5 2)(5 0)+
-

+
U3(5 2)(5 0)(5 4) 3
+
- - =

= 1 1(7) 0 Vy(7)(5)(1) 3
+ + +
=

03
2
=> -
=

Therefore
, q,(x) =
1 +

(x +

2) -

I(x +
2)(X - 0)(X -

4)
Simplify :

q,(x) =
1 +

(x +

2) -

I(x +
2)(X 0)(X
-
-

4)

1
I(x3 2x2 8x)
=

x +

2 -
-
-

x3
2x2 Ex
= - +
+
+

goes through the points


1-2 , 11 10, 3) (4 , 7) (5 , 3)
, , ,
-example : Use Lagrange method

to find a
polynomial is that
goes through
1-2 , 11 10, 3) (4 , 7) (5 , 3)
, , ,
2
Xo x1 Y2 4 5
-
=
0
xz
=
= =

sation , , ,

r(x)
=
1 .(x) +
3-l ,"(x) +

7 -
l(x) +

3 .

l,)
(X 0)(X 4)(X 5)
lo"(X)=
- - -

where -

0)( 2 4) 2 5)
(
-

2
-
- - -

e" 2)(X 4)(X 5)


-
-

(x +

(0 +

2)(0 -

4) (0-5)

e"(x)
0)(x 5)
-
-

(4 2)(4 0)(4 5)
+
- -

e,(x) =
( )(X-4)
(5 2)(5 + -
0)(5 -

4)

=
Tz(X) =
1 . -4)(X 5) - -

( - 2 -
0)( -
2 -

4) - 2 -

5)

5)
+ 34)(X- e
(x +
2)(x - 0) (x -

5)
(0 +
2)(0-4)(0- 5) (4 2)(4 0)(4+ - -

5)

y()(X 4)
-

+
2)(5 0)(5
(5 + -
-

4)
Divided difference (40 40)
, , - .., (Xn , Yn)
Recall the Newton’s method

pn(x) = γ0 + γ1(x − x0) + γ2(x − x0)(x − x1)

+ γ3(x − x0)(x − x1)(x − x2) + . . . + γn(x − x0) · · · (x − xn−1)

(1)

By plugging-in (xi, f (xi)), i = 0, 1, . . . , n, one at a time, we get

γ0 = f (x0),
f (x1) − f (x0)
γ1 = ,
x1 − x0

is its
... -


-

E ↑

E Xz-
x1

Uz =
E -
- Xe -

Xo W

W
f(x3) f(xe)
fo
-

-
f(xa)-f(x ) ifexa)-fex
, , )
-

X
x2 x2 x +
-

- Xz x1
-
-

7

X3 x1
-

------
~

xo -

Uz
=

X -

Yo
3

i 12
Define the divided difference recursively as

General case : f [x
f [x1 . . . xn] − f [x0x1 . . . xn−1]
0 x1 . . . x n ] = ,
xn − x0

Base case : f [x0] = f (x0).

The coefficients in (1) can then be written as

γ0 = f [x0], =
f(xo)

f.
+2x)
-

γ1 = f [x0x1], - =

x, -
xo
γ2 = f [x0x1x2],

!
...

γn = f [x0x1 . . . xn].

rz
f [xxxi
=

Xc -
X
,
X
,
-

Xo
-
-

Xe -

Xo

13
Example (revisitted)

Find
polynomial &z that
goes through
1-2 , 11 10, 3) (4 , 7) (5 , 3)
, , ,

-in q , (x) 00 U (x 2) ((X 2)(X 0)


+ +
= + +

, -

+
v(x +

2)(X -

0)(X -

4)

X y 22
f2 -

0)
=

vo 2,
f(
-

0
21
Y
=

2 ,0 ,
4)
f
-

> 31 0
=

- 1
O 3 0 -( 2) I
7 ⑧ 53
-

> 73 1 4 ( - 2)
-

-
=

47
4 -
0

S 1
-

=-1
>
53 3 = -

4 5 -
0

11

↑ ( - 2 0, 4 5)
, ,

Therefore
, q (x)
,
=
1 +

(x +

2) -

I(x +
2)(X - 0)(X -

4)
Example. Find Newton polynomial for the data below.

x 3 1 5 6

f(x) 1 -3 2 4

U(X 3) re(X 3)(x 1)


-

P , (x)
- -

26
+ +
=

3)(X 1)(X 5)
Uy(x
-
-
-
+

↳-
D
x I f23] fan
vo


51 f 23 453
,
3 1
=

3 02
O
-
-

↳ -
2
1 3


-

1
-
3
Us
I 2 3
=
2) t
+

5 2 5 -

>
,
=
2) =
6 4 20

abs
f ,, 5 ,s

Py(x) 1 2(X 3) z(X 3)(X 1) E(X 3)(x 1)(x 5)


- -
+
- + -
-
-
=
-

40

14
Polynomial interpolation theorems.

Theorem 1. (Existence and uniqueness.)

Let x0, x1, . . . , xn be distinct points and let y0, y2, . . . , yn be asso-

ciated function values. There exists a unique polynomial pn(x) ∈

Pn that interpolates yi at xi for i = 0, 1, . . . , n.

Proof. We let

pn(x) = a0 + a1x + . . . + an−1xn−1 + anxn

Because pn interpolates yi at xi for i = 0, 1, . . . , n, we have that

pn(xi) = yi for i = 0, 1, . . . , n. That is,

a0 + a1x0 + . . . + an−1xn−1
0 + anxn0 = y0

a0 + a1x1 + . . . + an−1xn−1
1 + anxn1 = y1

...

a0 + a1xn + . . . + an−1xn−1
n + anxnn = yn

The system can be written in vector form as

Vn!a = !y

15
where
     
1 x0 x20 · · · xn0   a0   y0 
     
     
 2
x1 x1 · · · x1  n   a1   y1 
1    
Vn =  , !a =  , !y =  
 .. ... ... . . . ...   ...   ... 
.
     
    
     
1 xn x2n · · · xnn an yn

The matrix Vn is called Vandermonde matrix. Its determinant

is given by
'
detVn = (xi − xj )
i>j

We can conclude that the solution !a of Vn!a = !y exists and is

unique because det Un #O Since xi = X


;

whenever i =j -

16
Theorem 2. (Error analysis.)

Let x0, x1, . . . , xn be distinct points and let f be a given real

values function with n + 1 continuous derivatives on the inter-

val I(x) = [a, b] where a = min {x0, x1, . . . , xn, x} and b =

max {x0, x1, . . . , xn, x}. Let pn(x) be the interpolating polyno-

mial of f at x0, x1, . . . , xn. Then, there exists ξx ∈ [a, b] such

that
ωn+1(x) (n+1)
f (x) − pn(x) = f (ξx),
(n + 1)!
where ωn+1 = (x − x0)(x − x1) · . . . · (x − xn).

17
0 4741213 + 0 4785665
109
.

(3 005).
-
-
.

, 2
Example.
4748439
* 0
=

x 3.00 3.01 3.02 3.03 3.04 3.05

log10 x 0.4771213 0.4785665 0.4800069 0.4814426 0.4828736 0.4842998

Claim. Let p1(x) be a linear function interpolating f (x) = log10 x

at any two consecutive points from 1.00, 1.01, 1.02, 1.03, . . . , 9.99.

Then,

|f (x) − p1(x)| ≤ 5.42 × 10−6, 1 ≤ x ≤ 10.

Proof. f 109 , X

-
=

~ · P, x
,

18
* sooro2
Special cases.

1. Equally-spaced points.
b−a
Let xi = a + ih, i = 0, . . . , n where h = . We can
h
n!
show that, for x ∈ [a, b], |ωn+1(x)| ≤ hn+1 . Therefore, we
4
have that

hn+1
|f (x) − pn(x)| ≤ max f (n+1) (x)
4(n + 1) x∈[a,b]

2. Chebyshev points. ([a, b] = [−1, 1])

The Chebyshev polynomials are defined recursively by

T0(x) = 1, T1(x) = x, Tn+1(x) = 2xTn(x)−Tn−1(x), n ≥ 1

The Chebyshev points (or nodes) are the zeros of Tn+1, given
( 2i+1 )
by xi = cos 2n+2 π , i = 0, . . . , n. In this case, ωn+1(x) =

Tn+1(x), and we can show that |Tn+1(x)| ≤ 2−n for x ∈

[−1, 1]. Therefore, we have

1
|f (x) − pn(x)| ≤ n
max f (n+1) (x)
2 (n + 1)! x∈[a,b]

19
Interpolation using other functions.

Given three data points (x0, y0), (x1, y1), (x2, y2).

1. Rational function.
* *
* *
* y0 x0 − x (x0 − x)y0 **
*
* *
* *
* y1 x1 − x (x1 − x)y1 **
*
* *
* *
* y2 x2 − x (x2 − x)y2 *
r(x) = * *
* *
* 1 x0 − x (x0 − x)y0 **
*
* *
* *
* 1 x1 − x (x1 − x)y1 **
*
* *
* *
* 1 x2 − x (x2 − x)y2 *

2. Trigonometry function.

sin 12 (x − x1) sin 12 (x − x2)


t(x) = y0 1
sin 2 (x0 − x1) sin 12 (x0 − x2)
sin 12 (x − x0) sin 12 (x − x2)
+ y1 1
sin 2 (x1 − x0) sin 12 (x1 − x2)
sin 12 (x − x0) sin 12 (x − x1)
+ y2 1
sin 2 (x2 − x0) sin 12 (x2 − x1)

20
1st degree
poly nomial
* 3. Piecewise Polynomial. For example, piecewise0
linear in-

terpolation.

IM
-

piecewise

quadratic
interpolation

Exercises. call it f(x)


-
1. Find a piecewise linear function that goes through (1, 1), (2, −3),
-

(3, −1). Is the answer unique?

(1 1)
,
Can show that


(3
,
-

1)
-
4x
+

5 x 21 , 2)

(
f(x) =
,

2x 7 x G 22, 3]
-

,
(2 -3)
,

Canurio)
Note The is
.
answer
unique .

21
(1 , 1)
in miknntmowogres

9 [fex)
b 23
ax x = [1 ,
=
+


13, -1) ,
f(x) =


fz(x) =
(x + d
,
x E 22 3]
,

(2 -3)
,
ve on a
,
b
,
c
,
d dist

① us fe(x) : dres f einwon ( 1) 110 =


,
(2-3)

Is is tay myatturce resumes owmes

Taiwa 2
paruwa on Pre mi

0 fe(x) =

Wo
+
U
,
(x-1)

Ing 8
=

1
, 0,
=
= = -

4
2 -
1

EN f(x) =
1
-

4(X -

1) = -

4x +
5

② F2(X) : 65 f a wa (2 ,
-3) 110 =
(3, -

1)
Penrose (ar fa(x)
3
= - +

- )(X-2)
-

(3 2)
-

· q(f2(X) =

24-7
2. Find a piecewise quadratic function that goes through (1, 1),

(2, −3), (3, −1). Is the answer unique?

Find b d such that


->
a
, ,
c
, ,
e
, g

b E [1 , 23
[f(x)
=
ax + x +
c
,
x
f(x) =

f2(x) =

dx +
ex +

9, x G [2 , 3]

goes through 21 1)
, ,
(2 -3)
, ,
(3, -1) .

sanucrot(
Note that the answer is NOT unique .

(see picture for example . I


order to
In get

... to
smooth graph at

the connecting ,
point

we need to choose

fo ,
f such that
,

connecting point
22
fi(2) fz'(2) =

x
=

2 (We call it spline ) .


2. Find a piecewise quadratic function that goes through (1, 1),

(2, −3), (3, −1). Is the answer unique?

t
isn't

(2 -3)
,

riccovogue
ax + b x E [1 , 23
[f(x)
=
+
c x
,
f(x) =

f2(x) =

dx +
ex +

9, x G [2 , 3]

① m f , (x) : oroso f, enwon (1 ,1) (2 -3)


, ,

stan a . + b -
1
+
c =

1
E
9 - 22 +
b .
2 +
C =
-
3

a b c 1

ingut
+ + =

4a +

2b +
c = -

croumot(
22
02 01 660 = Wind 18

a +
b + c = 1 free variable)
E 4a +

2b +
c = -

3 ↓

↳osamboU 3 as is insuwatosa
ewnwo On :
a suw free variable : a
b 1 a (I)
E
c
= -
+

eb +
c
= -
3 - 4a (#)

(I) b 4 3a
-

(1)
-
=

=>
-

6695a b = -

4 -
3d Ostr(I)
↳ C =

1 -
a -

b = 1 -
a -
( 4 -
-
3a)

5 +
2a

now fi(x) ax
= +

( -4-3a) x
+

(5 +

2a)

② en
fex) : wiwgn(2 ,
-3)
,
13
,
-1)

d 2
2 + e g 3
-

on (do z2
. +
= -

+ e -
z +

g =
-

>rouric)
4d +
2e
g =
-

jus
+

·
qd 3e 1
+

g = -
+

&d ouw free variable o


4d (II)
(2e g 3
+
-
= -

32
g -1 9d(IV)
+

= -

(AV) (1) e 2 5d
=
=> -

6642 e =
2 -
5d0sPr (#)

5d)
petg 3 4d 2(2
- -
= - -

=
1 +
6d

nswf(x) = dx +

(2 -
5d) x +
( 7
-
+

6d)
Islni
(& )
fi(x) =

ax +

( -
4 -

3a)x
+

(5 +

2a) 12 x 2

[
=

,
f(x) =

f2(x) = dx +

(2 -
5d)x +
( 7
-
+

6d) 22x =
3
,

Moon a d Fo .

niw Eure in mor new in burwen a, da


2 grosuario)
biwnifyr a =

1 d =
-1 pila"
,

fexs-(***** !I = s s

(dusearch Wolfram Alpha


enerwf te last in
,
110= &his plot)

E
D

main vos I

f
I-
L -

t
-


fz
Ibar (not smooth)
Mepwormoni 12
,
-3)

isworwowszi aucwornitos cioni o


osr

f(x
(f)(x) 7 1x 2
2x
-

= =

=
,

fe(x) = -
2x +
7
,
2 = X =
3

strin lim f(x) =

f(2)) =
f , (2) =
2(2) -
1 =
-

3
x -
2-

66=
limf(x) =

f(2+) fz(z) =
=
-

212) +

7 =
3

x- 2+
Estonis

Macar (A) :missionai a docists


enome ,

GoProudionon (2
,
-3) Eneza smooth

Mow

+!(x) = 2ax
+

( 4
- -
3a)
more
!(2) +(2) =

E f((x) 2dx
=
+

(2 -

5d)
now Moses 20 2 + (-4 3a) 2d 2
5d)
. =
-

(2
-
+ -

=>
4a -4 -3a =
4d +
2 -

5d

=> a -

4 =
-
d +
2

2nd = 6 -

a
is i w o : mostat denmis (A)
(5 2a) 1 x 2

(f(x)
3a)
+

= ax +
( -
4 -
x +

,
=

f(x) =

f(x) =
(6 a)x2
-
+
) -
28 +
5a)x +

(29 6a) -

21 x = 3
,

↳stain enwrosf groarion smooth


ga(2, -3)

M .
Ou a =
1 0 :
2
x -
xx
+

1 12 X =
2

f(x) ,

S
=

5x2 -

23 x +

23 , 2 X =3

f(x) =

3* s

f(2) = 212) -

1 = -

65 x
=

2 0 :

(f(24) =
10(2) -
23 =
-

N27864

bremrnf
in 2-spline
fr 45

·
·
I
-
quadratic
spline
3. Find a piecewise cubic function that goes through (1, 1), (2, −3),

(3, −1). Is the answer unique?

The answer is not unique .

is

fixs :

(Tc-axetDextea See
① m f:
=
Mos oddos i bordu
f, (1) b +
4 d
1 a 1
+ +
= =
=

, ,

f((z) =

3 =89
-
+
4b +

2, +
d, = -

3
,
I

Ou a ,
b
,
sw free variable

2
4 79,
-
3b ,
S
,
=
- -

1 inNn1s 0 : a
d 2b
5
= +

ba , ,

23
② unfr : O : mossounosirsordr

4b2 22 d2 3
=

fz(2)
-

3
+

89
+
+

= - =

f2(3) 9b2 32 dz = 1
+

2792
-
+

1
+
=
-
=

② free
· n de be fer free variable
, variable

See a Robe
4 Ms
enero or

n x b , x2
f , (X) =
a
,
+ +

( 4 7a ,
- - -

3b , )x +

(5 +
ba , +
2b
, )
f(x) =
4 x - [ 1 , 2] S

(f(x) =

a
,
x +

bex +
(2 -

1992 -

5b2)x +
( 7 -
+

30d2 +

6b2,
x G [ 2 3]
,

newbue Mimossber 3-spline (cubic spline)


Piston roww r 2 io no

(i) + ! (2) =

!(2)
"

(ii) f ,
(2) =

72" (2)
join fur free variable 6450 2 as livs
2. Spline

Let a = x0 < x1 < . . . < xn = b and let # be non-negative

integer. We define #−spline on [a, b] (or a spline of degree #, or a

spline of order # + 1) to be a function that satisfies

1. s(x) ∈ C#−1[a, b]. Here, Cm[a, b] is the set of m−time contin-

uously differentiable functions on [a, b].

te
2. s(x) ∈ P#[xi, xi+1) for i = 0, 1, . . . , n − 1.

Notations.

1. We let Ωn be a set of points (or knots) a = x0 < x1 < . . . <

xn = b that partition [a, b] into n subintervals.

2. We use S#(Ωn) to denote a set of all #-splines on Ωn.

moviavos 2-spline opde ni 35

Eas (*)

24
Examples of splines interpolating the points
(1 1) 12 , -3) , (3 -1)
,
, ,

① Linear spline (1-spline)

S1(X) 4x 5 xG 21 , 2]

E
+

= -

,
S(x) =

S (x) =
2x 7 x G [2, 3]
-

, ,

Note :
Unique !
② Quadratic spline (2-Spline)

3a)x (5 +
2a) 1 = x 2
S (x) ax ( 4 -
+ =

,
+ -

six)
,

S(x) =
(6 a) x
-
+
) -
28 +
5a)x +

(29 6a) -

21 x = 3
,

where a - IR a = 0 .

Note :

Not Unique !

when a 1 we have
Example : =
,

S , (X) = x2 -
xX
+

1 12 X = 2
,

S Se(X)
S(X) =

=
5x2 -

23 x +

23 , 2 X =3

S2

Se
Se
S2
Cubic spline. If s ∈ S3(Ωn), then s satisfies

1. s ∈ C2[a, b].
xite)
Iyxi ,
2. s ∈ P3[xi, xi+1), i = 0, . . . , n − 1.

To construct s ∈ S3(Ωn) that interpolates f on Ωn, we write




 s1(x) = a1x3 + b1x2 + c1x + d1,

 x ∈ [x0, x1],




six"

 s2(x) = a2x3 + b2x2 + c2x + d2, x ∈ [x1, x2],
s(x) =
 ... ...
↑ 



Mor 


(x) 
Sitt  sn(x) = anx3 + bnx2 + cnx + dn, x ∈ [xn−1, xn].
-X
To solve the unknowns, we can use the following conditions:
xit Xi xith

n+ 1 conditions s(xi ) = f (xi ), i = 0, 1, . . . , n; Interpolation conditions

s cont at

in Sin
si(xi) = si+1(xi), i = 1, 2, . . . , n − 1; , Xi

s'i(xi) = s'i+1(xi), i = 1, 2, . . . , n − 1; S'cont , at X;

s''i (xi) = s''i+1(xi), i = 1, 2, . . . , n − 1. s "cont at , y;

The total number of the unknowns is . . ..an


3(n 1) 4 - 2
The total number of conditions is . (n
. .. 1)
=
-

+ +

Therefore, we need .2. . more conditions.

25
End conditions.

1. Hermite end conditions: (for when f !(a), f !(b) are known)

s!(a) = f !(a),

s!(b) = f !(b).

* 2. Clamped end conditions:

s!(a) = 0,

s!(b) = 0.

A
#
3. Natural end conditions:

s!!(a) = 0,

s!!(b) = 0.

4. Periodic end conditions (for when f and f ! are periodic):

s!(a) = s!(b),

s!!(a) = s!!(b).

26
Example.
""=8 I
x =
-
1
,
0
,
1

Find a natural cubic spline s(x) that interpolates (−1, 1), (0, 2),

(1, −1). -
I
Se Se
-
! >X
Solution. Let I
-

⑧ 1



 s1(x) = a1x3 + b1x2 + c1x + d1, x ∈ [−1, 0],
s(x) =


 s2(x) = a2x3 + b2x2 + c2x + d2, x ∈ [0, 1].

We get



 s!1(x) = 3a1x2 + 2b1x + c1, x ∈ [−1, 0],
!
s (x) =


 s!2(x) = 3a2x2 + 2b2x + c2, x ∈ [0, 1],

and



 s!!1 (x) = 6a1x + 2b1, x ∈ [−1, 0],
!!
s (x) =


 s!!2 (x) = 6a2x + 2b2, x ∈ [0, 1].

interpla"Yous
The following conditions need to be satisfied.

->
(i) s (−1) = 1, s (0) = 2, s (0) = 2, s (1) = −1.
1 1 2 2

(ii) s!1(0) = s!2(0).


I
->
spline conditions
-
(iii) s!!1 (0) = s!!2 (0).
for
continuity

(iv) s!!(−1) = 0, s!!(1) = 0. Natural end condition


27
(i) S 1 -x =) a b 2
d
+

13
1
+ -
-
=

, , , =

1
S 10) =
2 = d =
2
,

S (0)
,
= 2 = d = 2

S
S2() = -1 =
92 +
be +

2z +

dz =
-
1

- a +

b -
2 = -

1
E
,
->> ⑪
az +

b +

cz
=
-

(ii) S
! 10) =

! 10)
S = c
,
=
2 ②

2b2
" "
(iii) S
,
(0) =
S (0) = 2b =

, ,

=> b, =
be

(iv) S", -1) =


0 = -ba
,
+
2b, = 0

six) =

0
692
=
+
2b = 0
,

=>

9 c
O
4

From &, 4 ,
we get a
,
=-
A2
From ①, &, we get

7
529
-2 =-
, ,
=>
C =
-
7
, de = -

1
202 +
2 = -

From ⑤, ac = 1

From b, =
-
3
,

b, = -
3

From &, 22 =
-1

ans




-
x3 3x2
-
-
x +
2
, x ∈ [−1, 0],
s(x) =


 x
3 - 3x2 -
x +
2 , x ∈ [0, 1].

28
3. Curve fitting (using polynomial)

Idea: Given n+1 points (x0, y0), (x1, y1), . . . , (xn, yn), find a poly-

nomial of degree m ≤ n that “fits these data the best”.


PmSX)=
Least square principle. Find pm = a0 + a1x + . . . + amxm

such that
n
%
E(pm) = E(a0, . . . , am) = {pm(xr ) − yr }2
r=0

anyo
is smallest.

Note. The quantity E is a multi-variable functions of the variables

a0, . . . , am. One can show that its minimum occurs at the critical

29
point a0, . . . , am satisfying

∂E
= 0, j = 0, . . . , m
∂aj

Using chain rule, we get

∂E ∂ & 2 2 2
'
= {pm(x0) − y0} + {pm(x1) − y1} + · · · + {pm(xn) − yn}
∂aj ∂aj
(
∂pm(x0) ∂pm(x1)
= 2 {pm(x0) − y0} + {pm(x1) − y1} + ···
∂aj ∂aj
)
∂pm(xn)
+ {pm(xn) − yn}
∂aj
& '
j j j
= 2 {pm(x0) − y0} x0 + {pm(x1) − y1} x1 + · · · + {pm(xn) − yn} xn
n
%
=2 {pm(xr ) − yr } xjr
r=0
%n n
%
=2 xjr pm(xr ) −2 yr xjr
r=0 r=0

Setting above to equal 0, we get


n
% n
% n
% n
%
a0 xjr + a1 xj+1
r + · · · + am xj+m
r = yr xjr ,
r=0 r=0 r=0 r=0

for j = 0, 1, . . . , m. These equations are called Normal equations.

30
The normal equations above can be written as matrix-vector form:
1 1 X 1 xY 1 
-
 -
y 1
   
.
.

x
x
A
- n - n - n
m  a0  - n A
 1 xr ··· xr     yr 
 r=0 r=0 r=0 "    r=0 
 n 1 X n X X x X   a   
- y X
- - 2 - n - n
.

   
-
.

1 .

 xr xr ··· xm+1    yr xr 
  ...
 r=0 r     r=0 
 r=0 r=0 = 
. ... ...     
 ..    ... 
    
 n   a m−1   
- m - n - n     - n
m 
xr xm+1
r · · · x 2m
r   y r x r
r=0 r=0 r=0 am r=0

31
x1 4
xy 5)
1 3
(o=
=

x2
=
=

, , ,

-
Example. Use least square principle to find p1(x) that best fits
x 1 3 4 5
the data want to find
y 2 4 3 1 + a X
P1(X) Go
=

,
3

Eon e) (ai] (- I
EYr
:

Yur

[iii] (ai)= ( ] ,

(9i] x 12 [ ] [i]
=

[I]= 2:

PIX) =
5
=> -

32
****
-
Example. Use least square principle to find p2(x) that best fits
x 1 3 4 5
the data Let P (X)
2
=

90 + 9 x
,
+
92 X2
y 2 4 3 1
2

Consider Eldo, an ,
&2) =
3 (P2Xr)-yr)
r =
0

=> Need to find min . E using critical point


Rewrite E =
E((90+ 9
, Xr+ 92XrY)
-

Yr]2
Stt

E = ↳[190 +
9
, xr
+

924)-Yr] :
1 = O

set

· =
(190 +9
, Xr+az4)-Yr] ·

Xr = O

set

92Yr)-yr] Yr2
0
~ [19
=

· & +9
& , xr
+
·

= -

z r=

simplify to get
= (90 9 Xr+ 92Xr) 1
= r

32gen) (ai
-
+

,
r
r = 0
3
& (90 + 9
, Xr+ 92Xr) ·

Xr =

Eor Xr
r = 0

= (90 + 9
, Xr+ 92Xr) .
Y =
Dr Xr

(g)
r = 0
-

33
Example. Use least square principle to find p2(x) that best fits
x 1 3 4 5
the data Pe(x) =

90 +

a
,
x +

92x2
y 2 4 3 1

I Exercisel (eit
Egix
1 r

I -35 ](ai -(ii)


413

453 3 4227
I q
= =
=
-

a
.

,
220

27/445
- 0 .

6136
92 =
-

33
Curve fitting using Exponential.
:
We can also use f (x) = aebx to fit the data (xi, yi) according to

the least square principle. In this case, we use log to transform the
f(x) =

y = aebX
problem into finding
Take In =>
Iny Ina +
InebX

I
=

..... F (x) = ln f (x) = bx + ln a Y (na bX



=
+

.....
e
that best fits the data set (xi, Yi) where Yi = ln yi. Line ar
-

Procedure.

1. Transform the data from (xi, yi) to (xi, Yi), i = 0, . . . , n,

where Yi = ln yi

2. Find the linear least square approximation

F (x) = A1x + A0

for the new set of data.

3. Upon comparing the definitions of F , we have that

b = A1, a = eA0 .

34
Example. Use least square principle to find the exponential func-

tion fitting for want to find fix) : a eby .

x 1 3 4 6 9 15

y 4.0 3.5 2.9 2.5 2.75 2.0

Solution. Use ln to convert the data (xi, yi) into (xi, Yi) as

x 1 3 4 6 9 15

Y 1.39 1.25 1.06 0.92 1.01 0.69

Let P , CX)
=

Ao+ A, X

E Ex .* )(i) [ =x !
5 5
[1
:

(03] (E) ( Y"]= (i) -"- ] :


:

1 3354

et = 20
.

3 8014

(9
=
.
=

=>

.
044

(-0 044x)
.

f(x) 3 8014 e
=>
=

35
Curve fitting using Hyperbolic function. -I
We can also use Hyperbota
:L
it
b
↳i
f (x) = a + ......

x
ir e
.

to fit the data (xi, yi) according to the least square principle. In


1
this case, we use the change of variable X = to change the
x

13
a
E
= +

problem into finding

y =
a +

bl
f (X) = a + bX

1
that best fits the data set (Xi, yi) where Xi = .
xi
Procedure.

1. Transform the data from (xi, yi) to (Xi, yi), i = 0, . . . , n,


1
where Xi =
xi

2. Find the linear least square approximation

f (X) = A1X + A0

for the new set of data.

3. We have that

b = A1, a = A0 .

36
Example. Use least square principle to find the hyperbolic func-

tion fitting for


Want to find
x 1 3 4 6 9 15

y 4.0 3.5 2.9 2.5 2.75 2.0


f(x) =
a
+
1
Solution. Convert the data (xi, yi) into (Xi, Yi) using Xi =
xi

X 1 0.33 0.25 0.17 0.11 0.07


Let
y 4.0 3.5 2.9 2.5 2.75 2.0 4, (1)
=
A +

Ao
,

-][i] L Er
Ed
j 5
=

Er 9

Lines" is] (Ei] ( 2] (ii) (i*s


:
= :

↳ b
2 364
1975
+

f(x)
=
.

37
Curve fitting using Trigonometry function.
Poonov
The fitting function is in the form
m m
a0 % %
t(x) = + ak cos(kωx) + bk sin(kωx)
2
k=1 k=1

In this case, we have

E = E(a0 , . . . , am , b1 , . . . , bm )
n
%
= {t(xr ) − yr }2
r=1
%n n
% n
%
= yr2 −2 t(xr )yr + [t(xr )]2
r=1 r=1 r=1
n n
1 m m
2
% % a0 % %
= yr2 − 2 + ak cos(kωxr ) + bk sin(kωxr ) yr
r=1 r=1
2
k=1 k=1
n
1 m m
22
% a0 % %
+ + ak cos(kωxr ) + bk sin(kωxr )
r=1
2
k=1 k=1

Solving for the critical point satisfying

∂E ∂E
=0 j = 0, 1, . . . , m and =0 j = 1, . . . , m
∂aj ∂bj

we get the system


n
1 m m
2 n
% a0 % % %
+ ak cos(kωxr ) + bk sin(kωxr ) = yr
r=1
2 r=1
k=1 k=1
n
1 m m
2 n
% a0 % % %
+ ak cos(kωxr ) + bk sin(kωxr ) cos(jωxr ) = cos(jωxr )yr
r=1
2 r=1
k=1 k=1
n
1 m m
2 n
% a0 % % %
+ ak sin(kωxr ) + bk sin(kωxr ) cos(jωxr ) = sin(jωxr )yr
r=1
2 r=1
k=1 k=1

for j = 1, 2, . . . , m

Note. This fitting function is called Discrete Fourier Transform (DFT).

38
& Noonfru
Example. Use m = 1, ω = 1. Find the Trigonometry function fitting for

x 0.0 0.4 0.8 1.2 1.6 2.0 2.4 2.8 3.2 3.6 4.0 4.4

y 3.0 2.1 1.3 0.5 0 −0.2 0 0.3 1.1 2.0 2.9 3.5
Solution. We get the normal equations
12
% 12
% 12
%
6a0 + cos xr a1 + sin xr b1 = yr
r=1 r=1 r=1
12
% 12
% 12
% %12
cos xr a0 + cos2 xr a1 + cos xr sin xr b1 = yr cos xr
r=1 r=1 r=1 r=1
%12 %12 12
% %12
sin xr a0 + cos xr sin xr a1 + sin2 xr b1 = yr sin xr
r=1 r=1 r=1 r=1

From the data above, we have that


-12 -12
r=1 cos xr = −2.000867, r=1 sin xr = 2.748837,
-12 -12
r=1 cos xr sin xr = 1.217139, r=1 yr = 16.5,
-12 -12
r=1 cos xr = 6.393092, r=1 sin
2 2
xr = 5.606908,
-12 -12
r=1 yr sin xr = −4.339589, r=1 yr cos xr = −0.041184
Therefore, the normal equations become

6.000000a0 − 2.000867a1 + 2.748837b1 = 16.5

−2.000867a0 + 6.393092a1 + 1.217139b1 = −0.041184

2.748837a0 + 1.217139a1 + 5.606908b1 = −4.339589

We get,

a0 = 5.352575, a1 = 2.415546, b1 = −3.922482

Thus,

t(x) = 2.6762875 + 2.415546 cos x − 3.922482 sin x

39
4. Least square and inconsistent system of linear equa-

tions

Consider the overdetermined system (m > n)

a11x1 + a12x2 . . . + a1nxn = b1 -> - error ,

a21x1 + a22x2 . . . + a2nxn = b2 --


=
error z

... I

"
am1x1 + am2x2 . . . + amnxn = bm -

=errorm
The system can be written as A#x = #b where
     
 a11 · · · a1n   x1   b1 
     
 . ...  , #x =  ... 
  #b =  ... 
A =  .. ,  
     
     
am1 · · · amn xn bm
mxn nx1 mx 1
When there is no solution, the system is called inconsistent. The
~b
AX
best we can do is find #x such that
m
%
Ax -
B =

(!
E(x1, . . . , xn) = [(A#x − #b)i]2
i=1
 2
m
% n
%
=  aij xj − bi
i=1 j=1

is smallest.

40
Normal Equations Derivation. We need to find the critical point

satisfying
 
m
% %n
∂E 
=2 aij xj − bi aik = 0
∂xk i=1 j=1

for k = 1, 2, · · · n. Rewrite to get


m %
% n m
%
aij aik xj = aik bi, k = 1, 2, · · · , n.
i=1 j=1 i=1

Define
m
% m
%
ckj = aij aik , dk = aik bi
i=1 i=1

We get that we have to solve the system


n
%
ckj xj = dk , k = 1, 2, · · · , m
j=1

which can be written as nxn Case


*

% %#
=
5
A A#x = A b
Y =

A 5
That is,
man Case man
7 8−1 -

#x = A%A A%#b AY =
B ~

7 8−1 x <(b
Note. The matrix A%A is called Pseudo inverse of A.
=

It
41
Example. Find the least square solution of

x1 + x2 = 1

x1 − x2 = 2

x1 + 2x2 = −1

Solution. The system can be written as A#x = #b where


   
 
 1 1   1 
   x1   
   , #b =  2 

A =  1 −1  , #x =    
   
  x2  
1 2 −1
~

A
I = i]
+ = I
b
- 3 x 2 2x1
3x1

At Asur * Atexex
I

24 3 ex ,

[23]
+

A A (AT A)2x2 Tax 5) ex


=

,
=
(A
~ -

x
=

(ATA) ** S
( _ ,)
2x
x
,
=

=>

* (AT A) A]5
T
=

42
Linear curve fitting (revisited). Use least square principle
x 1 3 4 5
to find p1(x) that best fits the data
y 2 4 3 1

Solution. The problem is equivalent to finding a0, a1 satisfying


   
 1 1    2 
   
   
 1 3   a0   4 
    
   =  
   
 1 4  a1 3
   
   
1 5 1

43

You might also like