0% found this document useful (0 votes)
39 views22 pages

Chapter 5 Fitting Other Models

This document discusses fitting functions other than polynomials to discrete data using least squares as well as performing continuous least squares approximation. It describes linearizing non-linear functions to apply linear regression. Examples are provided on fitting exponential and power functions by transforming the variables to a linear form and solving the normal equations.

Uploaded by

muhammad iqbal
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
39 views22 pages

Chapter 5 Fitting Other Models

This document discusses fitting functions other than polynomials to discrete data using least squares as well as performing continuous least squares approximation. It describes linearizing non-linear functions to apply linear regression. Examples are provided on fitting exponential and power functions by transforming the variables to a linear form and solving the normal equations.

Uploaded by

muhammad iqbal
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 22

THE METHOD OF LEAST SQUARES PART 3

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 techniques of finding least-squares
polynomials to fit discrete data. In this chapter we shall proceed with fitting other
models (other than polynomials) to that same type of data. We shall also discuss
how to perform 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 of fitting functions.

65
THE METHOD OF LEAST SQUARES PART 3

5.2 Fitting Other Functions or Models (Linearization)


The method of least-squares is not restricted to polynomials or to any specific
functional form. In cases where polynomials are not appropriate, transcendental
functions may be used to fit the data. Some functions are reducible to a linear
relationship, by suitable changes in the variables or transformation and may be
written so that the representation is expressed in linear form. Such procedure is
called data linearization.

The technique of data linearization has been used to fit curves such as
y  Ce kx , y  cx k , y  A ln( 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.

Function Linear Transformation


y  a0  a1 X
1. y  ax 2  b
X  x 2, a0  b, a1  a

Y = a0 + a1 X
1
2.  ax2  b
y 1
Y , X  x 2, a0  b, a1  a
y

y  ab x Y  a0  a1 x
3. ln y  ln a  x ln b
Y  ln y, a0  ln a, a1  ln b

y  ax b Y  a0  a1 X
4.
ln y  ln a  b ln x
Y  ln y, X  ln x , a0  ln a, a1  b

ax
y Y  a0  a1 X
bx
5.
1 b 1 1
 .  Y
1
,X
1
, a0 
1
, a1 
b
y a x a y x a a

y  keax Y  a0  a1 x
6.
ln y  ln k  ax Y  ln y, a0  ln k, a1  a

66
THE METHOD OF LEAST SQUARES PART 3

Subsequent to data linearization, linear regression can be applied to the linear


equation in the transformed variable(s). In this case the normal equations will be
written in the new or transformed variable(s). The unknowns or coefficients of the
model are drawn from the solutions of the coefficients or unknowns in the
transformed variable(s).

Steps : Fitting a transcendental function

 Identify the expected function f(x) or the model


 Identify the unknowns.
 Linearize the relationship of the independent and the
dependent variables.
 Transform the data.
 Identify the normal equations.
 Determine all the respective values.
 Solve for the coefficients:
 Solve for the unknowns.
 Write the model obtained for the data.

Example 1
Use the method of least-squares to fit an exponential model y  ae bx to the
following data.
xi 0.4 0.8 1.2 1.6 2.0 2.3
yi 800 975 1500 1950 2900 3600

Solution
 Identify the expected function : y  ae bx
 Identify the unknowns : a, b
 Linearize:
y  aebx
ln y  ln aebx

o ln y  ln a  ln e bx
 ln a  bx ln e ln e  1)
 ln a  bx

67
THE METHOD OF LEAST SQUARES PART 3

 Transform the data:


Y  ln y a0  ln a a1  b
 Identify normal equation
 n
  n 
 n x   Yi 
 a0  =  i 1
i
 i 1 
 n  
2   a1   n 
n


 xi
 i 1
i 1
xi 

 x i Yi 
 i 1


 Determine the respective values:
i xi xi2 yi Yi xi Yi
1 0.4 0.16 800 ln 800 2.6738
2 0.8 0.64 975 ln 975 5.5059
3 1.2 1.44 1500 ln 1500 8.7759
4 1.6 2.56 1950 ln 1950 12.1209
5 2.0 4.00 2900 ln 2900 15.9449
6 2.3 5.29 3600 ln 3600 18.8340
n n

x
i 1
i  8.3
x
n

i  14.09
n

Y i  44.6170 x Y
i 1
i i  63.8555
i 1 i 1

 Substitute the respective values in the normal equation.


6 8. 3  a0  44.6170
8.3 14.09   = 63.8555
   a1   
 Solve for the coefficients: a 0 and a1

a0  6.3037 and

a1  0.8187
 Solve for the model unknowns:
a0  ln a  6.3037 a1  b  0.8187
ae 6.3037

 546.5906

 The expected function or model is y  546 .5906 e 0.8187x

Example 2

68
THE METHOD OF LEAST SQUARES PART 3

Use least-squares procedure to fit y  Ax k 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:

y  Ax k
ln y  ln A  k ln x

The necessary transformation for the data and unknowns are:

Y  a0  a1 X

Y  ln y, X  ln x , a0  ln A, a1  k

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
Sum: 1.9971 0.9620 9.6388 3.3333

Rewrite
ln y  ln A  k ln x
as
Y  a0  a1 X

Hence, the required normal equations:

69
THE METHOD OF LEAST SQUARES PART 3

 6
  6 
 6  Xi    Yi 
 i 1  a0  =  i 1 
 6  
2   a1   6 
6


 Xi
 i 1
i 1
Xi 


 X i Yi 
 i 1 
 6 1.9971 a0  9.6358
1.9971 0.9620   = 3.3333
   a1   

Solving for a0 and a1:

a0  1.4649 , a1  0.4239

Since a1  0.4239 then k  a1  0.4239

And, ln A  a0  ln A  1.4649  A  e1.4649  4.327

Hence, the expected function or model is y  Ax k  4.327 x 0.4239

Warm up exercise

Find the values of a and b of the form y  ae x  be  x to the following data:

x 0 0.5 1.0 1.5 2.0 2.5


Y 5.02 5.21 6.49 9.54 16.02 24.53

5.3 Continuous Least-Squares Polynomials


The previous section discusses least-squares approximation to fit a collection of
discrete data. Another approximation problem concerns with the approximation
of functions or fitting continuous data using polynomials.
Consider a function y  f (x ) , which is continuous on [a, b]. Let

Pm ( x )  a0  a1 x  a2 x 2  ...  ai x i  ...  am x m be a polynomial which estimates

the function y  f (x ) , then the total least-squares error is defined as follows:


b
E ∫ f(x) - P
a
m (x) 2 dx

70
THE METHOD OF LEAST SQUARES PART 3

∫ f(x) - a  dx
b
2
 0  a1 x  a2 x 2  ...  ai x i  ...  am x m
a

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 is such that
∂E ∂E ∂E ∂E
= = ...  = ...  =0 0im
∂ a0 ∂ a1 ∂ ai ∂ am
Hence,

  
b

∫ f(x) - a0  a1 x  ...  ai x i  ...  am x m dx  0
2
(1)
a
a0

  
b

∫ f(x) - a0  a1 x  ...  ai x i  ...  am x m dx  0
2
( 2)
a
a1
.
.
.

  
b

∫ f(x) - a0  a1 x  ...  ai x i  ...  am x m dx  0
2
(i )
a
ai
.
.
.

  
b

∫ f(x) - a0  a1 x  ...  ai x i  ...  am x m dx  0
2
(m )
a
am

Simplifying (1) yields

∫ 2 f(x) - a 
b

0  a1 x  ...  ai x i  ...  am x m ( 1)dx  0


a

∫ a  
b

0  a1 x  ...  ai x i  ...  am x m  f ( x ) dx  0
a
b b b b b


a
  
a0 dx  a1 xdx  ...  ai x i dx  ...  am x m dx  f ( x ) dx
a a a

a
b b b b b

  
a0 dx  a1 xdx  ...  ai x dx  ...  am x dx  f ( x ) dx  
i m

a a a a a

Simplifying (2) to (m) using similar procedures yield the normal equations

71
THE METHOD OF LEAST SQUARES PART 3

b b b b b

  
a0 xdx  a1 x 2 dx  ...  ai x i 1dx  ...  am 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  ...  am x m i dx  x i f ( x )dx
a a a

a

a
.
.
b b b b b

  
a0 x m dx  a1 x 2m dx  ...  ai x i m dx  ...  am x 2m dx  x m f ( x )dx
a a a

a

a

The normal equations can be represented in matrix form as


 
 b 
 b b b b

 dx   xdx ...  x dx
i
... ... 
x dx 
m
 
 f ( x )dx 

 a a a a   a0   ba 
 b b b b    
 a 
 xdx
 x dx
2
... x
i 1
dx ... ... 
m 1 a
 .   a

x dx   1   xf ( x )dx 

 ... ...   .   .
a a a
... ... ... ... ... 
b    b 
 x i dx
b b b

x i m dx   a   x i f ( x )dx 
.
 x x 
i 1

2i
dx ... dx ... ...
  i   
a a a a  .   a 
 ... ... ... ... ... ... ...   
 . 
 ... .
... ... ... ... ... ...     . 
b b b b  am   b 
 x m dx x 2m dx 
 x x 
m 1 m i
 x m f ( x )dx 
a
 a
dx ...
a
dx ... ...
a

  
a 
 

Steps : Fitting Continuous Least-Squares Polynomial

 Determine the degree m of the polynomial : m


 Write the general expression of the polynomial to be fitted
Pm (x)  a0  a1 x  a2 x 2  ...  am x m
 Write the normal equations in matrix form.
b 1

 x i dx for 0  i  2m and  x f ( x )dx for 0  i  m


i
 Compute :
a 0
 Solve for the coefficients a0, a1…am.
 Thus, the least-squares function is:
Pm ( x )  a0  a1 x  a2 x 2  ...  am x m

72
THE METHOD OF LEAST SQUARES PART 3

Example 3
Derive the normal equation in matrix form to approximate y  f(x) with a straight
line on the interval [a, b].

Solution

Let P1 ( x )  a0  a1 x

∂E ∂E
= =0
∂ a0 ∂ a1
b
E ∫ f(x) - P (x) dx
2
1
a

b
 ∫ f(x) - a  a1 x  dx
2
0
a

b

∫ f(x) - a0  a1 x 2 dx  0
a
a0
b

∫ 2 f(x) - a
a
0  a1 x ( 1)dx  0

∫ a
a
0  a1 x   f ( x )dx  0

b b b

 a dx   a xdx   f ( x )dx
a
0
a
1
a
b b b

 
a0 dx  a1 xdx  f ( x )dx
a a

a

b

∫ f(x) - a0  a1 x 2 dx  0
a
a1
b

∫ 2 f(x) - a
a
0  a1 x (  x )dx  0

∫ a
a
0  a1 x   f ( x )xdx  0

73
THE METHOD OF LEAST SQUARES PART 3

b b b


a

a0 xdx  a1 x 2 dx  xf ( x )dx
a

a
b b b

 
a0 xdx  a1 x dx  xf ( x )dx 
2

a a a

Hence, the normal equations


b b
 b 
 dx
a
 
xdx  
 f ( x )dx 
 a0   a 
 a    b
a
b b 
 1 

 xdx
 

xf ( x )dx 
2
x dx
 a a

 
a 

Example 4
Find the least-squares polynomial approximation of degree one to the function
y  x 2  4x  4 on the interval [0,2].

Solution

2 2
 2 
 dx
0
  xdx  
 f ( x )dx 
 a0   0 
 a    2
0
2 2 
 1 

 xdx
 0 
0
x 2 dx 
  0 
xf ( x )dx 


 56 
2 2  a   
 8     3 
0

2 3   a1   68 
3

a0  3.336
  
 a1  5.997
Hence, P1 ( x )  3.336  5.997x

Example 5
Find the least-squares polynomial approximation of degree two to y  e x on
[ 0, 1].

74
THE METHOD OF LEAST SQUARES PART 3

Solution

 Determine the degree m of the polynomial


m=2
 Write the general expression of the polynomial to be fitted
P2(x) = a0  a1 x  a2 x 2
 Write the normal equations in matrix form.
 1 1 1
  1 x 
 dx   xdx  x dx  
 e dx 
2

 0   0 
 a 0   1
0 0
1 1 1 

 xdx
 x dx 
2
x 3dx   a1    xe x dx 

0  0 
1  a 2   1 
0 0
1 1
 x 2 dx   x e dx 
  x dx  
3 4 2 x
x dx
   
0 0 0  0 
1 1

 x i dx for 0  i  4 and  x f ( x )dx for 0  i  m


i
 Compute :
0 0

 1 0.5 0.3333 a0  1.7183


    
 0.5 0.3333 0.25   a1    1 
0.3333 0.25 0.2  a2  0.7183

 Solve for the coefficients a0, a1…am.


a0  1.0140 
   
 a1   0.8445
a2  0.8449

 Thus, the least-squares function is:


P2(x) = 1.0140  0.8445x  0.8449x2

75
THE METHOD OF LEAST SQUARES PART 3

5.4 Continuous Least-Squares Approximation using


Legendre Polynomials
The previous section considered the problem of least-squares approximation to
fit a collection of discrete data. The other approximation problem concerns the
approximation of functions or fitting continuous data. In this section we shall
learn to fit data in continuous form using sequences of Legendre polynomials.

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

3x 2 - 1 
P3 ( x ) 
1
2

5x 3 - 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 )    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)

76
THE METHOD OF LEAST SQUARES PART 3

In general, the Legendre polynomials can also be derived by the formula:

Pn ( x ) 
1 dn
n
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 )  ...  am Pm ( x )

We seek to minimize the sum of error squares,


1
L ∫  f(x) - y(x) dx
2

-1

1
 ∫  a P (x) + a P (x) + a - y(x) dx
2
0 0 1 1 m Pm (x) (1)
-1

where, Pi (x) is a Legendre polynomial and a i is a constant coefficient.

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),
1
L
ak
2
-1
∫  a P (x)  a P (x)  a
0 0 1 1 m Pm ( x ) - y ( x )dx

 0
With the orthogonality property of Legendre polynomials, this term can be
simplified to:
1

∫  a P ( x )P ( x ) - y ( x )P ( x )dx  0
-1
k k k k

1 1

∫ P ( x ) dx  ∫
2
ak . k y ( x ) Pk ( x )dx
-1 -1

1
2
2k  1
ak  ∫
-1
y ( x ) Pk ( x )dx

77
THE METHOD OF LEAST SQUARES PART 3

Thus,
1
2k  1
ak 
2 -1∫ y ( x ) Pk ( x ) dx

Notice that ak calculates the coefficients a0, a1, …, am with the condition that x is
defined for y(x) on the interval [-1,1].

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 )  ...  am Pm ( x ) where, the coefficients a0, a1, …, am is
be determined by
1
2k  1
ak 
2 1 
y ( x ) Pk ( x ) dx for k = 0,1,2,3,……….,m

Steps : Fitting continuous data (or function) using


Legendre polynomials if independent variable
is defined on [-1,1]

 Identify the observed function: y(x)


 Determine the Legendre polynomials of degree m:
f ( x )  a0P0 ( x )  a1P1 ( x )  ...  amPm ( x )
 Determine the coefficients a0, a1, …, am :
1
2k  1
ak 
2 1 
y ( x ) Pk ( x ) dx for k = 0,1,2,3,…m

Example 3
Find the least-squares polynomial approximation of degree one to

y  x 2  4x  4 on the interval [-1,1].

78
Solution
THE METHOD OF LEAST SQUARES PART 3

 Identify the observed function :


y  x 2  4x  4

 Determine the Legendre polynomials of degree 1:


f ( x )  a0 P0 ( x )  a1P1 ( x )
 a0  a1 x

since,
P0 ( x )  1 , P1 ( x )  x

Determined the coefficients a0 and a1:


1
2k  1
ak 
2 1 
y ( x ) Pk ( x ) dx for k = 0,1

1
2(0)  1
k  0: a0 
2 1

( x 2  4 x  4) P0 ( x ) dx

1
1

2 1 
( x 2  4 x  4)(1)dx

13

3
1
2(1)  1
k  1 : a1 
2 1

( x 2  4 x  4) P1 ( x ) dx

1
3

2 1( x 2  4 x  4)x dx

4
 Thus, the polynomial of degree one to fit y(x) is:
f ( x )  a0 P0 ( x )  a1P1 ( x )
13
  4x
3
Another method which can be applied is by solving for the unknowns a0 and a1:
 1 1
 1 

 dx
 1
 xdx  
 y ( x )dx 
 a0   1 
 a    1
1
1 1 
 1 

 xdx
1 
1
x 2 dx 
 1 
xy ( x )dx 


79
THE METHOD OF LEAST SQUARES PART 3

In the case where x (or the independent variable) is defined on [m,n], where
m  1 and n  1 , a suitable linear transformation is required so that the
interval range of the independent variable is normalized to be on [-1,1].

Steps : Fitting continuous data (or function) using


Legendre polynomials if independent variable
is not defined on [-1,1]

 Transform x to t linearly: x  [m, n ]  t  [1,1 ]


 Let x  at  b
 Solve for a and b
 Rewrite y(x) in term of y(t)
 Determine the Legendre polynomials of degree m
 f (t )  a0P0 (t )  a1P1 (t )  ...  am Pm (t )
 Determine the coefficients a0, a1, …, am :
1
2k  1
ak 
2 1 
y (t ) P k (t ) dt for k = 0,1,2,3,..,m

 The polynomial of degree m to fit y(t) is:


f (t )  a0P0 (t )  a1P1 (t )  ...  am Pm (t )
 Rewrite f(t) in term of f(x).

Example 4
Find the least-squares polynomial approximation of degree one to

y  x 2  4x  4 on the interval [0,2]

Solution

Since x  [0 ,2 ] and x  [1, 1 ] then transformation is required.


 Transform x to t linearly:
x  [0,2 ]  t  [1,1 ]
 Let x  at  b
When x  0 : t  1 thus 0  a(1)  b …(1)
When x  2 : t  1 thus 2  a(1)  b …(2)
 Solving for a and b:
a 1 b 1

80
THE METHOD OF LEAST SQUARES PART 3

Thus,
x  t 1 or t  x 1

 Rewrite y(x) in term of y(t):


y ( x )  x 2  4x  4
y (t )  (t  1) 2  4(t  1)  4
 t 2  6t  9
Determine the Legendre polynomials of degree 1 (in the variable t):
f (t )  a0 P0 (t )  a1P1 (t )
 a0  a1 (t )

 Determine the coefficients a0 and a1:


1
2k  1
ak 
2 1 
y (t ) P k (t ) dt for k = 0,1

1
2(0)  1
k  0: a0 
2 1

(t 2  6t  9) P 0(t ) dt

1
1 28

2 1 
(t 2  6t  9)(1) dt 
3
1
2(1)  1
k  1: a1 
2  y (t ) P (t ) dt
1
1

1
3
 
2 1
(t 2  6t  9)(t ) dt  6

 The polynomial of degree 1 to fit y(t) is:


f (t )  a0 P0 (t )  a1P1 (t )
28
  6t
3
 Rewrite f(t) in term of f(x):
28
f (t )   6 ( x  1)
3
since t  x  1
10
  6x
3

81
THE METHOD OF LEAST SQUARES PART 3

Example 5
Find the least-squares polynomial approximation of degree two to f ( x )  e x
on the interval
a) [-1, 1] b) [ 0, 1]

Solution
a) No transformation is required since x  [1, 1 ] .

Given f ( x )  e x and approximation by a polynomial of degree two,

f ( x )  a0 P0 ( x )  a1P1 ( x )  a2 P2 ( x )
1 
 ao  a1 x  a2  (3x 2  1) 
2 

1 
since P0 ( x )  1 , 1P1 ( x ) x and P2 ( x )   (3x 2  1) 
2 
Determine the coefficients a0 ,, a1 and a2:
1
2k  1
ak 
2 1 
y ( x ) Pk ( x ) dx for k = 0,1,2

1
2(0)  1
k  0 : a0 
2 1

e x P0 ( x ) dx

1
1

2 1 
e x dx

 1.1752
1
2(1)  1
k  1: a1 
2 1
e x P1 ( x ) dx

1
3

2 1 
e x x dx

 1.1036
1
2( 2)  1
k  2: a1 
2 1

e x P2 ( x ) dx

1
5 1 
 
e x  (3x 2  1)  dx
2 1  2 
 0.3578

82
THE METHOD OF LEAST SQUARES PART 3

Hence,
f ( x )  a0 P0 ( x )  a1P1 ( x )  a2 P2 ( x )
1 
 ao  a1 x  a2  (3x 2  1) 
2 
1 
 1.1752  1.1036x  0.3578 (3x 2  1) 
2 
 0.9963  1.1036x  0.5367x 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 ]
Let x  at  b , solve for a and b
When x  0 : t  1 thus 0  a(1)  b …(1)
When x  1 : t  1 thus 1  a(1)  b …(2)
Solving for a and b:
1 1
a and b
2 2
Thus,
1 1 t 1
x t  or 2x  t  1  t  2x  1
2 2 2
Write y(x) in the term of y(t):
y(x)  ex
t 1
y (t )  e 2

Write the least-squares polynomial in the new variable t in the form of


Legendre polynomials:
f(t) is a polynomial of degree two (quadratic),thus
f (t )  a0 P0 (t )  a1P1 (t )  a2 P2 (t )
1 
 ao  a1t  a2  (3t 2  1) 
2 
Determine the coefficients a0 , a1 and a2:
1
2k  1
ak 
2 1 
y (t ) Pk (t ) dt for k = 0,1,2

83
THE METHOD OF LEAST SQUARES PART 3

1 t 1
2( 0)  1
k  0: a0 
2 1
e  2 P0 (t ) dt

1 t 1
1

2 1 
e 2 dt

 1.7183
1 t 1
2(1)  1
k  1: a1 
2 1
e  2 P1 (t ) dt

1 t 1
3
 
2 1
e 2 t dt

 0.8452
1 t 1
2( 2)  1
k  2 : a2 
2 1
e  2 P2 (t ) dt

1 t 1
2 . 
5 1
   (3t  1)  dt
2
e
2 1 2 


5
0.0559
2
 0.1398
Thus,
f (t )  a0 P0 (t )  a1P1 (t )  a2 P2 (t )
1 
 1.7183  0.8452t  (0.1398) (3t 2  1) 
 2 
 1.6484  0.8452t  0.8388t 2
Hence,
f ( x )  1.6484  0.8452( 2 x  1)  0.8388( 2 x  1)2
 1.3097  14.7872x  13.0968x 2

Warm up exercise
Find the least-squares polynomial approximation of degree two to:
(i) f ( x )  sin 2x on the interval [-1,1] and [0, 1]

(ii) f ( x )  ln x on the interval [1,3]

84
THE METHOD OF LEAST SQUARES PART 3

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-squares error and determine which is a better model to


represents the data. Plot the data and the non-linear model.

2. The data shows the solubility, S, of n-butane in anhydrous hydrofluoric acid at


high temperature T needed in the design of petroleum refineries. Determine the
constants  and  to fit the data to the model S  eT . Estimate the solubility

when temperature is 95F.

Temperature F 77 100 185 239 285


Solubility (weight %) 2.4 3.4 7.0 11.1 19.6

3. One of the following data sets, (x,y1) and (x,y2) , follows an exponential law
y  Ae bx and the other follows a power law y  Ax b . Which is which? Fit the

data to the respective model and calculate the sum square errors.

x 2.0 2.5 3.0 3.5 4.0 4.5 5.0


y1 14.79 27.75 47.09 74.07 109.99 156.10 213.69
y2 12.13 19.58 31.59 50.97 82.21 132.59 213.82

4. Find the least-squares polynomial approximation of degree one to the function f(x)
on the indicated interval.
a) f ( x )  e 2 x ; [-1, 1] d) f ( x )  sin x ; [-1, 1]

1
b) f (x)  ; [1, 3] e) f ( x )  cos 2x f(x); [0, 0.5] ,
x

c) f ( x )  x 3  1 ; [0,2] f) f ( x )  ln x ; [1, 2]

85
THE METHOD OF LEAST SQUARES PART 3

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 f(x) ; [-1, 1]

b) f ( x )  x 3  x  1 ; [0, 3] d) f ( x )  sin 2x ; [0, ]

6. Consider the function f ( x )  sin 2x defined in [0, ].

 
a) Find the least-squares polynomial approximation of degree one in 0, 
 2
 
and  ,  .
2 
b) Find the least-squares polynomial approximation of degree two in [0, ].
c) Plot the graph to show the polynomials in a) and b) together with the
function f(x).
d) Approximate f(0.2) and f(2) using a) and b). Which polynomial gives a
better approximation.
e) Calculate the total least-squares error for a) and b).
f) If f(x) is approximated using least-squares polynomial of degree three
i.e., f ( x )  ao  a1 x  a2 x 2  a3 x 3 , find a3 .

86

You might also like