Curve Fitting
Curve Fitting
Curve Fitting
P. Sam Johnson
February 6, 2020
P. Sam Johnson (NIT Karnataka) Curve Fitting Using Least-Square Principle February 6, 2020 1 / 32
Overview
P. Sam Johnson (NIT Karnataka) Curve Fitting Using Least-Square Principle February 6, 2020 2 / 32
Introduction
For example, it is known that the speed v of a ship varies with the horse
power p of an engine according to the formula p = a + bv 3 . Here a and b
are the constants to be determined. For this purpose we take several sets
of readings of speeds and the corresponding horse powers.
The problem is to find the best values of v and p. Thus the general
problem is to find a suitable relation or law that may exist between the
variables x and y from a given set of observed values
(xi , yi ), i = 1, 2, . . . , n. Such relation connecting x and y is known as
empirical law.
P. Sam Johnson (NIT Karnataka) Curve Fitting Using Least-Square Principle February 6, 2020 3 / 32
Introduction
The process of finding the equation of the “curve of best fit” which may
be most suitable for predicting the unknown values is known as curve
fitting.
1. Graphical method
2. Method of group averages
3. Method of moments
4. Method of least squares.
P. Sam Johnson (NIT Karnataka) Curve Fitting Using Least-Square Principle February 6, 2020 4 / 32
Introduction
The method has the obvious drawback in that the straight line drawn may
not be unique. The method of least squares is probably the most
systematic procedure to fit a “unique curve” using given data points and
is widely used in practical computations. It can also be easily implemented
on a digital computer.
P. Sam Johnson (NIT Karnataka) Curve Fitting Using Least-Square Principle February 6, 2020 5 / 32
Fitting a Straight Line (Linear Form)
The least squares approach to this problem involves determining the best
approximating line when the error involved is the sum of the squares of the
differences between the y -values on the approximating line and the given
y -values.
P. Sam Johnson (NIT Karnataka) Curve Fitting Using Least-Square Principle February 6, 2020 7 / 32
Fitting a Straight Line (Linear Form)
and
m
∂S X
= −2 xi [yi − (a0 + a1 xi )].
∂a1
i=1
P. Sam Johnson (NIT Karnataka) Curve Fitting Using Least-Square Principle February 6, 2020 8 / 32
Fitting a Straight Line (Linear Form)
and
m
X m
X m
X
ma0 xi + a1 xi2 = xi yi .
i=1 i=1 i=1
Since the xi and yi are known quantities, the above two equations (called
the normal equations), can be solved for the two unknown a0 and a1 .
∂S ∂S
Differentiating ∂a 0
and ∂a 1
with respect to a0 to a1 respectively, we find
∂2S ∂2S
and
∂a02 ∂a12
and both will be positive at the points. Hence these values provide a
minimum of S.
P. Sam Johnson (NIT Karnataka) Curve Fitting Using Least-Square Principle February 6, 2020 9 / 32
Fitting a Straight Line (Linear Form)
∂2S ∂2S ∂2S ∂2S
Let Sa0 a0 = ∂a02
, S a1 a1 = ∂a12
, S a0 a1 = ∂a0 ∂a1
and Sa1 a0 = ∂a1 ∂a0
.
m
X
Sa0 a0 = −2 (−1) = 2m > 0
i=1
Xm m
X
Sa1 a1 = −2 xi (−xi ) = 2 xi2 > 0
i=1 i=1
Xm m
X
Sa1 a0 = −2 xi (−1) = 2 xi
i=1 i=1
Xm m
X m
X
Sa0 a0 Sa1 a1 − (Sa1 a0 )2 = 4m xi2 − 4 xi xi
i=1 i=1 i=1
for minimum we should get Sa0 a0 Sa1 a1 − (Sa1 a0 )2 > 0. This is guaranteed from the
Cauchy-Schwarz inequality
X m √ X m 1/2
xi < m xi2 .
i=1 i=1
P. Sam Johnson (NIT Karnataka) Curve Fitting Using Least-Square Principle February 6, 2020 10 / 32
Fitting a Straight Line (Linear Form)
Exercise
1. Convert the following equations into linear form
x
(a) y = a+bx (c) xay = b (e) xy = ax + b
ax+b (d) y = b (f) y = ax + bx 2
(b) y = x x(x−a)
(g) y = ax + bxy .
P. Sam Johnson (NIT Karnataka) Curve Fitting Using Least-Square Principle February 6, 2020 12 / 32
Polynomial of the nth degree
P. Sam Johnson (NIT Karnataka) Curve Fitting Using Least-Square Principle February 6, 2020 13 / 32
x y xy ··· x ny
x0 y0 x0 y0 ··· x0n y0
x1 y1 x1 y1 ··· x1n y1
.. .. .. .. ..
. . . . .
x y x y ··· xn y
Pmm Pmm Pmm m Pmm mn
i=1 xi i=1 yi i=1 xi yi ··· i=1 xi yi
P. Sam Johnson (NIT Karnataka) Curve Fitting Using Least-Square Principle February 6, 2020 14 / 32
Plausible (Feasible) Values
P. Sam Johnson (NIT Karnataka) Curve Fitting Using Least-Square Principle February 6, 2020 15 / 32
We get n equations. Solving these equations, we get most plausible
(feasible) values of x1 , x2 , . . . , xn . One can verify that at the values of
x1 , x2 , . . . , xn , determinant of every principal minor of the following matrix
is positive :
Sa0 a0 Sa0 a1 . . . Sa0 an
Sa a Sa a . . . Sa a
1 0 1 1 1 n
.. .. .. .. .
. . . .
San a0 San a1 . . . San an
Exercise
2. Find the most plausible values of x, y and z from the equations
x + 3y − 3z = −14
4x + y + 4z = 21
3x + 2y − 5z = 5
x − y + 2z = 3
P. Sam Johnson (NIT Karnataka) Curve Fitting Using Least-Square Principle February 6, 2020 16 / 32
Nonlinear Curve Fitting : Power Function
(xi , yi ), i = 1, 2, . . . , m.
P. Sam Johnson (NIT Karnataka) Curve Fitting Using Least-Square Principle February 6, 2020 17 / 32
Nonlinear Curve Fitting : Exponential function
log y = log a0 + a1 x,
Z = A + Bx,
P. Sam Johnson (NIT Karnataka) Curve Fitting Using Least-Square Principle February 6, 2020 18 / 32
Fitting the data with given curve
(xi , yi ), i = 1, 2, . . . , m,
ei = yi − f (xi ).
P. Sam Johnson (NIT Karnataka) Curve Fitting Using Least-Square Principle February 6, 2020 19 / 32
Fitting the data with given curve
If we write
then the method of least squares consists in minimizing S, i.e., the sum of
the squares of the errors.
P. Sam Johnson (NIT Karnataka) Curve Fitting Using Least-Square Principle February 6, 2020 20 / 32
Weighted Least Squares Approximation
In the above equation, the Wi are prescribed positive numbers and are
called weights.
P. Sam Johnson (NIT Karnataka) Curve Fitting Using Least-Square Principle February 6, 2020 21 / 32
Linear Weighted Least Squares Approximation
and
m
X m
X m
X
a0 Wi xi + a1 Wi xi2 = Wi xi yi
i=1 i=1 i=1
which are the normal equations in this case and are solved to obtain a0
and a1 .
(xi , yi ), i = 1, 2, . . . , m,
y = a0 + a1 x + a2 x 2 + · · · + an x n
P. Sam Johnson (NIT Karnataka) Curve Fitting Using Least-Square Principle February 6, 2020 24 / 32
These conditions yield the normal equations
m
X m
X m
X m
X
a0 Wi + a1 Wi xi + · · · + an Wi xin = W i yi
i=1 i=1 i=1 i=1
m
X m
X m
X m
X
a0 Wi xi + a1 Wi xi2 + · · · + an Wi xin+1 = Wi xi yi
i=1 i=1 i=1 i=1
.. .. .. .. ..
. . . . .
m
X m
X X m m
X
a0 Wi xin + a1 Wi xin+1 + · · · + an Wi xi2n = Wi xin yi .
i=1 i=1 i=1 i=1
If the xi ’s are distinct with n < m, then the equations possses a ’unique’
solution.
P. Sam Johnson (NIT Karnataka) Curve Fitting Using Least-Square Principle February 6, 2020 25 / 32
Method of Least Squares for Continuous Functions
P. Sam Johnson (NIT Karnataka) Curve Fitting Using Least-Square Principle February 6, 2020 26 / 32
Hence
Z b
−2 W (x)[y (x) − (a0 + a1 x + a2 x 2 + · · · + an x n )]dx = 0
a
Z b
−2 W (x)[y (x) − (a0 + a1 x + a2 x 2 + · · · + an x n )]xdx = 0
a
Z b
−2 W (x)[y (x) − (a0 + a1 x + a2 x 2 + · · · + an x n )]x 2 dx = 0
a
.. .. .. .. .. ..
. . . . . .
Z b
−2 W (x)[y (x) − (a0 + a1 x + a2 x 2 + · · · + an x n )]x n dx = 0
a
P. Sam Johnson (NIT Karnataka) Curve Fitting Using Least-Square Principle February 6, 2020 27 / 32
Rearrangement of terms gives the system
Z b Z b Z b Z b
a0 W (x)dx + a1 xW (x)dx + · · · + an x n W (x)dx = W (x)y (x)dx
a a a a
Z b Z b Z b Z b
a0 xW (x)dx + a1 x 2 W (x)dx + · · · + an x n+1 W (x)dx = xW (x)y (x)dx
a a a a
.. .. .. .. .. .. ..
. . . . . . .
Z b Z b Z b Z b
a0 x n W (x)dx + a1 x n+1 W (x)dx + · · · + an x 2n W (x)dx = x n W (x)y (x)dx.
a a a a
P. Sam Johnson (NIT Karnataka) Curve Fitting Using Least-Square Principle February 6, 2020 28 / 32
Exercises
4. If P is the pull required to lift a load W by means of a pulley block,
find a linear law of the form P = mW + C , connecting P and W ,
using the following data.
P (in kg.) 12 15 21 25
W (in kg.) 50 70 100 120
Compute P when W = 150 kg.
5. 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
6. Fit a straight line to the following data and estimate the value of y
corresponding to x = 6.
x 0 5 10 15 20 25
y 12 15 17 22 24 30
P. Sam Johnson (NIT Karnataka) Curve Fitting Using Least-Square Principle February 6, 2020 29 / 32
Exercises
7. Fit a second degree parabola by taking x as the independent variable.
x 1 1 2 3 4
y 1 5 10 22 38
8. Using the method of least squares, fit a curve of the form y = ab x to
the following data.
x 1 2 3 4
y 4 11 35 100
9. Fit a curve of the form y = ab x to the following data.
Year (x) 1951 1952 1953 1954 1955 1956 1957
Production
in tone (y ) 201 263 314 395 427 504 612
10. Fit a curve of the form y = ax b for the following data, where a and b
are constants.
x 61 26 7 10
y 350 400 500 600
P. Sam Johnson (NIT Karnataka) Curve Fitting Using Least-Square Principle February 6, 2020 30 / 32
Exercises
11. Using the principle of least squares, fit an equation of the form
y = ae bx (a > 0) to the data.
x 1 2 3 4
y 1.65 2.7 4.5 7.35
12. The pressure and volume of a gas are related by the equation
pc λ = k (λ and k are constants). Fit this equation for the following
data, using the principle of least squares.
p 0.5 1.0 1.5 2.0 2.5 3.0
v 1.62 1.00 0.75 0.62 0.52 0.46
13. Two quantities of x and y are measured and corresponding values are
given in the following table.
x 20 40 60 80 100 120
y 5.5 9.1 14.9 22.8 33.3 46
Find a second degree parabola to the data.
P. Sam Johnson (NIT Karnataka) Curve Fitting Using Least-Square Principle February 6, 2020 31 / 32
References
P. Sam Johnson (NIT Karnataka) Curve Fitting Using Least-Square Principle February 6, 2020 32 / 32