Professional Documents
Culture Documents
Curve Fitting Update1
Curve Fitting Update1
Curve Fitting Update1
Henok Mekonnen
Henok Mekonnen Solutions of Systems of Linear Algebraic Equations April 16, 2024 1 / 48
Summary
1 Introduction
2 Statistical background
Henok Mekonnen Solutions of Systems of Linear Algebraic Equations April 16, 2024 2 / 48
Summary
4 Interpolation
Overview
Newton’s Divided Difference Interpolation
Linear Interpolation
Quadratic Interpolation
General Polynomial Interpolation
Error Estimation
Lagrange’s Interpolation
Spline Interpolation
Multi-dimensional interpolation
5 Fourier Approximation
Periodic Functions and Sinusoidals
Curve fitting with Sinusoidals
Continuous Fourier Series
Henok Mekonnen Solutions of Systems of Linear Algebraic Equations April 16, 2024 3 / 48
Introduction
Henok Mekonnen Solutions of Systems of Linear Algebraic Equations April 16, 2024 4 / 48
Introduction
Henok Mekonnen Solutions of Systems of Linear Algebraic Equations April 16, 2024 5 / 48
Statistical background
Arithmetic mean (y ) is the sum of each data point values (yi ) divided
by the number of data points (n),
P
yi
y= (1)
n
Standard deviation about the mean, Sy is a common measure of the
spread or deviation of the data points around the arithmetic mean,
r
St
Sy = (2)
n−1
where St is the total sum of the squares of the residuals between the
data points and the mean,
X
St = (yi − y )2 (3)
Henok Mekonnen Solutions of Systems of Linear Algebraic Equations April 16, 2024 6 / 48
Statistical Background
The variance is another measure of the deviation of the data points
from the mean, which is the square of the standard deviation
(yi − y )2
P
2
Sy = (4)
n−1
The above equation can be written more conveniently without
evaluating the mean
P 2
2 (yi − yi y + (y )2 )
Sy = (5)
n−1
but
X (y1 + y2 + ... + yn ) (y1 + y2 + ... + yn )
yi y = y1 + y2 + ...
n n P
(y1 + y2 + ... + yn ) ( y i )2
+yn = and (6)
n Xn
y2 = 0
Henok Mekonnen Solutions of Systems of Linear Algebraic Equations April 16, 2024 7 / 48
Statistical Background
Thus,
yi2 − ( yi )2 /n
P P
Sy2 = (7)
n−1
Normal distribution
All kinds of variables in natural and social sciences are normally or
approximately normally distributed.
Henok Mekonnen Solutions of Systems of Linear Algebraic Equations April 16, 2024 8 / 48
Linear Regression
This is the simplest one of the least square regression techniques
data points are approximated by a linear expression or straight line
graphically
y = a0 + a1 x + e (8)
Residual
In the above linear regression equation, the term e is the residual which is
the difference between the value of the data point and the calculated value
corresponding to the data point.
Henok Mekonnen Solutions of Systems of Linear Algebraic Equations April 16, 2024 9 / 48
Linear Regression
The above criterion has its shortcomings, for example, in that it
doesn’t give a unique solution. A better expression of best-fit criteria
can be given as:
n
X n
X X
Sr = ei2 = (yi,measured −yi,modeled )2 = (yi −a0 −a1 xi )2 (10)
i=1 i=1
Let’s differentiate the total residual with respect to each coefficient.
∂Sr
= −2(yi − a0 − a1 xi )
∂a0
(11)
∂Sr
= −2[(yi − a0 − a1 xi )xi ]
∂a1
Minimizing the derivatives will minimize the total residual (Sr )
X X X
0= yi − a0 − a1 xi
X X X (12)
0= yi xi − a0 xi − a1 xi2
Henok Mekonnen Solutions of Systems of Linear Algebraic Equations April 16, 2024 10 / 48
Linear Regression
Henok Mekonnen Solutions of Systems of Linear Algebraic Equations April 16, 2024 11 / 48
Linear Regression
Goodness of fit
The distribution of the actual data points around the regression line
can show how good the fitting is. This can be defined as the standard
deviation around the regression line, instead of the mean value.
r
Sr
sy /x = (15)
n−2
The n − 2 is chosen instead of n because connecting two points
should be meaningless in terms of standard deviation, and n = 2
makes the denominator of the above expression zero.
Henok Mekonnen Solutions of Systems of Linear Algebraic Equations April 16, 2024 12 / 48
Linearization of non-linear relationships
Not all data can be approximated by a linear regression.
There are some data whose non-linear relationship can be converted
to a linear relationship.
One notable case is converting an exponential model into a linear
logarithmic one.
y = α1 e β1 x
(16)
ln y = ln α1 + β1 x
Henok Mekonnen Solutions of Systems of Linear Algebraic Equations April 16, 2024 13 / 48
Polynomial Regression
In a similar pattern a polynomial regression equation can be written as
y = a0 + a1 x + a2 x 2 + ... + an x n + e (18)
The sum of the squares of the residuals is
n
X
Sr = yi − a0 − a1 xi − a2 xi2 (19)
i=1
Henok Mekonnen Solutions of Systems of Linear Algebraic Equations April 16, 2024 14 / 48
Polynomial Regression
Henok Mekonnen Solutions of Systems of Linear Algebraic Equations April 16, 2024 15 / 48
Polynomial Regression
The above second-order polynomial equation can be extended to a
general m − th order polynomial as:
Putting the set of equations in matrix form
P P 2 P m P
n xi x ··· xi a0 yi
P P 2
P i3 P m+1 P
xi x i xi ··· xi a1 yi xi
.. = ..
.. .. .. .. ..
. . . . . . .
P m P m+1 P m+2 P 2m P m
xi xi xi ··· xi an yi xi
The derivatives
∂Sr X
= −2 yi − a0 − a1 x1i − a2 x2i
∂a0
∂Sr X
= −2 (yi − a0 − a1 x1i + a2 x2i )x1i (25)
∂a1
∂Sr X
= −2 (yi − a0 − a1 x1i + a2 x2i )x2i
∂a2
Henok Mekonnen Solutions of Systems of Linear Algebraic Equations April 16, 2024 17 / 48
Multiple Linear Regression
Henok Mekonnen Solutions of Systems of Linear Algebraic Equations April 16, 2024 18 / 48
Multiple Linear Regression
Henok Mekonnen Solutions of Systems of Linear Algebraic Equations April 16, 2024 19 / 48
Multiple Linear Regression
Henok Mekonnen Solutions of Systems of Linear Algebraic Equations April 16, 2024 20 / 48
General Least Square
The general matrix expression for multiple linear regression equation
will have profound use
y = a0 z0 + a1 z1 + a2 z2 + ... + am zm + e (29)
This general expression can also encompass polynomials as long as
the terms z0 , z1 , ..., zm terms represent monomial functions.
z0 = x 0 = 1, z1 = x, z2 = x 2 , z3 = x 3 , ... zm = x m (30)
For multiple data points
yi = a0 z0i + a1 z1i + a2 z2i + ... + am zmi + ei (31)
The sum of the square of the residuals is
Xn X
Sr = ei2 = (yi − a0 z0i − a1 z1i − a2 z2i − ... − am zmi )2
i=1
n m (32)
X X
2
Sr = (yi − aj zji )
i=1 j=0
Henok Mekonnen Solutions of Systems of Linear Algebraic Equations April 16, 2024 21 / 48
General Least Square
Henok Mekonnen Solutions of Systems of Linear Algebraic Equations April 16, 2024 22 / 48
General Least Square
Evaluating all the derivatives to zero to minimize the residuals
X X X X X
a0 z0i2 + a1 z0i z1i + a2 z0i z2i + ... + am z0i zmi = z0i yi
X X X X X
a0 z0i z1i + a1 z1i2 + a2 z1i z2i + ... + am z1i zmi = z1i yi
X X X X X
a0 z0i z2i + a1 z1i z2i + a2 z2i2 + ... + am z2i zmi = z2i yi
..
.
X X X X X
2
a0 z0i zmi + a1 z1i zmi + a2 z2i zmi + ... + am zmi = zmi yi
(34)
In matrix form
P 2 P P P P
P z0i Pz0i 2z1i P z0i z2i ... P z0i zmi a0 P z0i yi
z0i z1i z1i Pz1i 2z2i ... P z1i zmi a1 P z1i yi
P
z0i z2i P z1i z2i z2i ... z2i zmi
a2 = z2i yi
.. .. .. ..
.
P .
. .
P P P 2 P
z0i zmi z1i zmi z2i zmi ... zmi am zmi yi
Henok Mekonnen Solutions of Systems of Linear Algebraic Equations April 16, 2024 23 / 48
General Least Square
You can notice that the coefficient matrix is simply the product of the
vector of coefficients [Z ] and its transpose [Z ]T . Therefore, the
general least square regression in condensed matrix form is:
Henok Mekonnen Solutions of Systems of Linear Algebraic Equations April 16, 2024 24 / 48
Non-linear Regression
Some data do not fit with the general linear least square regression
curves.
f (x) = a0 (1 − e −a1 x ) + e (37)
In this case, the non-linear equation can be approximated by Taylor
series into a linear function. This method is called the Gauss-Newton
method
yi = f (xi , a0 , a1 , ..., am ) + ei (38)
yi = f (xi ) + ei (39)
∂f (xi )j ∂f (xi )j
f (xi )j+i = f (xi )j + ∆a0 + ∆a1 (40)
∂a0 ∂a1
∂f (xi )j ∂f (xi )j
yi − f (xi )j = ∆a0 + ∆a1 + ei (41)
∂a0 ∂a1
where j represents the iterative steps and i denotes the data points
Henok Mekonnen Solutions of Systems of Linear Algebraic Equations April 16, 2024 25 / 48
Non-linear Regression
In matrix form y1 − f (x1 )
y2 − f (x2 )
D = ..
.
{D} = [Zj ]{∆A} + {E } (42) yn − f (xn )
∆a0
∆a1
∆A = .
∂f1 ∂f1 ..
∂a0 ∂a1
∂f2 ∂f2 ∆am
∂a0 ∂a1
Zj . ..
.. . [[Zj ]T [Zj ]]{∆A} = {[Zj ]T {D}}
∂fn ∂fn (43)
∂a0 ∂a1
Henok Mekonnen Solutions of Systems of Linear Algebraic Equations April 16, 2024 26 / 48
Non-linear Regression
Convergence criteria
ak,j+1 − ak,j
|εa |k = 100% (45)
ak,j+1
Henok Mekonnen Solutions of Systems of Linear Algebraic Equations April 16, 2024 27 / 48
Interpolation: Overview
Henok Mekonnen Solutions of Systems of Linear Algebraic Equations April 16, 2024 28 / 48
Newton’s Divided Difference Interpolation: Linear
Interpolation
Linear Interpolation: The interpolation equation is derived by
equating the slope.
f1 (x) − f (x0 ) f (x1 ) − f (x0 )
= = slope (47)
x − x0 x1 − x0
Henok Mekonnen Solutions of Systems of Linear Algebraic Equations April 16, 2024 32 / 48
Newton’s Divided Difference Interpolation: General
Polynomial Interpolation
Henok Mekonnen Solutions of Systems of Linear Algebraic Equations April 16, 2024 33 / 48
Newton’s Divided Difference Interpolation: Error
Estimation
We use an analogy with the Taylor series approximation. The
truncation error can be given by:
f (n+1) (ξ)
Rn = (xi+1 − xi )n+1 (57)
(n + 1)!
where ξ is somewhere in the interval xi to xi+1
For an nth order interpolating polynomial, an analogous relationship is
f (n+1) (ξ)
Rn = (x − x0 )(x − x1 )...(x − xn ) (58)
(n + 1)!
where ξ is somewhere in the interval between the unknown and the
data
This formula requires that it should be differentiable to be used. This
is not usually the case
Henok Mekonnen Solutions of Systems of Linear Algebraic Equations April 16, 2024 34 / 48
Newton’s Divided Difference Interpolation: Error
Estimation
We can approximate the error function with the finite divide difference
Henok Mekonnen Solutions of Systems of Linear Algebraic Equations April 16, 2024 35 / 48
Lagrange’s Interpolation
The Newton interpolation polynomial could have been evaluated as:
x − x1 x − x0
f1 (x) = f (x0 ) + f (x1 ) (61)
x0 − x1 x1 − x0
(x − x1 )(x − x2 ) (x − x0 )(x − x2 )
f2 (x) = f (x0 ) + f (x1 )
(x0 − x1 )(x0 − x2 ) (x1 − x0 )(x1 − x2 )
(62)
(x − x0 )(x − x1 )
+ f (x2 )
(x2 − x0 )(x2 − x1 )
The general form is
n
X
fn (x) = Li (x)f (xi ) (63)
i=0
where
n
Y x − xj
Li (x) = (64)
xi − xj
j=0
j̸=1
Henok Mekonnen Solutions of Systems of Linear Algebraic Equations April 16, 2024 36 / 48
Largange’s Interpolation
Now you can imagine that for the conventional general polynomial
expression of order n, where there are n + 1 known data points, it is
possible to solve the system of equations simultaneously with the
methods discussed in chapter three.
But as the order of polynomials increases, the system of equations
becomes increasingly ill-conditioned and can also yield erroneous
results.
Therefore, as long as interpolation is of interest, go for the techniques
discussed here (Newoton’s or Lagrange’s interpolation polynomials)
Henok Mekonnen Solutions of Systems of Linear Algebraic Equations April 16, 2024 37 / 48
Spline Interpolation
The spline interpolation gives a visually smooth curve yet it defines
the interpolation functions for each interval between two data points.
It should satisfy two conditions
The interpolation equations of adjacent intervals should give the same
value at the intersection point
The slopes of the equations of the adjacent intervals should be equal
for a smooth transition
Henok Mekonnen Solutions of Systems of Linear Algebraic Equations April 16, 2024 41 / 48
Periodic Functions and Sinusoidals
A periodic function, which repeats itself in fixed intervals is expressed
as
f (t) = f (t + T ) (74)
where T is the period
One very common periodic function is a sinusoidal function which can
be expressed either in sine or cosine functions
Figure: Sinusoidal (a) General expression in a single curve (b) Each term in
separate curves
Henok Mekonnen Solutions of Systems of Linear Algebraic Equations April 16, 2024 43 / 48
Curve fitting with Sinusoidals: Least Squares
Fitting data with this general sinusoidal expression will have residuals
at each data point
Henok Mekonnen Solutions of Systems of Linear Algebraic Equations April 16, 2024 44 / 48
Curve fitting with Sinusoidals: Least Squares
Henok Mekonnen Solutions of Systems of Linear Algebraic Equations April 16, 2024 45 / 48
Curve fitting with Sinusoidals: Least Squares
In Matrix form
P P P
P N P cos(ω 0 ti ) sin(ω0 ti ) A0 yi
cos 2 (ω0 ti )
P P
cos(ω0 ti ) sin(ω
P 0 t2i )cos(ω0 ti )
A1 = yi cos(ω0 ti )
P P P
sin(ω0 ti ) cos(ω0 ti )sin(ω0 ti ) sin (ω0 ti ) B1 yi sin(ω0 ti )
where
i = −1
Z T /2 (88)
1
cek = f (t)e −kw0 t dt
T −T /2
Henok Mekonnen Solutions of Systems of Linear Algebraic Equations April 16, 2024 48 / 48