Professional Documents
Culture Documents
Curve Fitting
Lecture - I
1 Curve Fitting
Table of Contents
1 Curve Fitting
In this Chapter
Fitting a Straight Line
Non-Linear Curve Fitting
(a) Power Function
(b) Polynomial of nth Degree
(c) Exponential Function
∂S
=0 (1)
∂aj
P1 (x) = a0 + a1 x
∂S ∂S
= 0, =0 (2)
∂a0 ∂a1
P
m yi
P P
xi xi yi m xi yi − xi yi
P P P
a1 = P =
m x2i − ( xi )2
P P
m xi
P P 2
xi xi
Dr. Sukanta Deb Curve Fitting 10 / 37
Curve Fitting
Example
Fit a straight line to the x and y values in the first two columns of
the following Table:
xi yi x2i xi yi P1 (xi )
1 1.3 1 1.3 1.18
2 3.5 4 7.0 2.72
3 4.2 9 12.6 4.25
4 5.0 16 20.0 5.79
5 7.0 25 35.0 7.33
6 8.8 36 52.8 8.87
7 10.1 49 70.7 10.41
8 12.5 64 100.0 11.94
9 13.0 81 117.0 13.48
10 15.6 100 156.0 15.02
P 2
S ∼ 2.34
P P P
xi = 55 yi = 81.0 xi = 385 xi yi = 572.4
[P1 (xi ) − yi ]2
P
S=
Example
Let the straight line be given by
P1 (x) = a0 + a1 x,
where a0 , a1 are calculated to be
yi x2i − xi xi yi 385(81) − 55(572.4)
P P P P
a0 = = = −0.360
m x2i − ( xi )2 10(385) − (55)2
P P
m x i yi − x i yi 10(572.4) − 55(81)
P P P
a1 = = = 1.538
m x2i − ( xi )2 10(385) − (55)2
P P
Therefore, the least square (or the best) straight line fit is
Example
Figure: Filled circles denote the tabulated data points, whereas, the solid
line shows the straight line fit to the given data.
Pn (x) = a0 + a1 x + · · · + an xn
m
∂S X
= −2 (yi − a0 − a1 xi − · · · − an xni )
∂a0 i=1
m
∂S X
= −2 (xi )(yi − a0 − a1 xi − · · · − an xni )
∂a1 i=1
..
.
m
∂S X
= −2 (xni )(yi − a0 − a1 xi − · · · − an xni )
∂an i=1
we get:
m
X m
X m
X m
X
ma0 + a1 xi + a2 x2i + · · · + an xni = yi
i=1 i=1 i=1 i=1
m m m m
xn+1
X X X X
a0 xi + a1 x2i + · · · + an i = xi yi
i=1 i=1 i=1 i=1
..
.
m m m m
xn+1
X X X X
a0 xni + a1 i + · · · + an x2n
i = xni yi
i=1 i=1 i=1 i=1
yi =a0 + a1 xi , i = 1, 2, 3, . . . , m (4)
2 To get the first normal equation, take a sum on both sides
over the total number of data points, say m. That is
m
X m
X m
X
yi = a0 + a1 xi
i=1 i=1 i=1
m
X m
X m
X m
X
⇒ yi =ma0 + a1 xi ⇒ ma0 + a1 xi = yi
i=1 i=1 i=1 i=1
Dr. Sukanta Deb Curve Fitting 17 / 37
Curve Fitting
xi yi =a0 xi + a1 x2i
4 And then take the sum over the total number of data points:
m
X m
X m
X m
X m
X m
X
xi yi = a0 xi + a1 x2i ⇒ a0 xi + a1 x2i = xi yi
i=1 i=1 i=1 i=1 i=1 i=1
You may use any one of the methods for solving linear system of
equations to solve the normal equations to get the values of the
parameters of the fitted curve:
1 Gauss elimation method
2 Gauss-Jordan method
3 Gauss-Seidel Iterative method
4 Jacobi Iterative method
Other methods also do exist! But the above methods are numerical
and solutions are easily guaranteed! Besides this, you have learnt
these methods in the previous lecture of this course and applying
them in other problems will help you for their better understanding!
s0 a0 + s1 a1 + · · · + sn an = b0
s1 a0 + s2 a1 + · · · + sn+1 an = b1
..
.
sn a0 + sn+1 a1 + · · · + s2n an = bn
Non-Polynomial Fits
Exponential Fit: Let
y = aebx
Taking the natural logarithm on both sides
Then,
a = ea0 and b = a1
Power Law Fit: Let
y = axb
Dr. Sukanta Deb Curve Fitting 28 / 37
Curve Fitting
Non-Polynomial Fits
Then,
a = ea0 and b = a1
Yi Xi2 − Xi Xi Yi m Xi Yi − Xi Yi
P P P P P P P
a0 = 2 , a1 =
m Xi2 − ( Xi )2
P 2
m Xi − ( Xi )
P P P
(17.025)(220) − (30)(122.150)
∴ a0 = = 0.405
5(220) − (302 )
5 ∗ (122.150) − (30) ∗ (17.025)
a1 = = 0.500
5(220) − (302 )
Hence a = ea0 = e0.405 = 1.499, and b = a1 = 0.500.
⇒ y = aebx = 1.499e0.5x
2.0149
" # 1.2669 " #
T 5.000 15.1750
T
4.4487
∴V V = , V 0.7885 =
15.175 60.4561 7.6000
0.3784
0.0000
Therefore, the normal equations are:
" #" # " #
5.0000 15.1750 a0 4.4487
=
15.1750 60.4561 a1 7.6000
" # " #
a 2.1337
⇒ 0 =
a1 −0.4099
Therefore,
y = 8.4461e−0.4099x
Dr. Sukanta Deb Curve Fitting 33 / 37
Curve Fitting
The Vandermonde
matrix
is:
1 log(x1 ) 1 −0.4541
1 log(x ) 1 0.6070
2
V = 1 log(x3 ) = 1 1.1102
1 log(x4 ) 1 1.4434
1 log(x5 ) 1 1.6929
2.0149
" # 1.2669 " #
T 5.000 4.3994
T
4.4487
∴V V = , V 0.7885 =
4.3994 6.7564 1.2756
0.3784
0.0000
Therefore, the normal equations are:
" #" # " #
5.0000 4.3994 a0 4.4487
=
4.3994 6.7564 a1 1.2756
" # " #
a 1.6943
⇒ 0 =
a1 −0.9144
Therefore,
y = P (x) = 5.44281x−0.9144
Assignment
1 Fit the values of a0 and a1 so that y = a0 + a1 x fits the
following data:
xi 0 1 2 3 4
yi 1.0 2.9 4.8 6.7 8.6
2 Fit a polynomial of the second degree to the data points
(x, y) given by (0, 1), (1, 6) and (2, 17).
3 Determine the constants a and b, by the method of least
squares, such that the curve y = aebx fits the data:
xi 2 4 6 8 10
yi 4.077 11.084 30.128 81.897 222.62
4 Fit a function of the form y = axb for the following data:
xi 61 26 7 2.6
yi 350 400 500 600
Contact Me?
QPPPPPPRQPPPPPPRQPPPPPPRQPPPPPPRQPPPPPPRQPPPPPPRQPPPPPPRQPPPPPPRQPPPPPPR
THANK YOU!
T 9810362087
Í https://sites.google.com/site/sukantodeb
QPPPPPPRQPPPPPPRQPPPPPPRQPPPPPPRQPPPPPPRQPPPPPPRQPPPPPPRQPPPPPPRQPPPPPPR
Dr. Sukanta Deb Curve Fitting 37 / 37