0% found this document useful (0 votes)
1K views17 pages

Curve Fitting: Fitting A Straight Line

Curve fitting involves finding an equation that best represents the relationship between two variables based on data points. Least squares curve fitting minimizes the sum of the squared errors between observed and predicted values by fitting curves to data. Common curves that are fitted include straight lines, parabolas, power functions, exponential functions, and logarithmic functions. The normal equations derived from minimizing the sum of squared errors are solved to determine the curve's parameters. Examples demonstrate how to apply least squares fitting to find straight line equations for given data sets.

Uploaded by

20-317 Rithvik
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
1K views17 pages

Curve Fitting: Fitting A Straight Line

Curve fitting involves finding an equation that best represents the relationship between two variables based on data points. Least squares curve fitting minimizes the sum of the squared errors between observed and predicted values by fitting curves to data. Common curves that are fitted include straight lines, parabolas, power functions, exponential functions, and logarithmic functions. The normal equations derived from minimizing the sum of squared errors are solved to determine the curve's parameters. Examples demonstrate how to apply least squares fitting to find straight line equations for given data sets.

Uploaded by

20-317 Rithvik
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 17

CURVE FITTING

Curve fitting means an exact relationship between two variables by algebraic equations; in fact
this relationship is the equation of the curve. Therefore curve fitting means to form an equation
of the curve from the given data (or) The method of finding an exact mathematical relationship
between the two variables is given by simple algebraic expression is called curve fitting.

LEAST – SQUARES CURVE FITTING PROCEDORES: Let the set of data points be
(xi,yi), i= 1,2,3,…..,m, and let the curve y = f(x) is fitted to this data. At x = xi, the observed value
yi and the corresponding value on the fitting curve is f(xi). If ei is the error of approximation at x
= xi, then we have

ei = yi – f(xi), i = 1,2,3,…….,m
2 2 2
If we have S = [ y 1−f ( x 1) ] + [ y 2−f ( x 2 ) ] +… … … … …+ [ y m−f ( x m ) ]

2 2 2
= e 1 + e2 +… … … … … ..+e m

Then the method of least squares consists of minimizing S.

i.e; The sum of the squares of the errors.

Fitting a straight line:

Let y = a + bx be the straight line to be fitted to the data (xi,yi), i= 1,2,3,…..,m


2 2 2
S = [ y 1−( a+b x 1 ) ] + [ y 2−( a+b x 2 ) ] +… … … … …+ [ y m−( a+ bx m ) ] …..(1)

∂S
For S to be minimum, we have =0
∂a

⇨−2 [ y 1−( a+b x 1) ]−2 [ y 2−( a+b x 2 ) ]−… … … … …−2 [ y m−( a+bx m ) ]=0….(2)

∂S
And =0
∂b
⇨ −2 x1 [ y 1−( a+b x 1 ) ]−2 x 2 [ y 2− ( a+b x 2 ) ] −… … … …−2 x m [ y m−( a+bx m ) ] =0..(3)

The above equations simplify to

m a0 +a ( x 1 + x 2+ … … … … …+ x m )= y 1 + y 2 +… … … … .+ y m ………..(4)

And a ( x 1 + x 2+ … … … … …+ x m ) +b ( x 1 + x 2 +… … … … ..+ x m )
2 2 2

¿ x 1 y 1 + x 2 y 2 +… … .+ x m y m ……………………(5)

Or, more compactly to


m m
ma+b ∑ x i=∑ y i … … … ( 6 )
i=1 i=1

m m m
And a ∑ x i +b ∑ x i =∑ x i y i … … … ( 7 )
2

i=1 i=1 i=1

Since the xi and yi are known quantities.

Equations (6) and (7) can be solved for the two unknowns a0 and a1

Equations (6) and (7) are called normal equations.

These equations can be written as

∑ yi =na+b ∑ x i
∑ x i y i=a ∑ x i +b ∑ x i2

NON-LINEAR CURVE FITTING:

Fitting of a parabola:
Let y = a+ bx+ cx2 be the parabola to be fitted to the data points (xi,yi), i= 1,2,3,…..,m, then we
have

[ ] [ ] [ ]
2 2 2
S = y 1 −( a+ b x1 +c x12 ) + y 2−( a+b x 2 +c x 22 ) +. …+ y m−( a+bx m + c x m2 )

∂S ∂S ∂ S
For S to be minimum, we have =0 , = =00 ,
∂a ∂b ∂c
∂S
=0 ⇨
∂a
[ ] [ ]
−2 y 1−( a+b x 1 +c x 1 ) −2 y 2−( a+b x 2+ c x 2 ) −… … … … …−2 y m−( a+bx m +c x m ) =0
2 2
[ 2
]
∂S
=0⇨
∂b
[ ] [
−2 x1 y 1−( a+b x 1 +c x1 ) −2 x2 [ y 2−( a+b x 2 ) +c x 2 ] −… … … …−2 x m y m−( a+bx m + c x m ) =0
2 2 2
]
∂S
=0 ⇨⇨
∂c
[ ] [
−2 x12 y 1−( a+b x 1 +c x 12 ) −2 x 22 [ y 2−( a+b x 2) + c x 22 ]−… … … …−2 x m2 y m−( a+bx m +c x m2 ) =0 ]
We get the following normal equations are
m m m
ma+b ∑ x i +c ∑ x i =∑ y i
2

i=1 i=1 i =1

m m m m
a ∑ x i +b ∑ x i + c ∑ x i =∑ x i y i
2 3

i=1 i=1 i=1 i=1

And
m m m m
a ∑ x i +b ∑ x i + c ∑ x i =∑ x i y i
2 3 4 2

i=1 i=1 i=1 i=1

(OR)

na+ b ∑ xi + c ∑ x i =∑ y i
2

a ∑ x i +b ∑ x i + c ∑ x i =∑ x i y i
2 3

And
a ∑ x i +b ∑ x i + c ∑ x i =∑ x i y i
2 3 3 2

Fitting of the curve of the form y=a xc ( Power function):


Let the curve be y=a xc … … … … … … ( 1 )

Taking logarithms on both sides, we get

log y=log a+c log x … … … … . ( 2 )


Which is of the form Y = A +BX … .(3) where A=log a , B=c , X=log x ,∧Y =log y

Equation (3) is a straight line, Hence the normal equations are

∑ Y i=nA+ B ∑ X i … … … (4)
∑ X i Y i =A ∑ X i + B ∑ X i2 … … …..(5)
Solving equations (4) and (5), we get the value of A and b

Hence a=e A and c = B

Exponential function:
Fitting of the curve of the form y=a e bx be fitted to the given data.

Taking logarithms on both sides, we get

log y=log a+bx … … … .. ( 1 )

Which can be written in the form Y = A +Bx … … … .. ( 2 )

Where Y =log y , A=log a , B=b

Since equation (2) represents a straight line.

⸫ The normal equations are


∑ Y i=nA+ B ∑ x i … … …(3)
∑ x i Y i= A ∑ x i+ B ∑ x i2 … … …..( 4)
Solving equations (3) and (4), we get the value of A and B .

Hence a=e A and b=B

Fitting of the curve of the form y=a b x


Let y=a b x………..(1) be the curve to be fitted to the given data.

Taking logarithms on both sides, we get


log y=log a+ x log b … … … .. ( 1 )

Which can be written in the form Y = A +Bx … … … .. ( 2 )

Where Y =log y , A=log a , B=log b

Since equation (2) represents a straight line.

⸫ The normal equations are


∑ Y i=nA+ B ∑ x i … … …(3)
∑ x i Y i= A ∑ x i+ B ∑ x i2 … … …..( 4)
Solving equations (3) and (4), we get the value of A and B .

Hence a=e A and b=e B

Problems
1. By the method of least squares find the straight line that best fits the following data.

x 1 2 3 4 5

y 14 27 40 55 68

Solution: Let y = a + bx be a straight line to be fitted to the given data

The normal equations are

∑ yi =na+b ∑ x i ……………..(1)

∑ x i y i=a ∑ x i +b ∑ x i2 ……………..(2)
xi yi xiyi xi2
1 14 14 1

2 27 54 4

3 40 120 9

4 55 220 16

5 68 340 25

∑ x i=15 ∑ yi =204 ∑ x i y i=748 ∑ x i2=55


Here n = 5

From equation (1) and (2), we have

5a+15b =204…………….(3)

15a + 55b = 748…………..(4)

Solving equations (3) and (4), we get a = 0,b = 13.6

Thus the line of best fitting is y = 0+13.6x⇨ y= 13.6x

2. Fit a straight line to the following data by the method of least squares.

x 0 1 2 3 4

y 1 1.8 3.3 4.5 6.3

Solution: Let y = a + bx be a straight line to be fitted to the given data

The normal equations are

∑ yi =na+b ∑ x i ……………..(1)

∑ x i y i=a ∑ x i +b ∑ x i2 ……………..(2)
xi yi xiyi xi2

0 1 0 0

1 1.8 1.8 1

2 3.3 6.6 4

3 4.5 13.5 9

4 6.3 25.2 16

∑ x i=10 ∑ yi =16.9 ∑ x i y i=47.1 ∑ x i2=30


Here n = 5

From equation (1) and (2), we have

5a+10b =16.9…………….(3)

10a + 30b = 47.1…………..(4)

Solving equations (3) and (4),

Equation (3) X 2 – equation (4)

10a+20b = 33.8

10a+30b = 47.1

i.e; -10b = - 13.3⇨ b = 1.33

from equation (3), we get 5a+10(1.33) = 16.9

⇨5a+13.3=16.9⇨5a = 16.9 – 13.3 = 3.6⇨a= 0.72

Thus the line of best fitting is y = 0.72+1.33x


3. Fit a parabola to the following data by the method of least squares.
OR
Fit a second degree polynomial to the following data by the method of least squares.

x 0 1 2 3 4

y 1 1.8 1.3 2.5 6.3

Solution: Let the required parabola be y = a+bx+cx2…………..(1)

The normal equations are

na+ b ∑ xi + c ∑ x i2=∑ y i…………..(2)

a ∑ x i +b ∑ x i2+ c ∑ x i3=∑ x i y i………(3)

a ∑ x i +b ∑ x i + c ∑ x i =∑ x i y i ………..(4)
2 3 3 2

xi yi xi2 xi3 xi4 xiyi xi2 yi

0 1.0 0 0 0 0 0

1 1.8 1 1 1 1.8 1.8

2 1.3 4 8 16 2.6 5.2

3 2.5 9 27 81 7.5 22.5

4 6.3 16 64 256 25.2 100.8


∑ x i=10 ∑ yi =12.9 ∑ x i2=30 ∑ x i3=100 ∑ x i4 =354 ∑ x i y i=37.1 ∑ x i2 y i=130.3

Here n = 5

From equations (2),(3) and (4), we have

5a+10b+30c = 12.9 ………….(5)

10a+30b+100c = 37.1 ……….(6)

30a+100b+354c = 130.3 ………(7)

Solving equations (5),(6) and (7), we get

a = 1.42, b = -1.07, c = 0.55

Hence the equation of parabola is y = 1.42 – 1.07x+0.55x2

4. Fit a second degree polynomial to the following data by the method of least squares.

x 10 12 15 23 20

y 14 17 23 25 21

Solution: Let the required parabola be y = a+bx+cx2…………..(1)

The normal equations are

na+ b ∑ xi + c ∑ x i =∑ y i…………..(2)
2

a ∑ x i +b ∑ x i + c ∑ x i =∑ x i y i………(3)
2 3

a ∑ x i +b ∑ x i + c ∑ x i =∑ x i y i ………..(4)
2 3 3 2
xi yi xi2 xi3 xi4 xiyi xi2 yi

10 14 100 1000 10000 140 1400

12 17 144 1728 20736 204 2448

15 23 225 3375 50625 345 5175

23 25 529 12167 279841 575 13225

20 21 400 8000 160000 420 8400

∑ x i=80 ∑ yi =100 ∑ x i2=1398∑ x i3=26270∑ x i4 =521202 ∑ x i y i=1684 ∑ x i2 y i=¿ ¿30648

Here n = 5

From equations (2),(3) and (4), we have

5a+80b+1398c = 100 …………….(5)


80a+1398b+26270c = 1684 …………..(6)
1398a+26270b+521202c = 30648 ………..(7)
Solving equations (5),(6) and (7), we get
a = -8.89, b = 3.03 and c = -0.07

Hence the equation of parabola is y = -8.89 + 3.03x- 0.07x2

5. By the method of least squares, fit a second degree curve y = a+bx+cx2 to the following
data.
x 1 2 3 4 5 6 7 8 9

y 2 6 7 8 10 11 11 10 9

Ans: y = -1+3.35x-0.27x2

6. Find the curve of best fit of the type y=a e bx to the following data by the method of least
squares.

x 2 4 6 8 10

y 4.077 11.084 30.128 81.897 222.62

Solution: The given curve of the form y=a e bx ………….(1)

Taking logarithms on both sides, we get

log y=log a+bx … … … .. ( 2 )

Which can be written in the form Y = A +Bx … … … .. ( 3 )

Where Y =log y , A=log a , B=b

Since equation (2) represents a straight line.

⸫ The normal equations are


∑ Y i=nA+ B ∑ x i … … …(4 )
∑ x i Y i= A ∑ x i+ B ∑ x i2 … … …..(5)
xi yi Y i=log y i xi2 xiY i
2 4.077 1.405 4 2.810

4 11.084 2.405 16 9.620

6 30.128 3.405 36 20.430

8 81.987 4.405 64 35.240

10 222.62 5.405 100 54.050

∑ x i=30 ∑ Y i=17.025 ∑ x i2=220 ∑ x i Y i=122.150

Here n = 5
From equation (4) and (5), we get

5A+30B = 17.025 …………….(6)


30A+220B = 122.150 …………(7)

Solving equations (6) and (7), we get


A = 0.405 and B = 0.5
Hence a=e A=e 0.405 =1.499 b= B=0.5
Hence the required curve is y = 1.449e 0.5 x.

7. Using the method of least squares determine the constant a and b such that y=a e bx fits
the following data.

x 0.0 0.5 1.0 1.5 2.0 2.5

y 0.10 0.45 2.15 9.15 40.35 180.75

Solution: The given curve of the form y=a e bx ………….(1)

Taking logarithms on both sides, we get

log y=log a+bx … … … .. ( 2 )

Which can be written in the form Y = A +Bx … … … .. ( 3 )


Where Y =log y , A=log a , B=b

Since equation (2) represents a straight line.

⸫ The normal equations are


∑ Y i=nA+ B ∑ x i … … …(4 )
∑ x i Y i= A ∑ x i+ B ∑ x i2 … … …..(5)

xi yi Y i=log y i xi2 xiY i

0 0.10 -2.3026 0 0

0.5 0.45 -0.7985 0.25 -0.3993

1.0 2.15 0.7655 1 0.7655

1.5 9.15 2.2138 2.25 3.3207

2.0 40.35 3.6976 4 7.3952

2.5 180.75 5.1971 6.25 12.9928

∑ x i=7.5 ∑ Y i=¿ ¿8.7729 ∑ x i2=13.75 ∑ x i Y i=24.0749

Here n = 6
From equation (4) and (5), we get

6A+7.5B = 8.7729 …………….(6)


7.5A+13.75B = 24.0749 …………(7)

Solving equations (6) and (7), we get


Hence the required curve is y = 0.1019e 2.9963 x.

8. Fit a curve of the form y=a b x to the following data by the method of least squares.
x 2 3 4 5 6

y 144 172.8 207.4 248.8 298.5

Solution: Let the required curve be y=a b x……………..(1)

Taking logarithms on both sides, we get

log y=log a+ x log b … … … .. ( 1 )

Which can be written in the form Y = A +Bx … … … .. ( 2 )

Where Y =log y , A=log a , B=log b

Since equation (2) represents a straight line.

⸫ The normal equations are


∑ Y i=nA+ B ∑ x i … … …(3)
∑ x i Y i= A ∑ x i+ B ∑ x i2 … … …..( 4)
xi yi Y i=log y i xi2 xi Y i
2 144 4.9698 4 9.9396

3 172.8 5.1521 9 15.4563

4 207.4 5.3346 16 21.3384

5 248.8 5.5166 25 27.583

6 298.5 5.6988 36 34.1928

∑ x i=20 ∑ Y i=¿ ¿26.6 ∑ x i2=90 ∑ x i Y i=108.5101


719

Here n = 5
From equations (3) and (4), we get
5A+20B = 26.6719 ………………(5)
20A+90B = 108.5101 …………… (6)
Solving equations (5) and (6), we get
A = 4.6054, B = 0.1822
Hence a=e A=e 4.6054 =100.023∧b=e B =e 0.1822=1.1998=1.2
⸫ The required curve is y= (100.023 )( 1.2 )x .

9. Find 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

10. Fit a curve of the form y=a xb to the following data by the method of least squares.
x 2 4 7 10 20 40 60 80

y 43 25 18 13 8 5 3 2

Solution: The given curve is y=a xb ………………. (1)

Taking logarithms on both sides, we get

log y=log a+b log x

Which is of the form Y = A +BX … .(2) where A=log a , B=b , X =log x ,∧Y =log y

Equation (2) is a straight line, Hence the normal equations are

∑ Y i=nA+ B ∑ X i … … … (3)
∑ X i Y i =A ∑ X i + B ∑ X i2 … … …..(4)
Here n = 8

xi yi X i =log X i Y i=log y i Xi2 Xi Y i


2 43 0.693 3.761 0.480 2.606

4 25 1.386 3.219 1.921 4.462

7 18 1.946 2.890 3.787 5.624

10 13 2.303 2.565 5.304 5.907

20 8 2.996 2.079 8.976 6.229

40 5 3.689 1.609 13.609 5.936

60 3 4.094 1.099 16.761 4.499

80 2 4.382 0.693 19.202 3.037

∑ X i=21.489 ∑ Y i=¿ ¿17.9 ∑ x i2=70 .04 ∑ X i Y i =38.3


15

From equations (3) and (4), we get

8A+21.489B = 17.915 …………….. (5)


21.489A+70.04B = 38.3 ………….. (6)

Solving equations (5) and (6), we get


A = 4.3827 and B = -0.7979
⸫a=e A=e 4.3827 =80.0538 and b=B = -0.7979
⸫ The required curve is y= ( 80.0538 ) x−0.7979

You might also like