You are on page 1of 12

COLLEGE OF SCIENCE AND TECHNOLOGY, R.U.B, P/LING:: BHUTAN S.T.

VENKATESAN

CURVE FITTING
In many branches of Applied Mathematics, Engineering and Sciences we come across experiments
and problems which involve two variables. Let ( xi , yi ) : i  1, 2, , n be n sets of numerical values

of two variables x (independent) and y (dependent). If we plot these n sets on the graph we get a
diagram, which is called the scatter diagram. In the scatter diagram, a smooth curve can be drawn
to pass through near the plotted points. Such a curve is called an approximating curve. The equation
of this curve may be taken as an approximate relation between x and y and it is called empirical
law. The general problem of finding exact equations of approximating curves which fit given data
is called curve fitting.

For example it is known that the speed v of a ship varies with the horse power p of an engine
according to the formula p  a  b v 3 . For this purpose we take several sets of readings of speeds
and the corresponding horse powers. The problem is to find the best values for a and b using the
observed values of v and p. Thus the general problem is to find a suitable relation or law that may
exist between the two variables from a given set of observed paired values. Such a relation
connecting the two variables is known as empirical law.

The process of finding the equation of the curve of best fit which may be most suitable for
predicting the unknown values is known as curve fitting.

Methods of Curve Fitting:


Following are standard methods for fitting a curve.
(i) Graphical method. (ii) Method of group averages.
(iii) Method of moments. (iv) Method of Least Squares.

Here we discuss only the method of least squares.

Linear Law:
Suppose the relationship between the variables x and y is linear, and of the form y  a x  b . Thus
the curve to be fitted for the given data is a straight line. In simple cases a straight line may be fitted
by eye. But if the points are scattered then it becomes unreliable. Hence we use some mathematical
principles to determine the values of a and b. But it must be noted that sometimes the given data
may not follow a liner law. In such cases it may be possible to find some other nonlinear law which
can be reduced to linear law by suitable transformation.

NUMERICAL ANALYSIS – CURVE FITTING Page 1 of 12


COLLEGE OF SCIENCE AND TECHNOLOGY, R.U.B, P/LING:: BHUTAN S.T.VENKATESAN

The following EXAMPLES are some laws which are reducible to Linear Law.
1) y  a x n  b

Taking X  x n and Y  y the above law becomes Y  a X  b which is linear.

2) y  a x b

Taking common logarithms { log10 } on both sides, we get

log10 y  log10 a  b log10 x .

Substituting, Y  log10 y , X  log10 x , A  b , B  log10 a .

Then the equation takes the linear form Y  A X  B .

3) y  a eb x

Taking common logarithms { log10 } on both sides we get,

log10 y  log10 a  (b log10 e) x .

Putting Y  log10 y , X  x then the equation takes the linear form Y  A X  B where

A  b log10 e , B  log10 a .

4) x y n  a

Taking common logarithms { log10 } on both sides, we get,

1
log10 x  n log10 y  log10 a that is, log10 y   log10 a  log10 x  .
n
Putting Y  log10 y , X  log10 x then the equation takes the linear form Y  A X  B

1 1
where A  and B  log10 a .
n n

EXERCISE – 1.1
Convert the following equations into linear form
x a xb
(a) y  ; (b) y  ; (c) y  a  b x y ;
abx x
b
(d) y  ; (e) x y  a x  b ; (f) y  a x  b x 2 ;
x ( x  a)

(g) x a y  b ; (h) y  a b x .

NUMERICAL ANALYSIS – CURVE FITTING Page 2 of 12


COLLEGE OF SCIENCE AND TECHNOLOGY, R.U.B, P/LING:: BHUTAN S.T.VENKATESAN

The Method of Least Squares:


Among the many methods available for curve fitting the most popular method is the Method of
Least Squares. This method of curve fitting was suggested early in the nineteenth century by the
French mathematician Adrien Legendre. Principle of Least Square provides a unique set of values
to the constants and hence suggests a curve of best fit to the given data.

Let ( xi , yi ) : i  1, 2, , n be n sets of observations and let y  f ( x) (1.1) be the relation

suggested between x and y. When x  xi the Observed value of yi is yi  PM


i i and the

corresponding Expected value = Li M i  f ( xi ) . Observed value – Expected value = error.

Therefore, Residual (or error) at x  xi is ei  yi  f ( xi ) .

Y
Pi

P1 P4 Li

L2 L3
y = f(x) L4
L1
P2 P3

O(0 , 0)
M1 M2 M3 M4 Mi
Fig: 1.1

It is obvious that some of ei ' s may be  ve or  ve . Thus by giving equal weightage to each
n n
residuals, consider E   ei2   [ yi  f ( xi ) ]2 (1.2 )
i 1 i 1

Now, if E  0 then yi  f ( xi )  i ; that is, all the points lie on the curve.

Otherwise the minimum of E results the best fitting curve to the data.
The Principle of Least Squares states that the sum of the squares of the residuals is minimum.
This principle does not suggest to determine the form of the curve y  f ( x) but it determine the
values of the parameters or constants of the equation of the curve.

NUMERICAL ANALYSIS – CURVE FITTING Page 3 of 12


COLLEGE OF SCIENCE AND TECHNOLOGY, R.U.B, P/LING:: BHUTAN S.T.VENKATESAN
Using this principle we shall fit the following curves.
(A) A straight line. (B) A second degree parabola. (C) An exponential curve. (D) Any curve.

(A) Fitting a Straight line. y  a x  b (1.3) .

Consider the fitting of the straight line y  a x  b to the data ( xi , yi ) : i  1, 2, ,n.

The residual ei is given by ei  yi  f ( xi ) , here ei  yi  ( a xi  b ) .


n n
Therefore, E   ei2   [ yi  a xi  b ]2 . According to the Principle of Least Squares we
i 1 i 1

E E
have to determine the parameters a and b so that E is minimum i.e.,  0 and 0 .
a b
E
 0   2  ( yi  a xi  b ) xi  0   ( yi xi  a xi2  b xi )  0
a

  yi xi  a  xi2  b  xi (1.4 )

E
 0   2  ( yi  a xi  b )  0   yi  a  xi  nb (1.5)
b
Since xi , yi are known, equations (1.4) and (1.5) results two equations in a and b. Solving

these, the best values for a and b can be known and hence equation (1.3) straight line.
The equations (1.4) and (1.5) are called Normal equations to the straight line (1.3).

Note to obtain the normal equations: y  a x  b is the straight line and its normal

equations are y  a x  n b and xy  a x 2  b x , which are got by taking  on both


sides of the straight line, and also taking  on both sides after multiplying by x both sides of
the straight line.

(B) Fitting a second degree Parabola. y  a x2  b x  c (1.6 )

Consider the fitting of the parabola y  a x2  b x  c to the data ( xi , yi ) : i  1, 2, ,n.

The residual ei is given by ei  yi  f ( xi ) , here ei  yi  ( a xi2  b xi  c ) . Therefore,


n n
E  ei2   [ yi  ( a xi2  b xi  c ) ]2 . Now E should be minimum for the best values of
i 1 i 1

E E E
a , b , c by Principles of Least Squares i.e., 0,  0 and 0 .
a b c

NUMERICAL ANALYSIS – CURVE FITTING Page 4 of 12


COLLEGE OF SCIENCE AND TECHNOLOGY, R.U.B, P/LING:: BHUTAN S.T.VENKATESAN
E
 0   2  ( yi  a xi2  b xi  c ) xi2  0   ( yi xi2  a xi4  b xi3  c xi2 )  0
a

  yi xi2  a  xi4  b  xi3  c  xi2 (1.7 )

E
 0   2  ( yi  a xi2  b xi  c ) xi  0   ( yi xi  a xi3  b xi2  c xi )  0
b

  yi xi  a  xi3  b  xi2  c  xi (1.8)

E
 0   2  ( yi  a xi2  b xi  c )  0   yi  a  xi2  b  xi  n c (1.9 )
c
Equations (1.7), (1.8) and (1.9) are called Normal equations of the parabola (1.6).

Solving these normal equations we get the best values of a , b , c and hence best fit of
equation (1.6).

Note to obtain the normal equations:

y  a x2  b x  c is the second degree parabola, to obtain its normal equation take  on

both sides we get y  a x2  b x  nc . In the second degree parabola multiply by x both

sides and then take  on both sides we get xy  a x 3  b x 2  c x . Again in the second

degree parabola multiply by x 2 both sides and then take  on both sides we get

x2 y  a x4  b x3  c x2 .

(C) Fitting an Exponential curve. y  a eb x (1.10 ) where a  0 .

Exponential curves can be brought to linear form by suitable transformation of variables.


Taking common logarithms { log10 } on both sides of equation (10), we get,

log10 y  log10 a  (b log10 e) x .

Putting Y  log10 y , X  x then the equation takes the linear form

Y  AX B (1.11) where A  b log10 e , B  log10 a .

By using the Principle of Least Squares, the Normal equations for (1.11) are

Y  A X  n B (1.12) and  X Y  A X 2  B  X (1.13)

Solving the equations (1.12) and (1.13), we get A and B.


A
Hence, a  anti log10 ( B ) and b  . Substituting a and b in equation (1.10).
log10 e

NUMERICAL ANALYSIS – CURVE FITTING Page 5 of 12


COLLEGE OF SCIENCE AND TECHNOLOGY, R.U.B, P/LING:: BHUTAN S.T.VENKATESAN

(D) Fitting any curve. y  a xb (1.14 ) where a  0 . y  a. b x (1.15) where a , b  0 .

Curves of the form, equation (1.14), equation (1.15) or any other form, can be brought to
linear form by suitable transformation of variables. { Refer equations converting into linear
law }. Then using the Principle of Least Squares the curve of best fit can be achieved.
----------------------------------------------------------------------------------------------------------- -------
Calculation of the sum of the squares of the residuals in the case of Straight line fit:
In fitting a straight line, we know that the sum of the squares of the residuals E is given by
E   [ y  (a x  b ) ]2   [ y  (a x  b )][ y  (a x  b )]

   y [ y  (a x  b )]  a x [ y  (a x  b )]  b [ y  (a x  b )] 

  y [ y  (a x  b )]  a x [ y  (a x  b )]  b  [ y  (a x  b )]   y [ y  (a x  b )]  a (0)  b (0)
Since the last two sums vanish due to normal equations of the straight line.
Therefore, E   y 2  a  xy  b  y . When we fit a straight line by the method of least squares, the

error committed (which is minimum) is given by E   y 2  a  xy  b  y .

Note: To remember this formula, multiply y  (a x  b ) by y and take  .

Calculation of the sum of the squares of the residuals in the case of Parabola fit:
In fitting a parabola, we know that the sum of the squares of the residuals E is given by
E   [ y  (a x 2  b x  c) ]2   [ y  (a x 2  b x  c) ][ y  (a x 2  b x  c) ]

   y [ y  (ax 2  bx  c)]  ax 2 [ y  (ax 2  bx  c)]  bx[ y  (ax 2  bx  c)]  c[ y  (ax 2  bx  c)]

  y[ y  (ax 2  bx  c)]  ax 2 [ y  (ax 2  bx  c)]  bx[ y  (ax 2  bx  c)]  c[ y  (ax 2  bx  c)]

  y [ y  (ax 2  bx  c)]  a (0)  b (0)  c (0)


Since the last three sums vanish due to normal equations of the second degree parabola.
Therefore, E   y 2  a  x 2 y  b  xy  c  y . When we fit a straight line by the method of least

squares, the error committed (which is minimum) is given by E   y 2  a  x 2 y  b  xy  c  y .

Note: To remember this formula, multiply y  (a x 2  b x  c) by y and take  .

NUMERICAL ANALYSIS – CURVE FITTING Page 6 of 12


COLLEGE OF SCIENCE AND TECHNOLOGY, R.U.B, P/LING:: BHUTAN S.T.VENKATESAN
SOLVED PROBLEMS

Problem 1: By the Method of Least Squares, find the straight line that best fit the following data:
x 1 2 3 4 5
y 14 27 40 55 68

Solution: Let the Straight line to be fitted to the given data be y  a x  b (i ) .


Here n  5 . The parameters a and b are got from the Normal equations.
The Normal equations of the Straight line ( i ) are

 y  a x  nb ( ii ) and  x y  a  x2  b  x ( iii )

The values of  x ,  y ,  x 2 and  x y are calculated as shown below:

Sl. No. x y x.y x2


1 1 14 14 1
2 2 27 54 4
3 3 40 120 9
4 4 55 220 16
n=5 5 68 340 25
Total  x = 15 204 748 55

Therefore, the Normal equations ( ii ) and ( iii ) becomes,


204  15 a  5 b ( iv ) and 748  55 a  15 b (v) .
Solving the equations ( iv ) and ( v ) for a and b, we get a  13.6 and b  0 .
Substituting these values in ( i ) , we get the required Straight line of best fit for the given data is

y  13.6 x

Problem 2: Fit a second degree Parabola by taking x as the independent variable in Least Square
sense to the given data:
x 0 1 2 3 4
y 1 5 10 22 38

Solution: Let the second degree Parabola to be fitted to the given data be y  a x2  b x  c (i )
Here n  5 . The Normal equations of the Parabola ( i ) to find a , b , c are given by

NUMERICAL ANALYSIS – CURVE FITTING Page 7 of 12


COLLEGE OF SCIENCE AND TECHNOLOGY, R.U.B, P/LING:: BHUTAN S.T.VENKATESAN
 y  a  x2  b  x  nc ( ii ) ,  x y  a  x3  b  x2  c  x ( iii ) and

 x 2 y  a  x 4  b  x3  c  x 2 ( iv )

The values of  x ,  y ,  x 2 ,  x y , etc., are calculated below:

Sl. No. x y x.y x2 x2 y x3 x4


1 0 1 0 0 0 0 0
2 1 5 5 1 5 1 1
3 2 10 20 4 40 8 16
4 3 22 66 9 198 27 81
n=5 4 38 152 16 608 64 256
Total  x = 10 76 243 30 851 100 354

Therefore, the Normal equations ( ii ) , ( iii ) and ( iv ) becomes,

76  30 a  10 b  5 c ( v ) , 243  100 a  30 b  10 c ( vi ) and

851  354 a  100 b  30 c ( vii ) .


Solving the equations ( v ) , ( vi ) and ( vii ) for a , b , c .
We get, a  2.21429 , b  0.24284 and c  1.42858 .
Substituting these values in ( i ) , we get the required second-degree Parabola of best fit for the

given data is y  2.21429 x 2  0.24284 x  1.42858 .

Problem 3: Fit the curve of best fit of the type y  a eb x to the following data by the Method of
Least Squares:
x 1 5 7 9 12
y 10 15 12 15 21

Solution: Let the Exponential equation to be fitted for the given data be y  a eb x (i )
Taking common logarithms { log10 } on both sides of equation (i),

We get, log10 y  log10 a  (b log10 e) x .

Then the equation takes the linear form Y  A X  B ( ii )

Where Y  log10 y , X  x , A  b log10 e , B  log10 a .

The Normal equations of the Straight line ( ii ) are

Y  A X  n B ( iii ) and  X Y  A  X 2  B  X ( iv ) .
NUMERICAL ANALYSIS – CURVE FITTING Page 8 of 12
COLLEGE OF SCIENCE AND TECHNOLOGY, R.U.B, P/LING:: BHUTAN S.T.VENKATESAN
The parameters A and B are got from the Normal equations.
A
Hence, a  anti log10 ( B ) and b   A  log e 10 . Here n  5 .
log10 e

The values of  X ,  Y ,  X 2 and  X Y are calculated as shown below:

Sl. No. x=X y Y = log10 (y) X2 X*Y


1 1 10 1 1 1
2 5 15 1.17609 25 5.88045
3 7 12 1.07918 49 7.55426
4 9 15 1.17609 81 10.58481
n=5 12 21 1.32222 144 15.86664
Total 34 5.75358 300 40.88616

Substituting the table values in the Normal equations (iii) and (iv), we get
5.75358  34 A  5 B ( v ) and 40.88616  300 A  34 B ( vi )
On solving (v) and (vi) A  0.02561 ; B  0.97658 .
A
Therefore, a  anti log10 ( B )  9.47502 and b   A  log e 10  0.05897 .
log10 e

Hence the required Exponential curve (i) is y  (9.47502) e (0.05897) x .

Problem 4: Obtain a relation of the form y  a . b x for the following data by the Method of Least
Squares:
x 2 3 4 5 6
y 8.3 15.4 33.1 65.2 127.4

Solution: Let the curve to be fitted is y  a .b x (i )


Taking common logarithms { log10 } on both sides of equation (i),

We get, log10 y  log10 a  x log10 b .

Then the equation takes the linear form Y  A X  B ( ii )

Where Y  log10 y , X  x , A  log10 b , B  log10 a .

The Normal equations of the Straight line ( ii ) are

Y  A X  n B ( iii ) and  X Y  A  X 2  B  X ( iv ) .

NUMERICAL ANALYSIS – CURVE FITTING Page 9 of 12


COLLEGE OF SCIENCE AND TECHNOLOGY, R.U.B, P/LING:: BHUTAN S.T.VENKATESAN
The parameters A and B are got from the Normal equations.
Hence, a  anti log10 ( B ) and b  anti log10 ( A ) . Here n  5 .

The values of  X ,  Y ,  X 2 and  X Y are calculated as shown below:

Sl. No. x=X y Y = log10 (y) X^2 X*Y


1 2 8.3 0.91908 4 1.83816
2 3 15.4 1.18752 9 3.56256
3 4 33.1 1.51983 16 6.07932
4 5 65.2 1.81425 25 9.07125
n=5 6 127.4 2.10517 36 12.63102
Total = 20 7.54585 90 33.18231

Substituting the value of  X ,  Y ,  X 2 and  X Y from the above table in the Normal equations
(iii) and (iv), we get 7.54585  20 A  5 B ( v ) and 33.18231  90 A  20 B ( vi )
On solving (v) and (vi) A  0.29989 ; B  0.30961 .

Therefore, a  anti log10 ( B )  2.03991 and b  anti log10 ( A )  1.99476 .

Hence the required curve (i) is y  2.03991  (1.99476) x .

-------------------------------------------------------------------------------------------------------------------

EXERCISE – 1.2

1) A simply supported beam carries a concentrated load P (lb) at its mid–point. Corresponding
to various values of P, the maximum deflection Y (in) is measured. The data are given
below. Find a law of the type Y  a  b P .

P 100 120 140 160 180 200


Y 0.45 0.55 0.60 0.70 0.80 0.85

2) If P is the pull required to lift a load W by means of a pulley block, find a Linear law of the
form P  mW  c connecting P and W, using the data:

P 12 15 21 25
W 50 70 100 120
where P and W are taken in kg – wt.

NUMERICAL ANALYSIS – CURVE FITTING Page 10 of 12


COLLEGE OF SCIENCE AND TECHNOLOGY, R.U.B, P/LING:: BHUTAN S.T.VENKATESAN

3) Fit the curve p v  k to the following data:

p (kg / cm 2 ) 0.5 1 1.5 2 2.5 3


v (liters) 1620 1000 750 620 520 460

4) The pressure of the gas corresponding to various volumes V is measured, given by the
following data:

V (cm 3 ) 50 60 70 90 100
P (kg / cm 2 ) 64.7 51.3 40.5 25.9 78

Fit the data to the equation PV   c .

a
5) Use the method of Least Squares to fit the curve: y   b x to the following table of
x
values:

x 0.1 0.2 0.4 0.5 1 2


y 21 11 7 6 5 6

6) The voltage V across a capacitor at time t seconds is given by the following table. Use the
Principle of Least Squares to fit a curve of the form V  a e k t to the data:

t 0 2 4 6 8
V 150 63 28 12 5.6

7) Find the second degree Parabola which fits most closely with observations:

x -3 -2 -1 0 1 2 3
y 4.63 2.11 0.67 0.09 0.63 2.15 4.58

8) By proper transformation, convert the relation y  a  b x y to a linear form and find the
equation to fit the data:
x -4 1 2 3
y 4 6 10 8

9) Fit a straight line and a parabola to the following data and find out which one is most
appropriate. Reason out for your conclusion.
x 0 1 2 3 4
y 1 1.8 1.3 2.5 6.3

NUMERICAL ANALYSIS – CURVE FITTING Page 11 of 12


COLLEGE OF SCIENCE AND TECHNOLOGY, R.U.B, P/LING:: BHUTAN S.T.VENKATESAN

10) Short Answer Questions:


A) What is Principle of Least Squares ?
B) What are the Normal equations in fitting a Straight line or a Parabola ?
C) In fitting a Straight line y  a x  b , what is the formula to find the sum of the squares of
the residuals ?
D) In fitting a Parabola y  a x2  b x  c , what is the formula to find the sum of the squares
of the residuals ?
E) In fitting a Straight line y  a x  b ,  x   6,  y  12,  x2  54,  x y  12 then find
the Straight line.

11) Say True or False: (i) In fitting the best fitting Straight line, the line must pass through
two paired data. (ii) You are given ( xi , yi ), i  1, , n and a Parabola is fitted to them. It is

possible that no point of the system may lie on the Parabola.


------------------------

NUMERICAL ANALYSIS – CURVE FITTING Page 12 of 12

You might also like