Professional Documents
Culture Documents
Least Square Fitting:: ADITI (2030260) ABHAY NEGI (2030192) ABHAY BHARDWAJ (2030187)
Least Square Fitting:: ADITI (2030260) ABHAY NEGI (2030192) ABHAY BHARDWAJ (2030187)
❖ ADITI (2030260)
❖ ABHAY NEGI (2030192)
❖ ABHAY BHARDWAJ (2030187)
❖ WHAT IS LEAST SQUARE
FITTING METHOD ?
• “ It is a mathematical procedure for finding the best-fitting curve to a given set
of points by minimizing the sum of the squares of the offsets ("the residuals")
of the points from the curve.”
• EXAMPLE :-
❖ WHY DO WE NEED LEAST SQUARE
FITTING METHOD ?
• In science and engineering, the experimental data are usually viewed
by plotting as graphs on plane paper. But, the problem is: what is the
‘best curve’ for a given set of data ? If n data points (xi, yi), i = 1, 2,...,n
are given, then an nth degree polynomial can be constructed using
interpolation methods . But, the handling of higher degree polynomial
is practically very difficult . “Therefore, we will be using another very
reliable and more efficient method i.e. LSQ (LEAST SQUARE FITTING
METHOD)”
• For the given data points we can construct lower degree polynomials
such as linear, quadratic etc. using least squares method, which
minimizes the sum of squares of the absolute errors. An analyst using
the least-squares method will generate a line of best fit that explains
the potential relationship between independent and dependent
variables. The least-squares method provides the overall rationale for
the placement of the line of best fit among the data points being
studied.
❖ THE GENERAL APPROACH FOR
LEAST SQUARE FITTING :-
• The method of least squares assumes that the best fit curve of a given type is
the curve that has the minimal sum of deviations, i.e., least square error from
a given set of data.
• Suppose that the data points are (x1, y1), (x2, y2), …, (xn, yn) where x is the
independent variable and y is the dependent variable. The fitting curve f(x)
has the deviation (error) ei from each data point, as follows:
• According to the method of least squares, the best fitting curve has the
property that
is minimum.
❖ FITTING OF A STRAIGHT LINE :-
Let , Y= a + bx
be the equation of a straight line which is to be fitted on the curve obtained from
the experimental data point, (xi , yi), i = 1, 2, . . . , n. Here, a and b are two
parameters whose values are to be determined by the linear fitting method. Thus,
S can be given by
Let this solution be denoted by a = a*, b = b*. Then the fitted straight line is
y = a* + b*x
Example :
Use least squares method to fit the line y = a + bx based on the sample
(1996,40), (1997, 50), (1998, 62) , (1999, 58) and (2000,60) .
Solution.
Straight line equation is y=a+bx.
The normal equations are
∑y = an + b∑x
∑xy = a∑x + b∑x2
✓ “ The values of ∑x i yi , ∑ y i , ∑ x i and ∑ x i 2 are calculated as follows ”
xi yi x = 1998-xi xi2 x i yi
1996 40 -2 4 -80
1997 50 -1 1 -50
1998 62 0 0 0
1999 58 1 1 58
2000 60 2 4 120
∑x i = 9990 ∑y i = 270 ∑x = 0 ∑x i2 = 10 ∑x iy i = 10
Substituting these values in the normal equations
270 = 5a + 0b
48 = 0a + 10b
Which implies ,
5a = 270 →(1)
10b = 48 →(2)
⇒a = 270/5
⇒ a = 54 →(3)
⇒ b = 24/5 →(4)
That is ,
These (k + 1) equations contain (k + 1) unknowns a0, a1,...,ak. Let a0 = a*0, a1 = a*1
,...,ak = a*k be the solution of the above system of linear equations. Then the fitted
polynomial is ,
Let , y = a + bx + cx2
be the second degree parabolic curve, where a, b, c are unknown parameters
and the values of them are to be determined based on the sample values (xi, yi), i
= 1, 2,...,n. Assume that Yi is the predicted value of y obtained from the curve at
x = xi, i.e.
yi = a + bxi + cxi2
The sum of squares of residuals
Let a = a*, b = b* and c = c* be the solution of the above equations. Then the
fitted parabolic curve is
y = a* + b*x + c*x2
Example :
Use least squares method to fit the curve y = a + bx + cx2 based on the data
(1,2), (2, 6), (3, 7) , (4, 8) , (5,10) , (6 ,11) , (7,11) , (8 , 10) and (9, 9)
Solution.
Let the equation of the parabola be
y = a + bu + cu2
where u = 5 − x, and u is taking as the independent variable.
Therefore, the normal equations are
∑y = na + b ∑u + c ∑u2
∑uy = a ∑u + b ∑u 2 + c ∑u 3
∑u 2y = a ∑u 2 + b ∑u 3 + c ∑u 4
The calculations are shown in the following table.
x u y u2 uy u3 u2y u4
1 4 2 16 8 64 32 256
2 3 6 9 18 27 54 81
3 2 7 4 14 8 28 16
4 1 8 1 8 1 8 1
5 0 10 0 0 0 0 0
6 -1 11 1 -11 -1 11 1
7 -2 11 4 -22 -8 44 16
8 -3 10 9 -30 -27 90 81
9 -4 9 16 -36 -64 144 256
TOTAL 0 74 60 -51 0 411 708
Then the above normal equations reduce to
74 = 9a + 0.b + 60.c
−51 = 0.a + 60.b + 0.c
411 = 60.a + 0.b + 708.c
c = { [ Σ x2 y * Σ xx ] - [ Σ xy * Σ xx2 ] }
{ [ Σ xx * Σ x2x 2] - [ Σ xx2 ]2 }
a = 1 [ ( Σ y ) - { b * ( Σ x ) } - { c * ( Σ x 2) } ]
n
Where ,
▪ Σ x x = [ Σ x 2 ] - [ ( Σ x )2 / n ]
▪ Σxy=[Σxy]-[(Σx*Σy)/n]
▪ Σ x x2 = [ Σ x 3 ] - [ ( Σ x 2 * Σ x ) / n ]
▪ Σ x2 y = [ Σ x 2 y] - [ ( Σ x 2 * Σ y ) / n ]
▪ Σ x2 x2 = [ Σ x 4 ] - [ ( Σ x 2 )2 / n ]
▪ x and y are the Variables.
▪ a, b, and c are the Coefficients of the Quadratic Equation
▪ n = Number of Elements
▪ Σ x= Sum of xi
▪ Σ y = Sum of yi
▪ Σ x2 = Sum of xi2
▪ Σ x 3 = Sum of xi3
▪ Σ x 4 = Sum of xi4
▪ Σ xy= Sum of xi * yi
▪ Σ x2y = Sum of xi 2 * yi
❖ PROGRAM :-
• SCINOTES :-
• NUMERICAL METHOD :-
• IN BUILT COMMAND METHOD :-
• CONSOLE :-
• NUMERICAL METHOD : • IN BUILT COMMAND METHOD :
• GRAPH :-
• NUMERICAL METHOD : • IN BUILT COMMAND METHOD :
❖ CASE – 2 : FITTING OF A CUBIC
CURVE :-
• LSQ COMMAND METHOD :-
• SCINOTES :-
• CONSOLE :-
• GRAPH :-
❖ FITTING OF A POWER
FUNCTION :-
Let , y = axb
be the geometric curve to be fitted to the given data (xi, yi), i = 1, 2,...,n, where a,
b are unknown parameters. Taking logarithm on both sides, we obtain the
equation
log y = log a + b*log x
this can be written as
Y = A + bX
The original points (xi, yi) in the xy-plane are transferred to (Xi, Yi), i = 1, 2,...,n in
the XY -plane. This process is called data linearization.
Now, using the method described in Section “FITTING OF A STRAIGHT LINE”
one can determine the values of A and b, and a can be obtained from a = eA.
Example :
Use least squares method to fit the curve y = axb based on the data (1, 3.5) ,
(2, 6.2), (3, 9.5) , (4, 15.3) and (5,20.4) .
Solution.
Let y = ax b. Then its corresponding linear curve is Y = A + bX,
where log y = Y, log x = X, log a = A.
The normal equations are ,
∑ Yi = nA + b ∑Xi
∑ XiYi = A ∑Xi + b ∑Xi 2
The values of ∑Xi , ∑ Yi , ∑Xi 2 and ∑ XiYi are calculated in the following table.
x y X Y X2 XY
1 3.5 0 1.25276 0 0
2 6.2 0.69315 1.82455 0.48046 1.26469
3 9.5 1.09861 2.25129 1.20694 2.47329
4 15.3 1.38629 2.72785 1.92180 3.78159
5 20.4 1.60944 3.01553 2.59030 4.85331
TOTAL 4.78749 11.07198 6.19950 12.37288
Then the normal equations are
5A + 4.78749b = 11.07198,
4.78749A + 6.19950b = 12.37288.
y = 3.20416 x 1.09655
❖ PROGRAM :-
• LSQ COMMAND METHOD :-
• SCINOTES :-
• CONSOLE :-
• GRAPH :-
❖ FITTING OF AN EXPONENTIAL
CURVE :-
5A + 25b = 14.525
25A + 165b = 92.625
y = 1.499 e0.5x
❖ PROGRAM :-
• LSQ COMMAND METHOD :-
• SCINOTES :-
• CONSOLE :-
• GRAPH :-