5 - Curve Fitting by Numerical Methods
5 - Curve Fitting by Numerical Methods
GTU # 3130006
Unit-5
Curve Fitting by
Numerical Methods
Why curve fitting is
needed?
Football ticket price in India
Year 2012 2014 2016 2018
7000
Curve fitting is the process of finding the ‘best-fit’ curve for a given set of data. It
is the representation of the relationship between two variables by means of an
algebraic equation.
Curve Fitting
There are two general approaches for curve fitting:
Interpolation Curve Fitting
When we need curve fitting ?
In our daily life, we come across many situations where we often require to find a
relationship between two or more variables.
For example, weight and height of a person, demand and supply, expenditure
depends on income, etc.
These relation, in general, may be expresses by polynomial or they may have
exponential or logarithmic relationship.
In order to determine such relationship, first it is require to collect the data
showing corresponding values of the variables under consideration.
Fitting Straight Line
y__= n A + B __
x
x y = A x + B x__2
So, we need to find the value of x , y , xy and x 2 to find the value of A and B.
M-1 Ex-1: Fit a straight line for the following data.
x 1 2 3 4 5
y 14 27 40 55 68
Solution:
The normal equations for the straight line y = A + Bx are
y = nA + B x
xy = A x + B x 2
2
So, we need to find the value of x , y , xy and x to find the value of A and B.
𝐱 𝐲 𝐱𝐲 𝐱𝟐
1 14 14 1
2 27 54 4
3 40 120 9
4 55 220 16
5 68 340 25
x = 15 y = 204 xy = 748 x 2 = 55
y = nA + B x y = 204
x = 15
xy = A x + B x2
xy = 748
⇒ 748 = 15A + 55B _____________(ii)
A = 0 and B = 13.6
x 2 5 6 9 11
y 2 4 6 9 10
Solution:
The normal equations for the straight line y = A + Bx are
y = nA + B x
xy = A x + B x 2
2
So, we need to find the value of x , y , xy and x to find the value of A and B.
𝐱 𝐲 𝐱𝐲 𝐱𝟐
2 2 4 4
5 4 20 25
6 6 36 36
9 9 81 81
11 10 110 121
x = 33 y = 31 xy = 251 x 2 = 267
y = nA + B x y = 31
x = 33
xy = A x + B x2
xy = 251
⇒ 251 = 33A + 267B _____________(ii)
By equation (i) and (ii), we have x 2 = 267
n 2
y
__ = A + B x
__ + C x
__
2
x y = A x + B x__ + C x__23
2 3
2 3
4
x 2y x x x
= A __ + B __ + C __
2
So, we need to find the value of x , y , x 2 , x 3 , x 4 , xy and x y to find
the value of A, B and C.
M-2 Ex-4: Fit a second degree polynomial for y on x to the following data.
x -1 0 1 2 3
y 5 6 21 50 93
Solution:
The normal equations for the second degree polynomial y = A + Bx + Cx 2 are
y = nA + B x + C x 2
xy = A x + B x 2 + C x 3
x2y = A x2 + B x3 + C x4
2y
2 3 4
So, we need to find the value of x , y , x , x , x , xy and x to find
y = nA + B x + C x 2
n=5
xy = A x + B x 2 + C x 3 x 2 = 15
x 3 = 35
x2y = A x2 + B x3 + C x4
A = 6 , B = 8 and C = 7
y = nA + B x + C x 2
xy = A x + B x 2 + C x 3
x2y = A x2 + B x3 + C x4
2
So, we need to find the value of x , y , x 2 , x 3 , x 4 , xy and x y to find
the value of A, B and C.
𝐱 𝐲 𝐱𝐲 𝐱𝟐 𝐱𝟐𝐲 𝐱𝟑 𝐱𝟒
1 5 5 1 5 1 1
2 12 24 4 48 8 16
3 26 78 9 234 27 81
4 60 240 16 960 64 256
5 97 485 25 2425 125 625
y = nA + B x + C x 2
n=5
xy = A x + B x 2 + C x 3 x 2 = 55
x 3 = 255
x2y = A x2 + B x3 + C x4
Fitting
General
Curve
x
y = ab y = ax b
Fitting a curve 𝐲 = 𝐚𝐞𝐛𝐱
Apply logarithm on both the sides
⇒ log y = log a + bx log e log e e = 1
⇒ log y = log a + bx
Denote , log y = Y and log a = A, then the above equation will becomes
⇒ Y = A + bx
Using method of fitting a straight line, find A and b.
Find a, where a = Antilog(A).
M-3 Ex-1: Fit a curve of the best fit of the type y = aebx to the following data.
x 1 5 7 9 12
y 10 15 12 15 21
Solution:
Apply logarithm on both the sides of the equation y = aebx .
⇒ log y = log a + bx log e
log e e = 1
⇒ log y = log a + bx
Let, log y = Y and log a = A, then by the above equation, we have
⇒ Y = A + bx
The normal equations for the straight line Y = A + bx are
Y = nA + b x
xY = A x + b x 2
So, we need to find the value of x , Y , xY and x 2 to find the value of A and b.
𝐱 𝐲 𝐘 = 𝐥𝐨𝐠 𝐲 𝐱𝐘 𝐱𝟐
1 10 2.3026 2.3026 1
5 15 2.7081 13.5405 25
7 12 2.4849 17.3943 49
9 15 2.7081 24.3729 81
12 21 3.0445 36.534 144
2
x = 34 Y = 13.2482 xY =94.1443 x = 300
Y = nA + b x Y = 13.2482
x = 34
xY = A x + b x 2
xY = 94.1443
⇒ 94.1443 = 34A + 300b _____________(ii)
By equation (i) and (ii), we have x 2 = 300
⇒ b = 0.0590
Therefore, the best fit curve of the type y = aebx is
y = 9.4754 e0.0590x
Fitting a curve 𝐲 = 𝐚𝐱 𝐛
Apply logarithm on both the sides
⇒ log y = log a + b log x
Denote, log y = Y, log a = A and log x = X, then above equation will becomes
⇒ Y = A + bX
Using method of fitting a straight line, find A and b.
Find a, where a = Antilog(A).
M-3 Ex-5: Fit a curve of the best fit of the type y = ax b to the following data.
x 1 2 3 4 5
y 0.5 2 4.5 8 12.5
Solution:
Apply logarithm on both the sides of the equation y = ax b .
⇒ log y = log a + b log x
Let, log y = Y, log a = A and log x = X, then by the above equation, we have
⇒ Y = A + bX
The normal equations for the straight line Y = A + bx are
Y = nA + b X
XY = A X + b X 2
So, we need to find the value of X , Y , XY and X 2 to find the value of A and b.
𝐱 𝐲 𝐗 = 𝐥𝐨𝐠 𝐱 𝐘 = 𝐥𝐨𝐠 𝐲 𝐗𝐘 𝐗𝟐
1 0.5 0 −0.6931 0 0
2 2 0.6931 0.6931 0.4804 0.4804
3 4.5 1.0986 1.5041 1.6524 1.2069
4 8 1.3863 2.0794 2.8827 1.9218
5 12.5 1.6094 2.5257 4.0649 2.5902
Y = nA + b X Y = 6.1092
X = 4.7874
XY = A X + b X 2
XY = 9.0803
⇒ 9.0803 = 4.7874A + 6.1993b _____________(ii)
By equation (i) and (ii), we have X 2 = 6.1993
A = −0.6931 and b = 2
⇒b=2
Therefore, the best fit curve of the type y = ax b is
y = 0.5 x 2
Fitting a curve 𝐲 = 𝐚𝐛𝐱
Apply logarithm on both the sides
⇒ log y = log a + x log b
Denote, log y = Y, log a = A and log b = B, then above equation will becomes
⇒ Y = A + Bx
Using method of fitting a straight line, find A and b.
Find a and b, where a = Antilog A and b = Antilog B .
M-3 Ex-6: Fit a curve of the best fit of the type y = abx to the following data.
x 2 3 4 5 6
y 8.3 15.4 33.1 65.2 126.4
Solution:
Apply logarithm on both the sides of the equation y = abx .
⇒ log y = log a + x log b
Let, log y = Y, log a = A and log b = B, then by the above equation, we have
⇒ Y = A + Bx
The normal equations for the straight line Y = A + Bx are
Y = nA + B x
xY = A x + B x 2
So, we need to find the value of x , Y , xY and x 2 to find the value of A and B.
𝐱 𝐲 𝐘 = 𝐥𝐨𝐠 𝐲 𝐱𝐘 𝐱𝟐
2 8.3 2.1163 4.2326 4
3 15.4 2.7344 8.2032 9
4 33.1 3.4995 13.9980 16
5 65.2 4.1775 20.8875 25
6 126.4 4.8395 29.0370 36
2
x = 20 Y = 17.3672 xY = 76.3583 x = 90
Y = nA + B x Y = 17.3672
x = 20
xY = A x + B x2
xY = 76.3583
⇒ 76.3583 = 4.7874A + 90B _____________(ii)
⇒ b = 1.9916
Therefore, the best fit curve of the type y = ax b is
y = 2.0496 1.9916 x
y = a + bx 2
Special types
of curves
2
b
pv γ = C y = ax +
x
Fitting a Curve 𝐲 = 𝐚 + 𝐛𝐱 𝟐
The normal equations for the curve 𝐲 = 𝐚 + 𝐛𝐱 𝟐 are
n 2
y
__ = A + B x
_
x 24
x 2 y = A x 2 + B __
So, we need to find the value of y , x 2 , x 2 y and x 4 to find the value of A and B.
M-3 Ex-3: Find the least square curve of the form y = a0 + a1 x 2 to the following
data.
x -1 0 1 2
y 2 5 3 0
Solution:
The normal equations for the given curve y = a0 + a1 x 2 are
y = na0 + a1 x 2
x 2 y = a0 x 2 + a1 x 4
2 , x2y 4
So, we need to find the value of y , x and x to find the value of a0 and a1 .
𝐱 𝐲 𝐱𝟐 𝐱𝟐𝐲 𝐱𝟒
−1 2 1 2 1
0 5 0 0 0
1 3 1 3 1
2 0 4 0 16
x = 2 y = 10 x 2 = 6 x 4 = 5 x 4 =18
y = na0 + a1 x 2 y = 10
x2 = 6
x 2 y = a0 x 2 + a1 x 4
x2y = 5
⇒ 5 = 6a0 +18a1 _____________(ii)
x2y = a x4 + b x
y 1
= ax + b 2
x x
y 1
So, we need to find the value of x , x2y , x4 , and 2 to find the value of a and b.
x x
b
M-3 Ex-9: Using least square method fit the curve y = ax 2 + to the following
x
data.
x 1 2 3 4
y -1.51 0.99 3.88 7.66
Solution:
b
The normal equations for the given curve y = ax 2 + are
x
x2y = a x4 + b x
y 1
= ax + b 2
x x
y 1
So, we need to find the value of x , x4 , x2y , and 2 to find a and b.
x x
𝟒
𝐲 𝟏
𝐱 𝐲 𝐱𝟐 𝐱𝟐𝐲 𝐱
𝐱 𝐱𝟐
1 −1.51 1 −1.51 1 −1.51 1
2 0.99 4 3.96 16 0.4950 0.25
3 3.88 9 34.92 81 1.2933 0.1111
4 7.66 16 122.56 256 1.9150 0.0625
y 1
x =10 x2y = 159.93 x4 = 354 = 2.1933 2 = 1.4236
x x
2
x y = ax + bx 4 x 2 y = 159.93
y 1 x = 10
= ax + b 2
x x
y
= 2.1933
⇒ 2.1933 = 10a +1.4236b _____________(ii) x
By equation (i) and (ii), we have 1
2 = 1.4236
x
a = 0.5092 and b = −2.0307
b
Therefore, the best fit line is y = a + ⇒ y = 0.5092 −2.0307x
x
Fitting a Curve 𝐏𝐕 𝛄 = 𝐂
1
Take power both the sides,
𝛾
1
C γ
⇒V=
P
P 50 60 70 80 90
V 64.7 51.3 40.5 25.9 78
Solution:
1
Take power both the sides,
γ
1
C γ 1 1
−
⇒V= = CγP γ
P
Now, take log both the sides,
1 1
⇒ log V = log C − log P
γ γ
1 1
Let log V = Y, log C = A, − = B, log P = X.
γ γ
So, given equation will become Y = A + BX,
The normal equations for the straight line Y = A + BX are
Y = nA + B X
XY = A X + B X 2
𝐏 𝐕 𝐗 = log 𝐏 𝐘 = log 𝐕 𝐗𝐘 𝐗𝟐
50 64.7 3.9120 4.1698 16.3123 15.3039
60 51.3 4.0943 3.9377 16.12226 16.7637
70 40.5 4.2485 3.7013 15.72496 18.0497
80 25.9 4.3820 3.2542 14.26018 19.2022
90 78 4.4998 4.3567 19.60436 20.2483
Y = nA + B X Y = 19.4197
X = 21.1366
XY = A X + B X 2
XY = 82.0240
⇒ 82.0240 = 21.1366a +89.5678b _____________(ii)
By equation (i) and (ii), we have X 2 = 89.5678
𝟏
𝐥𝐨𝐠 𝐂 = 𝐀
𝛄
⇒ log C = Aγ
⇒ log C = 5.236 (3.1270)
⇒ log C = 16.372972
⇒ C = antilog(16.372972)
⇒ C = 12903020.6392168
Therefore, PV 𝛾 = C
3.1270 γ = 3.1270
⇒ PV = 12903020.6392168
C = 12903020.6392168