Numerical Analysis
Non-Linear Regression
Topic: Curve Fitting (Parabola fitting)
Curve Fitting
To determine an equation that
connects variables, first step is to
collect data.
For example, (x1, y1), (x2, y2), (x3,
y3) and so on.
The next step is to plot the data
points on a rectangular coordinate
system. This is called a scatter
For
example, data and scatter diagram are
diagram.
1
0
1
5
2
7
3
8
4
5
7
7
Non-linear Curve Fitting
From a scatter diagram it is often
possible to visualize a smooth
curve. This is an approximate
curve.
For example the data plot shown
here appears to be a parabolic.
So, we say a non-linear relationship
exists between x and y.
We can sometimes reduce a nonlinear
relation to a linear by change of variables.
However, general problem of finding
equation or relationship between x and y or
curve fitting is generally used.
Nonlinear Curve Fitting
Nonlinear Equations Reducible to linear form:
Let us do one example to understand this.
Example 1:
Volume, V
Pressure, P
Table here gives the experimental values
of pressure (P) for various volumes
(V) of gas. According to physics, the
law is PVr = C = constant.
54.3
61.2
61.8
49.5
72.4
37.6
(a) Find values of r and constant C.
(b) Write an equation for P and V.
(c) Find value of P when V = 100.
88.7
28.4
118.6
19.2
194.0
10.1
Nonlinear Curve Fitting
Nonlinear Equations Reducible to linear form:
Example 1:
Since, the law is PV r = C = constant.
We can say:
log P + rlog V = log C
log P = log C rlog V
Calling log V = X
And
log P = Y
The equation can be written as
Y = a 0 + a1 X
Where, a0 = log C and a1 = r
Volume, V
Pressure,
P
54.3
61.2
61.8
49.5
72.4
37.6
88.7
28.4
118.6
19.2
194.0
10.1
Nonlinear Curve Fitting
Nonlinear Equations Reducible to linear form:
Example 1: Table here gives log V = X and log P = Y
V
X = log V
Y = log P
X2
XY
54.3
61.2
1.7348
1.7868
3.0095
3.0997
61.8
49.5
1.7910
1.6946
3.2077
3.0350
72.4
37.6
1.8597
1.5752
3.4585
2.9294
88.7
28.4
1.9479
1.4533
3.7943
2.8309
118.6
19.2
2.0741
1.2833
4.3019
2.6617
194.0
10.1
2.2878
1.0043
5.2340
2.2976
X = 11.6953
Y = 8.7975
X2 = 11.6953
XY = 16.8543
Nonlinear Curve Fitting
Example 1:
To find constants a0 and a1, let us use
normal equations:
Y a N a X
XY a X a X
0
N=6
X = 11.6953
Y = 8.7975
X2 = 23.0059 XY = 16.8543
Putting values of sums into above equations:
8.7975 = 6a0 + 11.6953a1
16.8543 = 11.6953a0 + 23.0059a1
Solving these we get: a0 = 4.20
and a1 = -1.40
So, least square line equation is
Y = 4.20 - 1.40 X
Nonlinear Curve Fitting
Example 1:
(a)
Y = 4.20 - 1.40 X
Since a0 = 4.20 = log C ; and a1 = -1.40 = -r ; it means C = 1.60 x 104 and r = 1.4
(b)
Required equation in terms of P and V is P V 1.4 = 1.60 x 104 .
(c)
When V = 100, X = log V = 2, Y = log P = 4.20 - 2.8 = 1.40;
P = antilog (P) =25.1.
Non-Linear Regression - Parabolic
fitting
To avoid individual judgment in fitting curves, it is necessary
to agree on a definition of best fitting curve.
y
xi , yi
Of all the curves
approximating the data
set, the curve having the
property that sum of all
squares of residual is
minimum, that curve is
called best fitting curve.
2
1
2
2
2
3
2
4
xn , y n
x2 , y 2
x3 , y3
x1 , y1
2
n
i is minimum.
i 1
Parabolic curve fitting
The best fitting parabola is then called least-square curve. The
least square curve that approximates the data (x1, y1), (x2,
y2), . . . , (xn, yn) is
y a0 a1 x a2 x 2
Where, constants are determined
from solving following:
y a N a xa x
0
y
x,y
y a0 x a1 x a2 x
2
x2 , y 2
x3 , y3
These are called normal equations for
least square parabola.
xn , y n
2
3
xy
a
x
a
x
a
x
0
1
2
2
x1 , y1
Example on least square Curve
fitting
Example 2:
Year
Population, y
1880
50.2
1890
62.9
1900
76.0
(a) Draw a graph for the data.
1910
92.0
(b) Find an equation of a least-square parabola that
fits the data.
1920
105.7
1930
122.8
(c) Predict the population in 1990, and 2000.
1940
131.7
1950
151.1
1960
179.3
1970
203.3
1980
226.5
Table shows the population (in millions) of a country
in 10-year intervals.
Example on least square Curve
fitting
Example 3
Year
x2
x3
x4
xy
x2y
1880
-5
50.2
25
-125
625
-251.0
1255.0
1890
-4
62.9
16
-64
256
-251.6
1006.4
1900
-3
76.0
-27
81
-228.0
684.0
1910
-2
92.0
-8
16
-184.0
368.0
1920
-1
105.7
-1
-105.7
105.7
1930
122.8
1940
131.7
131.7
131.7
1950
151.1
16
302.2
604.4
1960
179.3
27
81
537.9
1613.7
1970
203.3
16
64
256
813.2
3252.8
1980
226.5
25
125
625
1132.5
5662.5
x =
0
y =
1401.5
x2 =
110
x3 =
0
x4 =
1958
xy =
8904.7
x2y =
14684.2
Example on least square Curve
fitting
Example 3:
y a0 N a1 x a2 x
To find constants a0 and a1, let us
use normal equations:
2
3
xy
a
x
a
x
a
x
0
1
2
2
3
4
x
y
a
x
a
x
a
x
0
1
2
2
x = 0
y = 1401.5
x2 = 110
x3 = 0
x4 = 1958
xy = 1897.2
Putting values of sums into above equations:
1401.5 = 11 a0 + 110 a1
1897.2 = 110 a1
14684.2 = 110a0 + 1958 a1
Solving these we get: a1 = 17.25 ;
So, least square line equation is
a0 = 119.61 and a2 = 0.7800
y = 119.61 + 17.25 x + 0.78 x2
x2y = 14684.2
Example on least square Curve
fitting
Example 3:
So, least square line equation is
y = 119.61 + 17.25 x + 0.78 x2
The origin is at x = 0 and it is 1930. The unit of x is 10 years.
(c) The year 1990 corresponds to x = 6 and y = 251.2 and the year 2000
corresponds to x = 7 and y = 278.6 million. So, it the trend continues, these
are predicted populations from this curve.
Example on least square Curve
fitting
Example 4: male and female populations in a country as a
function of years is given in millions :
year
1920
1930
1940
1950
1960
1970
1980
Male population
(millions)
53.90
62.14
66.06
75.19
88.33
98.93
110.05
female population
(millions)
51.81
60.64
65.61
76.14
90.99
104.31
116.49
difference
(millions)
2.09
1.50
0.45
-0.95
-2.66
-5.38
-6.44
(a) Graph the differences in these populations.
(b) Find an equation for the least square line fitting this difference data.
(c) Try to predict the differences for the year 1990; year 2000 and year
2010 assuming that the trend continues.
Example on least square line
fitting
Example 4: Farm employment in a country as a function of years
is given in millions of workers as shown in table below:
(a) Graph for the data.
year
Difference
(in millions)
1920
2.90
1930
1.50
1940
0.45
1950
-0.95
1960
-2.66
1970
-5.38
1980
-6.44
Example on least square Curve
fitting
Example 4:
Year
x2
x3
x4
xy
x2y
1920
-3
2.90
-27
81
-8.7
26.1
1930
-2
1.50
-8
16
-3.0
6.0
1940
-1
0.45
-1
-0.45
0.45
1950
-0.95
1960
-2.66
-2.66
-2.66
1970
-5.38
16
-10.76
-21.52
1980
-6.44
27
81
-19.32
-57.96
x =
0
y =
-10.58
x2 = 28
x3 = 0
x4 =196
xy =
-44.89
x2y =
-49.59
Example on least square line
fitting
Example 3:
y a0 N a1 x a2 x
2
3
xy
a
x
a
x
a
x
0
1
2
To find constants, let us use
normal equations:
x = 0
y = -10.58
x2 = 28
2
3
4
x
y
a
x
a
x
a
x
0
1
2
2
x3 = 0
x4 = 196
xy = -44.89
x2y = -49.59
Putting values of sums into above equations:
-10.58 = 7 a0 + 28a2
-44.89 = 28 a1
-49.59 = 28a0 + 196a2
Solving these we get: a1 = - 1.603 ;
So, least square line equation is
a0 = -1.165 and a2 = 0.0866
y = -1.165 - 1.603 x - 0.0866 x2
Example on least square Curve
fitting
Example 4: y = -1.165 - 1.603 x - 0.0866 x
2
Year
yest
1920
-3
2.90
2.87
1930
-2
1.50
1.69
1940
-1
0.45
0.35
1950
-0.95
-1.17
1960
-2.66
-2.86
1970
-5.38
-4.72
1980
-6.44
-6.23
Example on least square Curve
fitting
Example 3: y = -1.165 - 1.603 x - 0.0866 x
2
So, least square curve equation is
The origin is at x = 0 and it is 1950. The unit of x is 10 years.
(c)
The year 1990 corresponds to x = 4 and y = -8.96 million and the year
2000 corresponds to x = 5 and y = -11.35 million. So, it the trend of this
difference in population continues, these are predicted values from this
curve.