0% found this document useful (0 votes)
942 views57 pages

5 - Curve Fitting by Numerical Methods

Curve fitting by vimal gohil

Uploaded by

Free Use
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)
942 views57 pages

5 - Curve Fitting by Numerical Methods

Curve fitting by vimal gohil

Uploaded by

Free Use
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/ 57

Probability and Statistics (PS)

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

Price 2000 4200 5900 7000


5900 (in ₹)

Que. Find the polynomial for given


data.
4200
Que. Predict a price of the ticket
for year 2021.
2000

2012 2014 2016 2018


What is curve fitting ?

 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

Curve Fitting Fitting Parabola

Fitting General Curves


Fitting a straight line 𝐲 = 𝐀 + 𝐁𝐱
 The normal equations for the best fitting straight line 𝐲 = 𝐀 + 𝐁𝐱 are

෍ 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

Therefore, by using this data we can find normal equations.


The normal equations for the straight line are

෍ y = nA + B ෍ x ෍ y = 204

⇒ 204 = 5A + 15B _____________(i) n=5

෍ x = 15
෍ xy = A ෍ x + B ෍ x2

෍ xy = 748
⇒ 748 = 15A + 55B _____________(ii)

By equation (i) and (ii), we have ෍ x 2 = 55

A = 0 and B = 13.6

Therefore, the best fit line is y = A + Bx ⇒ y = 13.6x


M-1 Ex-2: Fit a straight line for the following data. Also find y when x = 2.8

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

Therefore, by using this data we can find normal equations.


The normal equations for the straight line are

෍ y = nA + B ෍ x ෍ y = 31

⇒ 31 = 5A + 33B _____________(i) n=5

෍ x = 33
෍ xy = A ෍ x + B ෍ x2

෍ xy = 251
⇒ 251 = 33A + 267B _____________(ii)
By equation (i) and (ii), we have ෍ x 2 = 267

A = −0.0244 and B = 0.9431

Therefore, the best fit line is y = A + Bx ⇒ y = −0.0244 + 0.9431x


Now, for finding the value of y at x = 2.8
We have, y = −0.0244 + 0.9431x
⇒ y = −0.0244 + 0.9431( 2.8 )
⇒ y = −0.0244 + 2.6407
⇒ y = 2.6163

Therefore, y at x = 2.8 is 2.6163.


Fitting Straight Line

Curve Fitting Fitting Parabola

Fitting General Curves


Fitting a parabola 𝐲 = 𝐀 + 𝐁𝐱 + 𝐂𝐱 𝟐
 The normal equations for the best fitting parabola 𝐲 = 𝐀 + 𝐁𝐱 + 𝐂𝐱 𝟐 is

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

the value of A, B and C.


𝐱 𝐲 𝐱𝐲 𝐱𝟐 𝐱𝟐𝐲 𝐱𝟑 𝐱𝟒
−1 5 −5 1 5 −1 1
0 6 0 0 0 0 0
1 21 21 1 21 1 1
2 50 100 4 200 8 16
3 93 279 9 837 27 81

෍ x =5 ෍ y = 175 ෍ xy = 395 ෍ x 2 = 15 ෍ x 2 y =1063 ෍ x 3 =35 ෍ x 4 =99

Therefore, by using this data we can find normal equations.


The normal equations for the second degree polynomial are ෍ y = 175

෍ y = nA + B ෍ x + C ෍ x 2
n=5

⇒ 175 = 5A +5B + 15C + _____________(i) ෍x = 5

෍ xy = A ෍ x + B ෍ x 2 + C ෍ x 3 ෍ x 2 = 15

⇒ 395 = 5A + 15B + 35C _____________(ii) x 2 yxy==1063


෍෍ 395

෍ x 3 = 35
෍ x2y = A ෍ x2 + B ෍ x3 + C ෍ x4

⇒ 1063 = 15A +35B + 99C _____________(iii) ෍ x 4 = 99


By equation (i), (ii) and (iii), we have

A = 6 , B = 8 and C = 7

Therefore, the best fit line is y = A + Bx + Cx 2


⇒ y = 6 + 8x +7x 2
M-2 Ex-2: Fit a second degree polynomial for y on x to the following data. Find
y(2.4).
x 1 2 3 4 5
y 5 12 26 60 97
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
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

෍ x =15 ෍ y = 200 ෍ xy = 832 ෍ x 2 = 55 ෍ x 2 y =3672 ෍ x 3 =225 ෍ x 4 =979

Therefore, by using this data we can find normal equations.


The normal equations for the second degree polynomial are ෍ y = 200

෍ y = nA + B ෍ x + C ෍ x 2
n=5

⇒ 200 = 5A +15B +55C + _____________(i) ෍ x = 15

෍ xy = A ෍ x + B ෍ x 2 + C ෍ x 3 ෍ x 2 = 55

⇒ 832 = 15A + 55B + 255C _____________(ii) x 2 yxy


෍෍ == 832
3672

෍ x 3 = 255
෍ x2y = A ෍ x2 + B ෍ x3 + C ෍ x4

⇒ 3672 = 55A + 255B + 979C _____________(iii) ෍ x 4 = 979


By equation (i), (ii) and (iii), we have

A = 10.4 , B = −11.0857 and C = 5.7143

Therefore, the best fit line is y = A + Bx + Cx 2


⇒ y = 10.4 + −11.0857 x + 5.7143x 2
⇒ y = 10.4 − 11.0857x + 5.7143x 2
Now, for finding the value of y at x = 2.4
We have, y = 10.4 − 11.0857x + 5.7143x 2
⇒ y = 10.4 − 11.0857( 2.4 ) + 5.7143 2.4 2

⇒ y = 10.4 − 26.6057 + 32.9144


⇒ y = 16.7087
Fitting Straight Line

Curve Fitting Fitting Parabola

Fitting General Curves


y = aebx

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

Therefore, by using this data we can find normal equations.


The normal equations for the straight line are

෍ Y = nA + b ෍ x ෍ Y = 13.2482

⇒ 13.2482 = 5A + 34b _____________(i) n=5

෍ 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

A = 2.2487 and b = 0.0590

Therefore, the best fit line is Y = A + bx ⇒ Y = 2.2487 + 0.0590x


Now, A = log a
⇒ a = antilog(A)
⇒ a = 9.4754

⇒ 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

෍ x =15 ෍ X = 4.7874 ෍ Y = 6.1092 ෍ XY =9.0803 ෍ X 2 = 6.1993

Therefore, by using this data we can find normal equations.


The normal equations for the straight line are

෍ Y = nA + b ෍ X ෍ Y = 6.1092

⇒ 6.1092 = 5A + 4.7874b _____________(i) n=5

෍ 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

Therefore, the best fit line is Y = A + bX ⇒ Y = −0.6931 + 2X


Now, A = log a
⇒ a = antilog(A)
⇒ a = 0.5

⇒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

Therefore, by using this data we can find normal equations.


The normal equations for the straight line are

෍ Y = nA + B ෍ x ෍ Y = 17.3672

⇒ 17.3672 = 5A + 20B _____________(i) n=5

෍ x = 20
෍ xY = A ෍ x + B ෍ x2

෍ xY = 76.3583
⇒ 76.3583 = 4.7874A + 90B _____________(ii)

By equation (i) and (ii), we have ෍ x 2 = 90

A = 0.7176 and B = 0.6890

Therefore, the best fit line is Y = A + Bx ⇒ Y = 0.7176 + 0.6890x


Now, A = log a
⇒ a = antilog(A)
⇒ a = 2.0496

⇒ 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

Therefore, by using this data we can find normal equations.


The normal equations for the given curve are

෍ y = na0 + a1 ෍ x 2 ෍ y = 10

⇒ 10 = 4a0 + 6a1 _____________(i) n=4

෍ x2 = 6
෍ x 2 y = a0 ෍ x 2 + a1 ෍ x 4

෍ x2y = 5
⇒ 5 = 6a0 +18a1 _____________(ii)

By equation (i) and (ii), we have ෍ x 4 = 18

a0 = 4.1667 and a1 = −1.1111

Therefore, the best fit line is y = a0 + a1 x 2 ⇒ y = 4.1667 +1.1111x


𝐛
Fitting a Curve 𝐲 = 𝐚𝐱 𝟐 +
𝐱
𝐛
 The normal equations for the curve 𝐲 = 𝐚𝐱 𝟐 + are
𝐱

෍ x2y = a ෍ x4 + b ෍ x

y 1
෍ = a෍x + 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
෍ = a෍x + 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

Therefore, by using this data we can find normal equations.


The normal equations for the given curve are

2
෍x y = a෍x + b෍x 4 ෍ x 2 y = 159.93

⇒ 159.93 = 354a + 10b _____________(i) ෍ x 4 = 354

y 1 ෍ x = 10
෍ = a෍x + 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

 Take logarithm both the sides,


1 1
⇒ log V = log C − log P
γ γ
1 1
 Denote log V = Y, log C = A, − = B, log P = X then above equation will
γ γ
become Y = A + BX.
1
 Find A, B & consequently γ = − and C = ant𝑖𝑙𝑜𝑔(γ𝐴) can be calculated.
B
M-3 Ex-10: The pressure P of the gas corresponding to various volume V is
measured given by the following data, fit the data to the equation PV γ = C.

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

෍ X =21.1366 ෍ Y = 19.4197 ෍ XY =82.0240 ෍ X 2 = 89.5678


The normal equations for the straight line are

෍ Y = nA + B ෍ X ෍ Y = 19.4197

⇒ 19.4197 = 5A +21.1366B _____________(i) n=5

෍ 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

A = 5.236 and B = −0.3198

Therefore, the best fit line is Y = A + BX ⇒ Y = 5.236 −0.3198X


𝟏
− =𝐁
𝛄 B = −0.3198
1
⇒ − = −0.3198
γ A = 5.236
⇒ γ = 3.1270

𝟏
𝐥𝐨𝐠 𝐂 = 𝐀
𝛄
⇒ 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

You might also like