Curve Fitting
Curve Fitting
Dr. K. Murugesan
Professor(HAG)
Department of Mathematics
National Institute of Technology, Tiruchirappalli 620015,
Tamil Nadu, India
Email : [email protected]
[Curve fitting - method of group averages - method of least squares - Solving difference equation with constant
coefficients ]
1
CURVE FITTING
1 Introduction
Very often in engineering and science, we obtain experimentally a number of corresponding values of
two variables x and y. It will be necessary to find a mathematical relation between them. This relation
when written as an equation y = f (x), is called an empirical equation. Many times we may not able to
get an exact relation but we may get only an approximate curve. This approximating curve is an empirical
equation and the method of finding such an approximating curve is called curve fitting.
The constants occurring in the equation of the approximating curve can be found by various methods.
If (xi , yi ), i = 1, 2, . . . n are the n paired data which are plotted on the graph sheet, it is possible to draw a
number of smooth curves passing through the points. So the approximating curve is not unique.
y = a + bx. (2.1)
We assume that the law is a linear one. We want to determine a and b. By assumption, y = a + bx is the
law, it doesn’t mean the points lie on the straight line. It is only an approximating straight line and it is
possible that no point may lie on the line.
y
Pn (xn , yn )
Pn (xn , yn )
Qn
P3 (x3 , y3 )
P3 (x3 , y3 )
Q3
Q2
P1 (x1 , y1 )
P1 (x1 , y1 )
Q1
P2 (x2 , y2 )
P2 (x2 , y2 )
x
M1 M2 M3 Mn
2
We plot the points (xi , yi ) by Pi , i = 1, 2, . . . n. The ordinates at x = xi , meets the straight line at Qi ,
i = 1, 2, . . . n. We have,
Pi Mi = yi = observed value of y at xi
Qi Mi = a + bxi = expected value of y at xi
di = Qi Pi = Pi Mi − Qi Mi = yi − (a + bxi )
which is the difference between the observed values y and the expected value of y is called the residual at
x = xi . In general di ’s may be positive or negative.
Principle: The method of group averages is based on the principle that the sum of the residuals at all points
P
is zero. That is di = 0.
Since we require two equations to find two unknowns a and b, we divide the given data into two groups,
first one containing γ sets of values and the other containing n − γ sets of values. We apply the principle
P
di = 0 for each group. Now consider the first group.
γ
X
[yi − (a + bxi )] = 0.
i=1
γ
X γ
X
=⇒ yi = (a + bxi ).
i=1 i=1
Xγ Xγ
=⇒ γa + b xi = yi
i=1 i=1
Pγ Pγ
i=1 xi i=1 yi
=⇒ a + b =
γ γ
=⇒ a + bx1 = y1 (2.2)
where x1 , y1 are the averages of x’s and y’s of the first group.
Now considering the second group,
n
X
[yi − (a + bxi )] = 0.
i=γ+1
n
X n
X
=⇒ yi = (a + bxi ).
i=γ+1 i=γ+1
Xn Xn
=⇒ (n − γ)a + b xi = yi .
i=γ+1 i=γ+1
Pn ! Pn
i=γ+1 xi i=γ+1 yi
=⇒ a + b =
(n − γ) (n − γ)
=⇒ a + bx2 = y2 (2.3)
where x2 , y2 are the averages of x’s and y’s of the second group.
From (2.2) and (2.3), we determine the values of a and b. Using these values in (2.1) we get the relation
y = a + bx.
3
Remark:
1. The answer is not unique since the grouping can be done in many ways. This is an important defect
of this method.
2. In general, we shall divide the data into two groups so that both contain the same number of points.
3. The relation we found using this method is a straight line passes through the points (x1 , y1 ) and
(x2 , y2 ). Hence the equation can be determine using the following formula
y − y1 y1 − y2
=
x − x1 x1 − x2
Example.
1. Find a straight line fit of the form y = a + bx, by the method of group averages for the following data.
x : 0 5 10 15 20 25
y : 12 15 17 22 24 30
Solution.
Let us divide the data into two groups each containing three sets of data.
Group I Group II
x y x y
0 12 15 22
5 15 20 24
10 17 25 30
P P P P
x =15 y =44 x =60 y =76
15
x1 = =5
3
44
y1 = = 14.6666
3
60
x2 = = 20
3
76
y2 = = 25.3333
3
Substituting the average values of each group in the relation y = a + bx, we get
a + 5b = 14.6666
a + 20b = 25.3333
4
2. The following numbers relate to the flow of water over a triangular notch.
H : 1.2 1.4 1.6 1.8 2.0 2.4
Q : 4.2 6.1 8.5 11.5 14.9 23.5
If the law is Q = CH n , find C and n by the method of group averages.
Solution.
Given the law is Q = CH n .
By taking logarithm on both sides we have,log10 Q = log10 C +n log10 H. This is of the form y = a+nx
where log10 Q = y, log10 C = a and log10 H = x. Now we can fit a straight line y = a + nx.
Let us divide the data into two groups each containing three sets of data.
Group I Group II
x = log10 H y = log10 Q x = log10 H y = log10 Q
0.07918 0.62325 0.25527 1.06070
0.14163 0.78533 0.30103 1.17319
0.20412 0.92942 0.38021 1.37107
P P P P
x =0.42493 y =2.33800 x =0.93651 y =3.60496
0.42493
x1 = = 0.14164
3
2.33800
y1 = = 0.77933
3
0.93651
x2 = = 0.31217
3
3.60496
y2 = = 1.20165
3
Substituting the average values of each group in the relation y = a + nx, we get
a + (0.14164)n = 0.77933
a + (0.31217)n = 1.20165
3. Fit a curve of the form y = a + bx3 by the method of group averages given that
x : 5 7 9 11 12
y : 290 560 1144 1810 2300
Solution.
Put x3 = X. Then the law becomes to the form we required, that is y = a + bX
5
Group I Group II
3
X=x y X = x3 y
125 290 1331 1810
343 560 1728 2300
729 1144
P P P P
X =1197 y =1994 X =3059 y =4110
1197
X1 = = 399
3
1994
y1 = = 664.66
3
3059
X2 = = 1529
2
4110
y2 = = 2055
2
Substituting the average values of each group in the relation y = a + bX, we get
a + (399)b = 664.66
a + (1529)b = 2055
In this case first we reduce the given equation to a linear one and from which, two unknowns can be
found as in the previous section.
The curve we want to fit is
y = a + bx + cx2 (2.4)
Assume that a particular point (x1 , y1 ) satisfies the equation (2.4). That is
y − y1 = b(x − x1 ) + c(x2 − x1 2 )
y − y1
= b + c(x + x1 )
x − x1
6
y − y1
Setting = Y and x + x1 = X, the equation becomes
x − x1
Y = b + cX
which is linear in X and Y . Now b and c can be found out by the previous method of group averages.
Example.
1. The data given below will fit a formula of the type y = a + bx + cx2 . Find the formula.
x : 87.5 84.0 77.8 63.7 46.7 36.9
y : 292 283 270 235 197 181
Solution.
Take the point (87.5,292) as the particular point on the curve.
y = a + bx + cx2 (2.6)
2
292 = a + (87.5)b + (87.5) c (2.7)
2
y − 292 = b(x − 87.5) + c(x2 − (87.5) )
y − 292
= b + c(x + 87.5)
x − 87.5
y − 292
Take Y = and X = x + 87.5, we have Y = b + cX
x − 87.5
Let us divide the data into two groups each containing three sets of data.
Group I Group II
y−292 y−292
x y X = x + 87.5 Y = x−87.5 x y X = x + 87.5 Y = x−87.5
87.5 292 - - 63.7 235 151.2 2.3950
84.0 283 171.5 2.5714 46.7 197 134.2 2.3284
77.8 270 165.3 2.2680 36.9 181 124.4 2.1937
P P P P
X =336.8 Y =4.8394 X =409.8 Y =6.9171
336.8
X1 = = 168.4
2
4.8394
Y1 = = 2.4197
2
409.8
X2 = = 136.6
3
6.9171
Y2 = = 2.3057
3
7
Substituting the average values of each group in the relation Y = b + cX, we get
b + (168.4)c = 2.4197
b + (136.6)c = 2.3057
Y = 1.8168 + (0.00358)X
y − 292
= 1.8168 + (0.00358)(x + 87.5)
x − 87.5
= (0.00358)x + 2.13
y − 292 = (x − 87.5)[(0.00358)x + 2.13]
y = (0.00358)x2 + 1.81675x + 105.62
First we will get the value of c so that the points (x1 , y1 ), (x2 , y2 ), (x3 , y3 ) be three points on the curve
y = axb + c where x1 , x2 , x3 are in geometric progression. (i.e, x2 2 = x1 x3 ). Substituting these points on
the curve
y = axb + c, (2.8)
we have,
y1 − c = ax1 b
y2 − c = ax2 b
y3 − c = ax3 b
b
Now, (y1 − c)(y3 − c) = a2 (x1 x3 )
= a2 (x2 2 )b
= (ax2 b )2
= (y2 − c)2
y1 y3 − c(y1 + y3 ) + c2 = y2 2 + c2 − 2cy2
y1 y3 − y2 2
c=
y1 + y3 − 2y2
Using the value of c in (2.8) we have only 2 unknowns left out. Taking logarithm on both sides of (2.8),
8
It is of the form Y = A + bX where Y = log10 (y − c), A = log10 a, X = log10 x which is linear in X and Y .
Example.
1. Fit a curve of the form y = axb + c to the following data.
x : 2 4 6 8 10
y : 5.0 8.6 13.9 25.3 35.6
Solution
We search for three values of x’s which are in G.P.
∴, x1 = 2, x2 = 4, x3 = 8 so that x1 x3 = x2 2
The value of c can be obtained from
y1 y3 − y2 2
c=
y1 + y3 − 2y2
5(25.3) − (8.6)2
=
5 + 25.3 − 2(8.6)
= 4.01
y = axb + 4.01
y − 4.01 = axb (2.9)
Group I
x y X = log10 x y − 4.01 Y = log10 (y − 4.01)
2 5.0 0.3010 0.99 -0.0044
4 8.6 0.6020 4.59 0.6618
6 13.9 0.7782 9.89 0.9952
P P
X =1.6812 Y =1.6526
Group II
x y X = log10 x y − 4.01 Y = log10 (y − 4.01)
8 25.3 0.9031 21.29 1.3281
10 35.6 1.0000 31.59 1.4995
P P
X =1.9031 Y =2.8276
9
1.6812
X1 = = 0.5604
3
1.6526
Y1 = = 0.5509
3
1.9031
X2 = = 0.9516
2
2.8276
Y2 = = 1.4138
2
Substituting the average values of each group in the relation Y = A + bX, we get
A + (0.5604)b = 0.5509
A + (0.9516)b = 1.4138
If the curve is of the form y = abx + c, we select three points (x1 , y1 ), (x2 , y2 ), (x3 , y3 ) be three points
on the curve where x1 , x2 , x3 are in arithmetical progression. (i.e, x1 + x3 = 2x2 ).
Substituting these points on the curve
y = abx + c, (2.10)
we have,
y1 − c = abx1
y2 − c = abx2
y3 − c = abx3
y − c = abx
log10 (y − c) = log10 a + x log10 b
10
It can be written in the form Y = A + Bx where Y = log10 (y − c), A = log10 a, B = log10 b which is linear
in x and Y .
y = aebx + c
= a(eb )x + c
= ak x + c where k = eb (2.11)
Example.
1. The temperature θ of a vessel of cooling water and the time t in minutes since the beginning of
observation are connected by the law of the form θ = aebt + c. The corresponding values of θ and t are
given by
t : 0 1 2 3 5 7 10 15 20
θ : 52.2 48.8 46.0 43.5 39.7 36.5 33.0 28.7 26.0
Find the best values of a, b, c.
Solution
Search for values of t which are in A.P.
Take t1 = 0, t2 = 10, t3 = 20 which are in A.P.
θ1 = 52.2, θ2 = 33, θ3 = 26.0. The value of c can be obtained from
θ1 θ3 − θ2 2
c=
θ1 + θ3 − 2θ2
52.2(26.0) − (33)2
=
52.2 + 26.0 − 2(33)
= 21.98
θ − 21.98 = aebt .
It can be written in the form Y = A + Bt where Y = log10 (θ − 21.98), A = log10 a, B = b log10 e which
is linear in t and Y . Now the unknowns A and B can be found by the previous method for linear fit.
Let us divide the data into two groups.
11
Group I
t θ θ − 21.98 Y = log10 (θ − 21.98)
0 52.2 30.22 1.4803
1 48.8 26.82 1.4284
2 46.0 24.02 1.3806
3 43.5 21.52 1.3328
P P
X =6 Y =5.6221
Group II
t θ θ − 21.98 Y = log10 (θ − 21.98)
5 39.7 17.72 1.2485
7 36.5 14.52 1.1620
10 33.0 11.02 1.0422
15 28.7 6.72 0.8274
20 26.0 4.02 0.6042
P P
X =57 Y =4.8843
6
t1 = = 1.5
4
5.6221
Y1 = = 1.4055
4
57
t2 = = 11.4
5
4.8843
Y2 = = 0.9769
5
Substituting the average values of each group in the relation Y = A + Bt, we get
A + (1.5)B = 1.4055
A + (11.4)B = 0.9769
Exercise.
1. By the method of group of averages, fit a straight line to the following data:
x : 0 5 10 15 20 25
y : 12 15 17 22 24 30
12
b
2. Convert the equation y = to a linear form and hence determine a and b. Which will best fit
x(x − a)
the following data:
x : 3.6 4.8 6.0 7.2 8.4 9.6 10.8
y : 0.83 0.31 0.17 0.10 0.07 0.05 0.04
3. Find the best values of a and b if the following data given are related by y = ax + bx2 .
x : 1 2 3 4 5 6
y : 2.6 5.4 8.7 12.1 16 20.2
4. The following pairs of values were found for the potential difference V volts and the current A amperes
in an electric circuit and are given below:
V : 50.3 47.3 46.8 45.1 43.6
A : 1.96 2.98 3.96 5.96 9.57
Find the curve of the form V = a + Ab .
5. If p is the pull required to lift a weight w by means of a pully block, find a law of the form p = a + bw
from the following data:
w : 50 70 100 120
p : 12 15 21 25
1
6. Fit a curve of the form x = a + by given the data:
y : 0 1 2.5 5 10
x : 1.02 0.08 0.62 0.46 0.32
13
y
Pn (xn , yn )
Pn (xn , yn )
Qn
P3 (x3 , y3 )
P3 (x3 , y3 )
Q2 Q3
P1 (x1 , y1 )
P1 (x1 , y1 )
Q1
P2 (x2 , y2 )
P2 (x2 , y2 )
x
M1 M2 M3 Mn
y = f (x) (3.1)
be the relation suggested between x and y. Let (xi , yi ) be represented by the point Pi . Let the ordinate at
Pi meet y = f (x) at Qi , and the x-axis at Mi .
M i Pi = y i
Mi Qi = f (xi )
Qi Pi = Mi Pi − Mi Qi = yi − f (xi ), i = 1, 2, 3, . . . , n
di = yi − f (xi ) is called the residual at x = xi . Some of the di ’s may be positive and some may be negative.
n
X n
X
E= di 2 = [yi − f (xi )]2
i=1 i=1
is the sum of the squares of the residuals. If E = 0, i.e, each di = 0, then all the n points Pi will lie on
y = f (x). If not, we will choose f (x) such that E is minimum. That is, the best fitting curve to the set of
points is that for which E is minimum. This principle is known as the principle of least squares or the
least square criterion.
This principle does not suggest to determine the form of the curve y = f (x) but it determines the values
of the parameters or constants of the equation of the curve.
14
n
X n
X
2
E= di = [yi − (axi + b)]2
i=1 i=1
∂E ∂E
= 0 and =0
∂a ∂b
∂E
consider,
=0
∂a
X
2 [yi − (axi + b)](−xi ) = 0
n
X
(xi yi − ax2i − bxi ) = 0
i=1
n
X n
X n
X
a x2i + b xi = xi yi (3.2)
i=1 i=1 i=1
∂E
=0
consider,
∂b
X
2 [yi − (axi + b)](−1) = 0
n
X
(yi − axi − b) = 0
i=1
Xn n
X
a xi + nb = yi (3.3)
i=1 i=1
The equations (3.2) and (3.3) are called normal equations. By solving them, we can find a and b.
Example
1. Fit a straight line to the data given below. Also estimate the value of y at x = 2.5.
x : 0 1 2 3 4
y : 1 1.8 3.3 4.5 6.3
Solution.
Let the best fit be y = ax + b.
The normal equations are
X
X
a
x + 5b = y
X X X
a x2 + b x= xy
15
x y x2 xy
0 1.0 0 0
1 1.8 1 1.8
2 3.3 4 6.6
3 4.5 9 13.5
4 6.3 16 25.2
2
P P P P
x =10 y =16.9 x = 30 xy = 47.1
10a + 5b = 16.9
30a + 10b = 47.1
Solving for a and b we have, a = 1.33, b = 0.72. Substituting the values of a and b in the equation of
linear fit, we have,y = 1.33x + 0.72
When x = 2.5 , the value of y becomes y(2.5) = 1.33(2.5) + 0.72 = 4.045.
2. Fit a straight line to the following data. Also estimate the value of y at x = 70.
x : 71 68 73 69 67 65 66 67
y : 69 72 70 70 68 67 68 64
Solution.
Since the values of x and y are larger, we choose the origins for x and y at 69 and 67 respectively. In
other words, we transform x and y.
Let X = x − 69, and Y = y − 67.
Let Y = aX + b be the fit.
The normal equations are
X X
a
X + 8b = Y
X X X
a X2 + b X= XY
x y X Y X2 XY
71 69 2 2 4 4
68 72 -1 5 1 -5
73 70 4 3 16 12
69 70 0 3 0 0
67 68 -2 1 4 -2
65 67 -4 0 16 0
66 68 -3 1 9 -3
67 64 -2 -3 4 6
2
P P P P
X = -6 Y = 12 X = 54 XY = 12
16
Therefore the normal equations become,
−6a + 8b = 12
54a − 6b = 12
Solving for a and b we have, a = 0.4242, b = 0.1818. Substituting the values of a and b in the equation
of linear fit, we have,
Y = 0.4242X + 0.1818
y − 67 = 0.4242(x − 69) + 0.1818
y = 0.4242x + 37.909
3. By proper transformation, convert the relation y = a + bxy to a linear form and find the equation to
fit the data.
x : -4 1 2 3
y : 4 6 10 8
Solution.
Let X = xy ∴ The equation becomes y = a + bX.
The normal equations are
X X X
a X +b X2 = Xy
X X
4a + b X= y
x y X X2 Xy
-4 4 -16 256 -64
1 6 6 36 36
2 10 20 400 200
3 8 24 576 192
2
P P P P
y =28 X = 34 X = 1268 Xy = 364
Solving for a and b we have, a = 5.9069, b = 0.1286. Substituting the values of a and b in the equation
of linear fit, we have,
y = 5.9069 + 0.1286X
y = 5.9069 + 0.1286xy
17
Thus the equation of linear fit is given by y = 5.9069 + 0.1286xy.
The equation can be rewritten as
3.2 Fitting a parabola or fitting a second degree curve by the method of least
squares
Let (xi , yi ), i = 1, 2, . . . n be n sets of observations of two related variables x and y. Let y = ax2 + bx + c
be the equation which fits them best. Now we have to find the constants a, b, c.
For any x = xi , the expected value of y is axi 2 + bxi + c and the corresponding observed value is yi .
The residual di = yi − (axi 2 + bxi + c)
Let E denote the sum of the squares of the residuals.
n
X
E= [yi − (axi 2 + bxi + c)]2
i=1
∂E ∂E ∂E
∴ = 0, = 0 and =0
∂a ∂b ∂c
Simplifying, we get
X X X X
a xi 4 + b xi 3 + c xi 2 = xi 2 yi
X X X X
a xi 3 + b xi 2 + c xi = xi yi
X X X
a xi 2 + b xi + nc = yi
18
Dropping the suffices, the normal equations are
X X X X
a x4 + b x3 + c x2 = x2 y (3.4)
X X X X
a x3 + b x2 + c x= xy (3.5)
X X X
a x2 + b x + nc = y (3.6)
Solving the equations (3.4), (3.5), (3.6) we get the values of a, b, c. Substituting these values of a, b, c in
y = ax2 + bx + c, we get the result.
Example
1. Fit a parabola, by th method of least squares, to the following data; also estimate y at x = 6.
x : 1 2 3 4 5
y : 5 12 26 60 97
Solution
Let y = ax2 + bx + c be the best fit.
The normal equation are
X X X
a x2 + b x + nc = y
X X X X
a x3 + b x2 + c x= xy
X X X X
a x4 + b x3 + c x2 = x2 y
x y x2 x3 x4 xy x2 y
1 5 1 1 1 5 5
2 12 4 8 16 24 48
3 26 9 27 81 78 234
4 60 16 64 256 240 960
5 97 25 125 625 485 2425
2 3 4 2
P P P P P P P
x =15 y =200 x = 55 x = 225 x = 979 xy =832 x y =3672
19
2. Fit a second degree parabola to the data.
x : 1929 1930 1931 1932 1933 1934 1935
y : 352 356 357 358 360 361 361
Solution
Let X = x − 1932, Y = y − 357. Let Y = aX 2 + bX + c be the best fit.
The normal equation are
X X X
a X2 + b X + nc = Y
X X X X
a X3 + b X2 + c X= XY
X X X X
a X4 + b X3 + c X2 = X 2Y
x y X Y X2 X3 X4 XY X 2Y
1929 352 -3 -5 9 -27 81 15 -45
1930 356 -2 -1 4 -8 16 2 -4
1931 357 -1 0 1 -1 1 0 0
1932 358 0 1 0 0 0 0 0
1933 360 1 3 1 1 1 3 3
1934 361 2 4 4 8 16 8 16
1935 361 3 4 9 27 81 12 36
X 2 = 28 X3 = 0 X 4 = 196 X 2Y = 6
P P P P P P P
X=0 Y =6 XY = 40
28a + 7c = 6
28b = 40
196a + 28c = 6
y = abx (3.7)
20
be the best fit for the data. Now, taking logarithm on both sides of (3.7),
where Y = log10 y, A = log10 a, B = log10 b. This is linear in x and Y . The value of A and B can be found
by fitting a straight line as in section 3.1. Using the value of A and B, we can find a and b and hence the
curve y = abx .
y = axb (3.8)
be the best fit for the data. Now, taking logarithm on both sides of (3.8),
where Y = log10 y, A = log10 a, X = log10 x. This is linear in X and Y . The value of A and b can be found
by fitting a straight line as in section 3.1. Using the value of A, we can find a and hence the curve y = axb .
Example
1. From the table given below, find the best values of a and b in the law y = aebx by the method of least
squares.
x : 0 5 8 12 20
y : 3.0 1.5 1.0 0.55 0.18
Solution.
Let
y = aebx (3.9)
21
x y Y x2 xY
0 3.0 0.4771 0 0
5 1.5 0.1761 25 0.8805
8 1.0 0 64 0
12 0.55 −0.2596 144 −3.1152
20 0.18 −0.7447 400 −14.894
2
P P P P
x =45 Y = −0.3511 x =633 xY = − 17.1287
5A + 45B = −0.3511
45A + 633B = −17.1287
y = abx (3.10)
22
x y Y x2 xY
1 151 2.1790 1 2.1790
2 100 2.0 4 4.0
3 61 1.7853 9 5.3559
4 50 1.6990 16 6.7960
5 20 1.3010 25 6.5050
6 8 0.9031 36 5.4186
2
P P P P
x =21 Y =9.8674 x =91 xY = 30.2545
6A + 21B = 9.8674
21A + 91B = 30.2545
3. It is known that the curve y = axb fits in the data given below. Find the best values of a and b.
x : 1 2 3 4 5 6
y : 1200 900 600 200 110 50
Solution.
Let
y = axb (3.11)
23
x y X Y X2 XY
1 1200 0.0 3.0792 0.0 0.0
2 900 0.3010 2.9542 0.0906 0.8892
3 600 0.4771 2.7782 0.2276 1.3255
4 200 0.6021 2.3010 0.3625 1.3854
5 110 0.6990 2.0414 0.4886 1.4269
6 50 0.7781 1.6990 0.6054 1.3220
2
P P P P
x =2.8573 Y =14.8530 X =1.7747 XY = 6.3490
6A + 2.8573b = 14.8530
2.8573A + 1.7747b = 6.3490
In fitting a straight line, we have seen that the sum of the squares of the residuals E is given by,
X
E= [y − (ax + b)]2
X
= [y − (ax + b)][y − (ax + b)]
X
= y[y − (ax + b)] − ax[y − (ax + b)] − b[y − (ax + b)]
X X X
= y[y − (ax + b)] − a x[y − (ax + b)] − b [y − (ax + b)]
X X X
= y2 − a xy − b y
P P
since the last two sums vanish due to normal equations x[y − (ax + b)] = 0 and [y − (ax + b)] = 0.
Thus the error committed(which is minimum), when we fit a straight line by the method of least squares is
given by
X X X
E= y2 − a xy − b y
24
3.5.2 In the case of parabola fit
In fitting a parabola, we have seen that the sum of the squares of the residuals E is given by,
X
E= [y − (ax2 + bx + c)]2
X
= [y − (ax2 + bx + c)][y − (ax2 + bx + c)]
X X X X
= y[y − (ax2 + bx + c)] − a x2 [y − (ax2 + bx + c)] − b x[y − (ax2 + bx + c)] − c [y − (ax2 + bx + c)]
X X X X
= y2 − a x2 y − b xy − c y
Example
1. 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
Solution
x y x2 x3 x4 xy x2 y y2
0 1 0 0 0 0 0 1
1 1.8 1 1 1 1.8 1.8 3.24
2 1.3 4 8 16 2.6 5.2 1.69
3 2.5 9 27 81 7.5 22.5 6.25
4 6.3 16 64 256 25.2 100.8 39.69
2 3 4 2
y 2 =51.87
P P P P P P P P
x =10 y =12.9 x =30 x =100 x =354 xy = 37.1 x y =130.3
that is
10a + 5b = 12.9
30a + 10b = 37.1
25
Solving we get a = 1.13 and b = 0.32. Therefore the best straight line fit is given by
y = 1.13x + 0.32
X X X
Error in this case = E1 = y2 − a xy + b y
that is
Solving we get a = 0.55, b = −1.07 and c = 1.42. Therefore the best parabola fit is given by
.
X X X X
Error in this case = E2 = y2 − a x2 y − b xy − c y
x : 0 1 2 3 4
y by data given : 1 1.8 1.3 2.5 6.3
y by straight line fit : 0.32 1.65 2.98 4.31 5.64
y by parabola fit : 1.42 0.90 1.48 3.16 5.94
26
Exercise
1. The weights of a calf taken at weekly intervals are supplied below. Fit a straight line and calculate the
average rate of growth per week.
Age (x) : 1 2 3 4 5 6 7 8 9 10
Weight (y) : 52.5 58.7 65.0 70.2 75.4 81.1 87.2 95.5 102.2 106.4
2. A rubber band stretched under a force F is found to increase in length l. The following observations
were got.
F : 2 3 4 5 6 7 8 9 10 11 12
l : 10 17 21 28 36 43 51 60 70 83 93
Fit a straight line.
4. The following table gives the levels of prices in certain years. Fit a second degree parabola to the data.
Year : 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885
Price : 88 87 81 78 74 79 85 84 90 92 100
7. Fit the parabola and the straight line of best fit to the following data and out of them which is more
reliable ?
x : −2 1 4 7 10
y : 10.8 1.9 29.2 92 190
Definition
An equation which expresses a relation between the independent variable, the dependent variable and the
successive differences of the dependent variable is called a difference equation.
For example,
27
Using ∆ = E − 1, ∆r = (E − 1)r , and assuming the interval of differencing as 1, we can write
Hence
can be written as
This indicates that a difference equation can be written in various forms such as (4.1), (4.2), (4.3), and (4.4).
The degree of a difference equation written in the form free from ∆’s is the highest power of the y’s. The
5 3
degree of yx+1 yx+2 − yx+1 yx + yx+3 = cosx is of degree 5. Some more examples for order and degree of
difference equation are given below
28
values to the arbitrary constants. For example yx = A.3x + B(−3)x is the general solution of
yx+2 − 9yx = 0
where a0 , a1 , a2 , . . . an and ϕ(x) are known function of x is called a linear difference equation.
The successive values of y viz, yx , yx+1 , yx+2 , . . . occur in the equation only in first degree and are not
multiplied together.
If a0 , a1 , a2 , . . . an are constants then it is called a linear equation with constant coefficients
The equation (4.5) or (4.6) can be written as
f (E)yx = 0 (4.8)
is called homogeneous equation corresponding to (4.7). The solution of the non-homogeneous linear equation
(4.7) depends upon the corresponding homogeneous linear equation (4.8).
Note.
1. If yx = f1 (x) is a solution of homogeneous equation (4.8), then yx = C1 f1 (x) is also a solution of (4.8).
Complementary function
Consider
29
To find complementary function replace E by a in f (E), and f (a) = 0 which is called the auxiliary equation
of (4.9). If the roots of f (a) = 0 are a1 , a2 , . . . , an then the following cases will arise.
3. If a1 = α + iβ, a2 = α − iβ are complex roots and a3 , a4 , . . . an are distinct then yx = rx (c1 cos θx +
p
c2 sin θx + c3 a3 x + . . . + cn an x ) is the complementary function of (4.9) where r = |α + iβ| = α2 + β 2
β
and θ = tan−1 α .
Particular Integral
While finding the particular integral of (4.9) we have the following four types.
Type 1
Suppose ϕ(x) = ax , where a is a constant. Then
ax
P.I = if f (a) ̸= 0.
f (a)
x(r) x−r
P.I = a
r!
ϕ(x)
P.I =
f (E)
= [f (1 + ∆)]−1 ϕ(x)
30
Type 3
Let ϕ(x) = ax F (x) where F (x) is some function of x. Then
F (x)
P.I = ax
f (aE)
Type 4
Let ϕ(x) = cos kx or sin kx
This can be done in two ways.
Or
eikx + e−ikx
Take cos kx =
2
e − e−ikx
ikx
sin kx = and proceed
2
Example
1. Form the difference equation of lowest order by eliminating the arbitrary constants a and b given
(i) y = a.2x + b.3x
(ii) y = (a + bx)2x
Solution.
(i) Given yx = a.2x + b.3x
From which we can write
31
(ii) Given yx = (a + bx)2x
From which we can write
(E 3 − 2E 2 − E + 2)yx = 0.
√
3+1
3. Solve yx+2 − yx+1 + yx = 0 given y0 = 1, y1 = .
2
Solution.
Writing in the shift operator form,
(E 2 − E + 1)yx = 0
√
2 1 3
The auxiliary equation is a − a + 1 = 0 whose roots are ± i
2 2
√ 2
v !
u 2
u 1 3 √ π
r= t + = 1 and θ = tan−1 3 =
2 2 3
π π
∴ yx = 1x A cos x + B sin x
3 3
π π
= A cos x + B sin x
3 3
Since y0 = 1,
√ substituting x = 0 and y = 1 we get
√ A = 1.
3+1 3+1
Since y1 = , substituting x = 1 and y = we get
2 2
√
π π 3+1
y1 = 1 cos + B sin =
3 √ 3 √ 2
1 3 3+1
+ B=
2 2 2
B=1
32
Hence the solution is
πx πx
yx = cos + sin
3 3
√ √
5− 5 5+ 5
Solving for A and B, we get A = , and B = .
10 10
Hence nth term of the sequence is
√ ! √ !n √ ! √ !n
5− 5 1+ 5 5+ 5 1− 5
yn = + .
10 2 10 2
(E 2 − 4E + 3)yn = 2n + 3n + 7.
CF = A.1n + B.3n
= A + B.3n
2n
P.I1 =
E 2 − 4E + 3
2n
= , Replacing E by 2
4−8+3
= −2n
33
3n
P.I2 =
E 2 − 4E + 3
3n
=
(E − 1)(E − 3)
3n 1 3n
= = .
(3 − 1)(E − 3) 2 E−3
1
= .n 3n−1
2
7.1n
P.I3 = 2
E − 4E + 3
7.1n
=
(E − 1)(1 − 3)
−7
= .n 1n−1
2
−7
= n
2
yn = CF + PI
1 7
= A + B.3n − 2n + .n 3n−1 − n
2 2
CF = A.2x + B.(−2)x
9x2
P.I =
E2 − 4
9x2
=
(1 + ∆)2 − 4
9x2
= 2
∆ + 2∆ − 3
1 9x2
=−
3 ∆2 + 2∆
1−
3
2
−1
∆ + 2∆
= −3 1 − x2
3
" 2 #
∆2 + 2∆
2
∆ + 2∆
= −3 1 + + + . . . x2
3 3
2∆ 7 2
= −3 1 + + ∆ + . . . (x(2) + x(1) )
3 9
34
2 7
= −3 (x(2) + x(1) ) + (2x(1) + 1) + (2)
3 9
2 14
= −3 x(x − 1) + x + (2x + 1) +
3 9
4x 20
= −3 x2 + +
3 9
Aliter: To find the P.I assume the particular integral yx = ax2 + bx + c. Substituting in the given
equation
Note.
In the case of unit interval differencing
CF = A.8x + B.(−1)x
x(x − 1).2x
PI =
E 2 − 7E − 8
x(x − 1)
= 2x 2
(2E) − 7(2E) − 8
x(x − 1)
= 2x 2
4E − 14E − 8
35
x(x − 1)
= 2x
4(1 + ∆)2 − 14(1 + ∆) − 8
x(x − 1)
= 2x
4∆2 − 6∆ − 18
x(x − 1)
= 2x−1
2∆2 − 3∆ − 9
−1
2x−1 2∆2 − 3∆
= 1+ x(x − 1)
−9 −9
" 2 2 2 #
1 x−1 2∆ − 3∆ 2∆ − 3∆
= − .2 1+ + + . . . x(2)
9 9 9
1 x−1 ∆ 1 2
= − .2 1− + ∆ + . . . x(2)
9 3 3
1 x−1 (2) 2 (1) 1
= − .2 x − x + (2)
9 3 3
1 x−1 2x 2
= − .2 x(x − 1) − +
9 3 3
1 x−1 2 5 2
= − .2 x − x+
9 3 3
CF = A.ax
cos nx
PI =
E−a
einx
= Real part of
E−a
(ein )x
= R.p of
E−a
einx
= R.p of in
e −a
einx (e−in − a)
= R.p of in
(e − a)(e−in − a)
ein(x−1) − aeinx
= R.p of
1 − a(ein + e−in ) + a2
cos n(x − 1) − a cos nx
=
1 − 2a cos n + a2
36
Hence the solution is
cos n(x − 1) − a cos nx
ux = A.ax +
1 − 2a cos n + a2
Exercise
1. Solve yx+1 − 3yx = 0.
37