Professional Documents
Culture Documents
by
Dr. Anita Pal
Assistant Professor
Department of Mathematics
National Institute of Technology Durgapur
Durgapur-713209
email: anita.buie@gmail.com
1
.
Chapter 3
Approximation of Functions
Module No. 1
Lots of experimental data are available in science and engineering applications and it
is very essential to construct a curve based on this data. From the fitted curve, it is easy
to determine the (approximate) values of unknown parameter(s) at non-experimental
points. So, curve fitting is a very useful and important topic. But, the question is which
curve is better for a given data set?
There are two broad methods are available for this problem, one is matching method
and another is approximation method. In Chapter 2, lots of interpolation methods
are discussed to construct a polynomial which passes through the given points. These
methods are called the matching methods. If n points (xi , yi ), i = 1, 2, . . . , n are given,
then in interpolation an nth degree polynomial is constructed. But, it is obvious that
the evaluation of large degree polynomial is a difficult task, though it gives exact values
at the given nodes x0 , x1 , . . . , xn . Again, the cubic spline generates n third degree
polynomials for n data points. By using approximation method one can construct
lower degree polynomials such as linear, quadratic etc. and other types of curve, viz.,
geometric, exponential etc. Mainly least squares method is used to construct such curve.
The least squares method does not give the guarantee that the curve must passes through
the given points, but it will minimizes the sum of square of the absolute errors. In this
method, the user can decide the degree of the polynomial irrespective of the data size,
but in interpolation the degree of the polynomial depends on the data set.
Let (xi , yi ), i = 1, 2, . . . , n be the give data set, i.e. a bivariate sample of size n. Our
problem is to construct a curve of the following form
y = g(x; a0 , a1 , . . . , ak ), (1.1)
where a0 , a1 , . . . , ak are the unknown parameters and their values are to be determined
in terms of given sample.
When x = xi , the ith argument, the value of y obtained from the equation (1.1) is
denoted by Yi . This value is called the predicted value or expected value or observed
value of y and in general, it is approximate value of y, i.e. erroneous value, where as yi
is the exact value of y.
1
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Least Squares Method
These points and the least squares curve are shown in Figure 1.1. The points are
drawn in blue colour and the curve is drawn in red colour. The dotted line represents
the actual value of y at x = xi . The predicted value Yi is the length between the (red)
curve and the x-axis.
y
6
r r
r r
r r r
r r r
r
r
6 6
yi -Yi r r
r r r6 r
?
r
r r
y i
Yi
? ? - x
O xi
Figure 1.1: The sample points and the least squares curve
Yi = g(xi ; a0 , a1 , . . . , ak ). (1.2)
In general, Yi and yi are different as the predicted values does not necessarily satisfy
the curve (1.1). The difference (yi − Yi ) is called the residual corresponding to x = xi .
Now, the sum of the square of the residuals be denoted by S and it is given by the
following expression
n
X n
X
S= (yi − Yi )2 = [yi − g(xi ; a0 , a1 , . . . , ak )]2 . (1.3)
i=1 i=1
The sum of the square of residuals is determined from the following equation
n
X n
X
S= 2
(yi − Yi ) = [yi − g(xi ; a∗0 , a∗1 , . . . , a∗k )]2 . (1.6)
i=1 i=1
This is the general method to fit a curve by using least squares method. Now, we
discuss this method to fit some special type of curves.
The straight line is a most simple curve and it is easy to handle. Let the equation of
a straight line be
y = a + bx, (1.7)
where a and b are two parameters and their values are to be determined by the least
squares method.
Let (xi , yi ), i = 1, 2, . . . , n, be a given sample of size n.
In this case, the sum of square of residuals S is given by
n
X n
X
S= (yi − Yi )2 = (yi − a − bxi )2 .
i=1 i=1
The above formula is generally used when the data set is large.
Let a∗ and b∗ be the values of a and b. Then the fitted straight line is
y = a∗ + b∗ x. (1.11)
Example 1.1 Let (2, 2), (−1.5, −2), (4, 4.5) and (−2.5, −3) be a sample. Use least
squares method to fit the line y = a + bx based on this sample and estimate the total
error.
Solution. The sample size is n = 4. The normal equations for straight line are
X X
yi = na + b xi
X X X
x i yi = a xi + b x2i
P P P
The values of xi , yi and xi yi are calculated in the following table.
xi yi x2i x i yi
2.00 2.00 4.00 4.00
−1.50 −2.00 2.25 3.00
4.00 4.50 16.00 18.00
−2.50 −3.00 6.25 7.50
Total 2.00 1.50 28.50 32.50
4
......................................................................................
y = −0.2023 + 1.1545x.
Estimation of error.
y = a0 + a1 x + a2 x2 + · · · + ak xk , (1.12)
5
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Least Squares Method
where a, b, c are unknown parameters and their values are to be determined by least
squares method.
Let Yi be the value of y when x = xi obtained from the curve (1.16).
Therefore, Yi = a + bxi + cx2i .
For this case, the sum of square of residuals S is
n
X n
X
S= (yi − Yi )2 = (yi − a − bxi − cx2i )2 .
i=1 i=1
X X X
yi = na + b xi + c x2i
X X X X
xi yi = a xi + b x2i + c x3i
X X X X
x2i yi = a x2i + b x3i + c x4i .
Let a = a∗ , b = b∗ and c = c∗ be the solution of the above equations. Then the fitted
parabolic curve is
y = a∗ + b∗ x + c∗ x2 (1.17)
Example 1.2 Fit a quadratic polynomial curve for the following data
x : 1 2 3 4 5 6 7 8 9
y : 3 4 6 7 7 8 10 11 11
X
= na + b u + c u2
P P
y
X
uy = a u + b u2 + c u3
P P P
X
u2 y = a u2 + b u3 + c u4 .
P P P
x u y u2 uy u3 u2 y u4
1 4 3 16 12 64 48 256
2 3 4 9 12 27 36 81
3 2 6 4 12 8 24 16
4 1 7 1 7 1 7 1
5 0 7 0 0 0 0 0
6 −1 8 1 −8 −1 8 1
7 −2 10 4 −20 −8 40 16
8 −3 11 9 −33 −27 99 81
9 −4 11 16 −44 −64 176 256
Total 0 67 60 −62 0 438 708
67 = 9a + 0b + 60c
−62 = 0a + 60b + 0c
438 = 60a + 0b + 708c.
Using least squares method one can fit many other curves such as geometric curve,
exponent curve, hyperbolic curve, etc. These type of curves occur in different applica-
tions and the nature of the curve depends on the problem and the data. Some of these
curves are described below.
8
......................................................................................
y = axb (1.18)
be the geometric curve. Here x and y are independent and dependent variables re-
spectively, and a and b are called the parameters of the curve. The values of these
parameters are to be determined by least squares method in terms of the sample
(xi , yi ), i = 1, 2, . . . , n.
Taking logarithm on both sides of the equation (1.18), we obtain log y = log a+b log x.
This equation can be written as Y = A + bX, where Y = log y, X = log x, A =
log a. Thus to fit the curve of equation (1.18), we have to determine the values of the
parameters A and b.
For this purpose, the given sample (xi , yi ) is to be converted to (Xi , Yi ), i = 1, 2, . . . , n.
Using this sample, and by using the procedure described in Section 1.2, one can deter-
mine the values of A and b. The value of a is then determine from the equation a = eA .
Example 1.3 Fit a geometric curve of the form y = axb for the following data.
x : 1 2 3 4 5
y : 2.7 5.6 10.2 15.3 21
Solution. Let y = axb . Here a and b are parameters. Taking logarithm both sides, we
get Y = A + bX, where log y = Y, log x = X, log a = A.
The normal equations for the curve Y = A + bX are
X X
Yi = nA + b Xi
X X X
Xi Yi = A Xi + b Xi2 .
x y X Y X2 XY
1 2.7 0 1.99325 0 0
2 5.6 0.69315 1.72276 0.48045 1.19413
3 10.2 1.09861 2.32238 1.20694 2.55139
4 15.3 1.38629 2.72785 1.92179 3.78159
5 21.0 1.60944 3.04452 2.59029 4.89997
Total 4.78749 10.81076 6.19947 12.42708
Thus the normal equations are
5A + 4.78749b = 10.81076,
4.78749A + 6.19947b = 12.42708.
y = aebx . (1.19)
Here the parameters are a and b and their values are to be determined by least squares
method.
Taking logarithm on both sides of the equation (1.19), we get log y = log a + bx. This
equation can be written as
Y = A + bx, where Y = log y, A = log a, i.e. a = eA .
The parameters A (and hence a) and b can be determined by the same process
discussed in Section 1.2.
Let us consider another kind of curve called the rectangular hyperbola whose equation
is of the following form:
1
y= . (1.20)
a + bx
10
......................................................................................
This is an extension of the least squares method. Weighted least squares method has
two fold importance. If a particular sample point, say (xk , yk ) is repeated for wk (say)
times, then this method is useful. Here, wk is an integer. Again, if a particular point(s),
say (xk , yk ) is (are) very significant, then the amount of importance can be represented
by a weight say wk . In this case, wk need not be an integer. Some times it may required
that the curve must passes through some given points. For this case also the weighted
least squares method is useful. If all the sample points have same significance, then the
weights are taken as 1.
This method is similar to the least squares method, only the weights are incorporated
in this new method.
n
X h i2
S= wi yi − (a + bxi ) . (1.21)
i=1
∂S ∂S
= 0, = 0.
∂a ∂b
11
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Least Squares Method
These give
n
X
−2 wi [yi − (a + bxi )] = 0
i=1
n
X
and −2 wi [yi − (a + bxi )]xi = 0
i=1
These are the normal equations and solving these equations we obtain the values of
a and b. This method is illustrated in the following example.
The same method can be used to fit other type of curves in case of weighted data.
Example 1.4 Consider the following sample:
x : 0 3 6 9
y : 9 16 21 28
x y w wx wx2 wy wxy
0 9 1 0 0 9 0
3 16 6 18 54 96 288
6 21 15 90 540 315 1890
9 28 1 9 81 28 252
Total 23 117 675 448 2430
Then the normal equations are 23a + 117b = 448 and 117a + 675b = 2430.
The solution is a = 9.8529, b = 1.8921.
Thus the fitted line is
y2 = 9.8529 + 1.8921x.
(c) In this case, the weights are 1, 20, 30, 1.
The calculations are shown in the following table.
x y w wx wx2 wy wxy
0 9 1 0 0 9 0
3 16 20 60 180 320 960
6 21 30 180 1080 630 3780
9 28 1 9 81 28 252
Total 52 249 1341 987 4992
Then the normal equations are 52a + 249b = 987 and 249a + 1341b = 4992 and the
solution is a = 10.4202, b = 1.7877.
Hence, the fitted line is
y3 = 10.4202 + 1.7877x.
Estimation of error.
x y y1 y2 y3 |y − y1 | |y − y2 | |y − y3 |
0 9 9.2000 9.8529 10.4202 0.2000 0.8529 1.4202
3 16 15.4001 15.5292 15.7833 0.5999 0.4708 0.2167
6 21 21.6002 21.2055 21.1464 0.6002 0.2055 0.1464
9 28 27.8003 26.8818 26.5095 0.1997 1.1182 1.4905
Sum of square of errors 1.5998 2.6474 3.2738
13
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Least Squares Method
Note that the sum of the square of errors is minimum for the line y1 , than the lines
for y2 and y3 . When the weights on second and third sample points are increased then
the absolute errors in y are reduced at these points, but, the sum of square of errors is
increased for the lines y2 and y3 .
The three lines are shown in Figure 1.2.
14