Linearization
Linearization
Chapter 5
Fitting Other
Models and
Continuous
Data
At the end of this chapter, students should be able to:
Describe discrete least-squares for other type of functions or models
Describe continuous least-squares approximation
Apply these two least-squares method in curve fitting problems
5.1 Introduction
In the previous chapter we discussed about finding least-squares polynomials to
fit discrete data. In this chapter we shall proceed with fitting other models (other
than polynomials) to that type of data. We shall also discuss how to do
continuous least-squares approximation (fitting functions or continuous data). At
the end of this chapter, sequences of Legendre polynomials will be discussed as
an alternative method.
63
Part 3 THE METHOD OF LEAST SQUARES MAT 575
The technique of data linearization has been used by scientists to fit curves such
as y = CeAx, y = cxA and y = Aln(x) + B and many more. Once the model has
been chosen, a suitable transformation of the variables must be found so that a
linear relation is obtained. Some examples of transformations are given as in the
table below.
1. y = a 0 + a1 X
y = ax2 + b
X = x2 , a=a1, b=a0
2.
Y = a 0 + a1 X
1
ax 2 b
y 1
X = x2, Y = , a=a1, b=a0
y
3.
y = abx Y = a 0 + a1 X
ln y = ln a + x ln b
Y = ln y, ln a=a0, ln b=a1
4.
y = axb Y = a 0 + a1 X
ln y = ln a + b ln x
X = ln x , Y = ln y, ln a=a0, b=a1
5.
ax 1 a 1
y Y a0 a1
bx y b b
6.
y = keax Y = a 0 + a1 x
ln y = ln k + ax
Y = ln y, ln k=a0 , a=a1,
64
Part 3 THE METHOD OF LEAST SQUARES MAT 575
Example 1
Solution
y aebx
ln y ln aebx
o ln y ln a ln ebx
ln a bx ln e ln e 1)
ln a bx
65
Part 3 THE METHOD OF LEAST SQUARES MAT 575
x i 8.3
y
n
i 14.09 Yi 44.6170
i 1
i1 i 1
i1
a0 6.3037 and
a1 0.8187
Substitute to the transform unknown :
a0 ln a 6.3037 a1 b 0.8187
6.3037
ae
546 .5906
66
Part 3 THE METHOD OF LEAST SQUARES MAT 575
Example 2
Use least-squares procedure to fit y = Axk to the following data.
xi 1.00 1.15 1.40 1.43 1.60 2.00
yi 4.33 4.58 4.98 5.06 5.28 5.80
Solution
y Ax k
Taking natural logarithm both sides:
ln y = l n A + k ln x
Y a0 a1X
Y ln y X ln x a0 ln A k a1
x y X = ln x X2 Y = ln y XY
1.00 4.33 0.0000 0.0000 1.4656 0.0000
1.15 4.58 0.1398 0.0195 1.5217 0.2127
1.40 4.98 0.3365 0.1132 1.6054 0.5402
1.43 5.06 0.3677 0.1279 1.6214 0.5799
1.60 5.28 0.4700 0.2209 1.6639 0.7821
2.00 5.80 0.6831 0.4805 1.7579 1.2185
1.9971 0.9620 9.6358 3.3333
Rewrite
ln y = ln A + k ln x
as
Y = a0 + a1 X
Hence, the required normal equations:
6 6
6 xi Yi
a 0
i 1
= 6
i 1
6 6 1
a
x i x i2 x i Yi
i 1 i 1 i 1
67
Part 3 THE METHOD OF LEAST SQUARES MAT 575
a0 = 1.4649
But ln A = a0 then
A = e a0 = e1.4649 = 4.327
Warm up exercise
Find the values of a and b of the form y = aex + be-x to the following data:
∫f(x)- Pm (x)
2
E dx
a
∫f(x)- a dx
b
2
0 a1x a2 x 2 ... ai x i ... am x m
a
68
Part 3 THE METHOD OF LEAST SQUARES MAT 575
We seek to minimize the sum of error squares. From the calculus of functions of
several variables, a necessary condition for the values a0, a1, …, and am to
minimize E such that
∂E ∂E ∂E ∂E
= = ... = ... =0 0im
∂a0 ∂a1 ∂ai ∂am
Hence,
f(x)- a
b
∫am 0 a1x ... ai x i ... am x m 2 dx 0 (m )
a
a0 dx a1xdx ... ai x i dx ... am x m dx f ( x ) dx
a a a a a
b b b b b
a0 dx a1 xdx ... ai x dx ... am x m dx f ( x ) dx
i
a a a a a
Simplifying (2) to (m) using similar procedures yield the normal equations
69
Part 3 THE METHOD OF LEAST SQUARES MAT 575
b b b b b
a0 xdx a1 x 2 dx ... ai x i 1dx ... a m x m 1dx xf ( x )dx
a a a a a
.
.
b b b b b
a0 x i dx a1 x 2 i dx ... ai x 2i dx ... a m x m i dx x i f ( x )dx
a a a a a
.
.
b b b b b
a0 x m dx a1 x1 m dx ... ai x i m dx ... a m x 2m dx x m f ( x )dx
a a a a a
x dx x f ( x)dx for 0 i m
i i
Compute : for 0 i 2m and
a 0
Solve for the coefficients a0, a1…am.
Thus, the least-squares function is:
f(x) = a0 + a1x + a 2 x 2 + ... + am x m
Solve for a0 and a1.
Thus, the least-squares line is f(x) = a0 + a1x.
70
Part 3 THE METHOD OF LEAST SQUARES MAT 575
Example 3
Derive the normal equation in matrix form to approximate y = f(x) with a straight
line on the interval [a, b].
Solution
∂E ∂E
= =0
∂a0 ∂a1
b
∫f(x)- P1(x) dx
2
E
a
b
∫a0 f(x)- a0 a1x dx 0
2
a
b
a0dx a1xdx f ( x )dx
a a a
b b b
a0 dx a1 xdx f ( x )dx
a a a
b
∫a1 f(x)- a0 a1x dx 0
2
a
b
71
Part 3 THE METHOD OF LEAST SQUARES MAT 575
b b b
a0 xdx a1x
2
dx xf ( x )dx
a a a
b b b
a0 xdx a1 x 2dx xf ( x )dx
a a a
b b b
dx
xdx
a0
f ( x )dx
ba b
a ba
a1
xdx
a
x 2dx
xf ( x )dx
a
a
Example 4
Find the least squares polynomial approximation of degree one to
y = x 2 + 4x + 4 on the interval [0,2].
Solution
2 2 2
dx xdx f ( x )dx
0 0 a0 0
2
2 a1
2 2
xdx x dx xf( x )dx
0 0 0
56
2 2 a
0
8 3
2 3 a1 68
3
a0 3.336
a1 5.997
Hence, P1( x) 3.336 5.997 x
Example 5
Find the least squares polynomial approximation of degree two to f(x) = e x on
the interval [ 0, 1]
72
Part 3 THE METHOD OF LEAST SQUARES MAT 575
Solution
P2(x) = a0 a1x a2 x 2
Write the normal equations in matrix form.
1 1
2
1 1 x
dx xdx x dx e dx
0 0 0 a0 0
1 1
2
1
3
1
x
xdx x dx x dx a1 xe dx
0 0 0 a 0
1 2 2 1
4 2 x
1 1
3
x dx x dx x dx x e dx
0 0 0 0
1 1
x dx x f ( x )dx
i i
Compute : for 0 i 4 and for 0 i m
0 0
73
Part 3 THE METHOD OF LEAST SQUARES MAT 575
Definition
The functions listed below are called Legendre polynomials and are defined for
-1 x 1:
P0(x) = 1
P1(x) = x
P2 ( x )
1 2
2
3x - 1
P3 ( x )
2
1 3
5x - 3x
P4 ( x )
1
8
35x 4 - 30x 2 + 3
P5 ( x )
1
8
63x 5 - 70x 3 + 15x
.
.
2m + 1 m
Pm 1( x ) Pm - Pm -1
m +1 m + 1
This set of Legendre polynomials is said to be orthogonal on [-1,1] with respect
to the weight function w(x) 1 .The criteria required is that these functions are
designed to satisfy the following orthogonality condition:
1 0 if n m
Pm ( x ) Pn ( x ) dx 2
if n m
1 2n 1
(details of orthogonality and weight function shall not be discussed here)
In general, the Legendre polynomials can also be derived by the formula:
Pn ( x )
1
n
dn
2 n! dx n
(x 2
- 1)n
Suppose y(x) is a function continuous on [-1,1]. Here, the approach to finding the
least-squares approximating polynomial f(x) to fit the function y(x) (or, the
continuous data) is done in a similar manner. Let f(x) be of polynomial of degree
m defined using sequences of Legendre polynomials such that
f(x) = a0P0(x) + a1P1(x) + a2P2(x) + . . . + amPm (x) .
74
Part 3 THE METHOD OF LEAST SQUARES MAT 575
∫ f(x)- y(x) dx
2
L
-1
1
∫ a 0 P0 (x) + a1P1 (x) + ... a m Pm (x) - y(x)2 dx (1)
-1
From the calculus of functions of several variables, a necessary condition for the
values a0, a1, …, am to minimize L is that
∂L
= 0, for each k = 0, 1, …, m.
∂ak
Hence, using (1),
L 1
∫ a0 P0 ( x ) a1P1( x ) am Pm ( x ) - y( x )2 dx
ak -1
0
With the orthogonality property of Legendre polynomials, this term can be
simplified to:
1
akPk ( x)Pk ( x) - y( x)Pk ( x) dx 0
∫
2
-1
1 1
ak . Pk ( x )2 x
∫ ∫ y( x) Pk ( x)dx
-1 -1
1
2
ak ∫y( x) Pk ( x)dx
2k 1
-1
Thus,
1
2k 1
ak ∫ y(x)Pk (x) dx
2
-1
Notice that ak calculates the coefficients a0, a1, …, am with the condition that x is
defined for y(x) on the interval [-1,1].
75
Part 3 THE METHOD OF LEAST SQUARES MAT 575
Theorem
Suppose y(x) is continuous and defined on [-1,1], then y(x) can be approximated
by a least-squares polynomial f(x) of degree m, using series of Legendre
polynomials such that:
f(x) = a0P0(x) + a1P1(x) + a2P2(x) + . . . + amPm(x)
where, the coefficients a0, a1, …, am is be determined by
1
2k 1
ak
2 y( x) Pk ( x) dx for k = 0,1,2,3,……….,m
1
Example 3
Find the least squares polynomial approximation of degree one to
Solution
Identify the observed function :
y(x) = x 2 + 4x + 4
Determine the Legendre polynomials of degree 1:
f(x) = a0P0(x) + a1P1(x)
= a0 + a1x
where P0(x) = 1 and P1(x) = x
76
Part 3 THE METHOD OF LEAST SQUARES MAT 575
1
2(0) 1
k 0: a0
2
( x 2 4 x 4) P0 ( x ) dx
1
1
1
2
( x 2 4 x 4)(1)dx
1
13
3
1
2(1) 1
k 1 : a1
2
( x 2 4 x 4) P1( x ) dx
1
1
3
2
( x 2 4 x 4)x dx
1
4
Thus, the polynomial of degree one to fit y(x) is:
f(x) = a0P0(x) + a1P1(x)
13
= + 4x
3
Other method which can be applied is
1 1 1
dx xdx
a0
y( x )dx
11 1
1 1
a1 1
xdx
1
x 2dx
xy( x )dx
1
1
77
Part 3 THE METHOD OF LEAST SQUARES MAT 575
Example 4
Find the least squares polynomial approximation of degree one to
y = x 2 + 4x + 4 on the interval [0,2]
Solution
78
Part 3 THE METHOD OF LEAST SQUARES MAT 575
= t 2 + 6t +9
Determine Legendre polynomials of degree 1:
f(t) = a0P0(t) + a1P1(t)
= a0 + a1t
where P0(t)=1 and P1(t)=t
Determine the coefficients a0 and a1:
1
2k 1
ak
2 1
y( t ) P k ( t ) dt for k = 0,1
2(0) 1 1 2
k 0 : a0 ( t 6t 9) P 0( t ) dt
2 1
11 2 28
( t 6t 9)(1) dt
2 1 3
2(1) 1 1
k 1 : a1 y( t ) P 1( t ) dt
2 1
3 1 2
( t 6t 9)(t ) dt 6
2 1
Example 5
Find the least squares polynomial approximation of degree two to f(x) = ex on
the interval
a) [-1, 1] b) [ 0, 1]
79
Part 3 THE METHOD OF LEAST SQUARES MAT 575
Solution
a) No transformation is required since x [1, 1 ] .
Given
y(x) = ex
and
f(x) = a0P0(x) + a1P1(x) + a2P2(x) polynomial of degree two
a0P0 ( x ) a1P1( x ) a2P2 ( x )
1
ao a1x a2 (3x 2 1)
2
1
since P0 ( x ) 1 , 1P1( x ) x and P2 ( x ) (3x 2 1)
2
Determined the coefficients a0 ,, a1 and a2:
1
2k 1
ak
2 y( x) Pk ( x) dx for k = 0,1,2
1
1
2(0) 1
k 0 : a0
2
e x P0 ( x ) dx
1
1
1
2
e x dx
1
1.1752
1
2(1) 1
k 1 : a1
2
e x P1( x ) dx
1
1
3
2
e x x dx
1
1.1036
1
2(2) 1
k 2: a1
2
e x P2 ( x ) dx
1
1
5 1
2
e x (3 x 2 1) dx
2
1
0.3578
80
Part 3 THE METHOD OF LEAST SQUARES MAT 575
Hence,
f ( x ) a 0P0 ( x ) a1P1( x ) a 2P2 ( x )
1
a o a1x a 2 (3 x 2 1)
2
1
1.1752 1.1036 x 0.3578 (3 x 2 1)
2
0.9963 1.1036 x 0.5367 x 2 .
b)
Need a suitable linear transformation since x [1, 1 ] and x [0 ,1 ]
Make a suitable linear transformation of x to t:
x [0,1 ] t [1,1 ]
i.e. x = at + b, solve for a and b
when x = 0, t = - 1 : 0 = a(-1) + b = - a + b …(1)
when x = 1, t = 1 : 1 = a(1) + b = a + b … (2)
81
Part 3 THE METHOD OF LEAST SQUARES MAT 575
t 1
2(0) 1 1 2
k 0 : a0 e P0 ( t ) dt
2 1
t 1
11
e 2 dt
2 1
1.7183
t 1
2(1) 1 1 2
k 1 : a1 e P1( t ) dt
2 1
t 1
3 1
e 2 t dt
2 1
0.8452
t 1
2(2) 1 1 2
k 2 : a2 e P2 ( t ) dt
2 1
t 1
51 1
e 2 . (3t 2 1) dt
2 1 2
0.0559
5
2
0.1398
Thus,
f ( t ) a0P0 ( t ) a1P1( t ) a2P2 ( t )
1
1.7183 0.8452 t (0.1398 ) (3t 2 1)
2
1.6484 0.8452 t 0.8388 t 2
Hence
Warm up exercise
82
Part 3 THE METHOD OF LEAST SQUARES MAT 575
Exercise 5
1. Find the values of A and B to fit a curve of the following form to the given data.
1 A
a) y b) y B
Ax B x
x -1 0.1 1 2 3
y 6.62 3.94 2.17 1.35 0.89
Calculate the least square error and determine which is a better model to
represents the data. Plot the data and the non-linear model.
3. One of the following data sets, (x,y1) and (x,y2) , follows an exponential law
y Aebx and the other follows a power law y Axb . Which is which? Fit the
data to the respective model and calculate the sum square errors.
4. Find the least- squares polynomial approximation of degree one to the function
f(x) on the indicated interval.
a) f(x) = e2x ; [-1, 1] d) f(x) = sinx ; [-1, 1]
1
b) f (x) ; [1, 3] e) f(x) = cos 2x ; [0, 0.5] ,
x
c) f(x) = x3 – 1; [0,2] f) f(x) = ln x; [1, 2]
83
Part 3 THE METHOD OF LEAST SQUARES MAT 575
5. Find the least- squares polynomial approximation of degree two to the function
f(x) on the indicated interval.
a) f(x) = e-x ; [0, 1] c) f(x) = cos x; [-1, 1]
b) f(x) = x3 – x + 1; [0, 3] d) f(x) = sin2x; [0, ]
f ( x ) ao a1x a2 x 2 a3 x 3 , find a3 .
84
Part 3 THE METHOD OF LEAST SQUARES MAT 575
2.
3.
4. a) d)
b) e)
c) f)
5. a) c)
b) d)
6 a) d)
b) e)
c) f)
85