Next: Numerical Differentiation and Integration
Up: Numerical Analysis for Chemical
Previous: Optimization
Subsections
Figure 5.1:
Three attempts to fit a best curve.
|
|
The simplest method for fitting a curve to data is to plot the points and
then sketch a line
- (a) Characterize the general upward trend of the data with a straight
line
- (b) Use straight-line segment or linear interpolation
- (c) Use curves to try to captuer the meanderings
Simple statistics
- Arithmetic mean
- Standard deviation : the measure of spread of a sample
where
is the total sum of the squares of the residual between the
data points and the mean, or
- Variance : The square of the standard deviation
- Coefficient of variation (c.v.) : The spread of data
Lest-squares regression is drived from a curve that minimized the
discrepancy between the data points and the curve.
A least-squares approximation is fitting a straight line to a set of paired
observation. The mathematical expression for the straight line is
 |
(5.1) |
The error, or residual, is the discrepancy between the true value of
and
the approximate value,
and that is
 |
(5.2) |
The criterion for least-squares regression is
 |
(5.3) |
To determine values of
and
, differentiate (5.3)
And setting these derivatives equal to zero, we get the so-called normal
equations
| 0 |
 |
(5.6) |
| 0 |
 |
(5.7) |
The coefficients of a straight line are
Quantification of error of linear regression
- The sum of the square of the residual
- A sampled data system
 |
(5.10) |
- A linear regressioned system
 |
(5.11) |
- Standard deviation
- A sampled data system
 |
(5.12) |
quantifies the spread around mean.
- A linear regressioned system
 |
(5.13) |
quantifies the spread around the regression line.
- The goodness of a fit
 |
(5.14) |
where
is called the coefficient of determination and
is the
correlation coefficient.
See the figure 17.4 in the textbook
Figure 5.2:
The residual in linear regression
|
|
The general linear least-square model:
 |
(5.15) |
In matrix notation
 |
(5.16) |
Note that Z is not a square matrix but we want to know about
.
 |
(5.17) |
Now A is
 |
(5.18) |
Gauss-Newton method
- Use a Taylor series to linearize a nonlinear function
- Apply least-square theorie to obtain new estimate of the parameters
that move in the direction of minimizing the residual.
Linear interpolation : connect two data points with a straight line
 |
(5.19) |
Quadratic interpolation : connect three data points with a
second-order polynomial
 |
(5.20) |
where
Newton's interpolating polynomial : connect
data with
th-order polynomial
 |
(5.21) |
where the coefficients are
where the bracket function evaluations are finite divided differences.
th finite divided difference is
![$\displaystyle f[x_n, x_{n-1},\ldots, x_0] = \frac{f[x_n,\ldots,x_1] - f[x_{n-1},\ldots,x_0]}{x_n - x_0}$](img207.png) |
(5.22) |
Newton's divided-difference interpolating polynomial is
![$\displaystyle f_n(x) = f(x_0) + (x-x_0)f[x_1,x_0] + \cdots (x-x_0)(x-x_1)\cdots(x-x_{n-1})f[x_n,\ldots,x_0]$](img208.png) |
(5.23) |
The Lagrange interpolating polynomial is simply a reformulation of the
Newton polynomial that avoids the computation of divided differences.
 |
(5.24) |
where
 |
(5.25) |
where
designates the ``product of.''
Spline interpolation is an alternative approach that lower-order polynomial
is applied to subsets of data point. Especially, when third-order curves
are employed to connect each pair of data points, it is called cubic
spline.
Linear splines : the simplest connection between two points is a
straight line.
where
is the slope of the straight line
 |
(5.26) |
Quadratic splines : connect three points with second-order
polynomials.
- The function values of adjacent polynomials must be equal at the
interior knots.
- The first and last functions must pass through the end points.
- The first derivatives at the interior knots must be equal.
- Assume that the second derivative is zero at the first point.
Cubic splines : derive a third-order polynomial for each interval
between knots
 |
(5.27) |
In early 1800s, the French mathematician Fourier proposed that ``any
function can be represented by an infinite sum of sine and cosine terms.''
There are functions that do not have a representation as a Fourier series,
however, most functions can be so represented. Fourier approximation is
another representation of a function with trigonometric series.
Trigonometric identities
Fourier series
Assume that
is a periodic function of period
and is
integrable over a period.
![$\displaystyle f(x) \simeq A_0 + \sum^\infty_{n=1} \left[ A_n \cos(nx) + B_n \sin(nx) \right]$](img226.png) |
(5.28) |
: integrating on both sides of (5.28) from
to
.
 |
(5.29) |
The last two integrations of trigonometric terms are equal to zero. Hence
 |
(5.30) |
: multiply both sides of (5.28) by
and
integrate
The only nonzero term on the right is when
in the first summation
 |
(5.31) |
: multiply both sides of (5.28) by
and
integrate
The only nonzero term on the right is when
in the second summation
 |
(5.32) |
Fourier series for any period
Consider the function whose period is
.
 |
(5.33) |
where the Fourier coefficients of
are given by the Euler formulas
 |
(5.34) |
Fourier series for even and odd functions
- Even function:
 |
(5.35) |
And integral value of a even function is
 |
(5.36) |
- Odd function:
 |
(5.37) |
And integral value of a even function is
 |
(5.38) |
- Fourier cosine series: the Fourier series of an even function of
period
.
 |
(5.39) |
- Fourier sine series: the Fourier series of an odd function of
period
.
 |
(5.40) |
Complex form of Fourier series : Real sines and cosines can be
expressed in terms of complex exponentials by the formulas
 |
(5.41) |
From this
With the above equation
 |
(5.45) |
where
This is the so-called complex form of the Fourier series, or complex
Fourier series of
.
Sinusoidal function : represent any waveform with a sine or cosine
 |
(5.46) |
where
is the mean value,
is the amplitude,
is the
angular frequency, and
is the phase angle or phase shift.
The angular frequency is related to frequency
(in cycles/time)
 |
(5.47) |
and frequency is
 |
(5.48) |
The trigonometric identity gives
 |
(5.49) |
where
,
Least-squares fit of a sinusoidal function is to determine coefficient
values that minimize
![$\displaystyle S_r = \sum^N_{i=1} \left\{y_i - \left[A_0 + A_1 \cos(\omega_0 t_i) + B_1 \sin(\omega_0 t_i) \right] \right\}^2$](img268.png) |
(5.50) |
 |
(5.51) |
For equispaced system
 |
(5.52) |
where
. These relationhips give
 |
(5.53) |
or
The above equations are similar with the determination of Fourier series.
Figure 5.3:
The Fourier series approximation of the square wave.
|
|
Some of phenomenon does not occured repeatedly or it will be a long time
until it occurs again. In this case we use Fourier integral that can be
used to represent nonperiodic functions, for example a single voltage pulse
not repeated, or a flash of light, or a sound which is not repeated. The
transition from a periodic to a nonperiodic function can be effected by
allowing the period to approach infinity. In other words, as
becomes
infinite, the function never repeats itself and thus becomes aperiodic.
From Fourier series to the Fourier intergral
Consider any periodic function
of period
 |
(5.57) |
where
. Insert
and
which are given by the
Euler formulas.
Now set
 |
(5.58) |
Then
, and
Let
and assume a periodic function
to be a
aperiodic function.
 |
(5.59) |
Then
and the first term of function approaches zero.
![$\displaystyle f_L(x) = \frac{1}{\pi} \sum^\infty_{n=1} \left[ \cos \omega_n x \...
...v + \sin \omega_n x \Delta \omega \int^L_{-L} f_L(v) \sin \omega_n v dv \right]$](img291.png) |
(5.60) |
results in
and the sum
of infinite series become an integral from 0 to
.
![$\displaystyle f(x) = \frac{1}{\pi} \int^\infty_0 \left[ \cos \omega x \int^\inf...
... dv + \sin \omega x \int^\infty_{-\infty} f(v) \sin \omega v dv \right] d\omega$](img295.png) |
(5.61) |
Introduce
and
as
 |
(5.62) |
Finally Fourier series for an aperiodic equation become
![$\displaystyle f(x) = \int^\infty_0 \left[ A(\omega) \cos \omega x + B(\omega) \sin \omega x \right] d\omega$](img299.png) |
(5.63) |
This is called a representation of
by a Fourier integral.
Alternatively, the Fourier integral can be written as complex Fourier
series.
 |
(5.64) |
![$\displaystyle f(x) = \sum^\infty_{-\infty} \left[ \frac{1}{2L} \int^L_{-L} f(u) e^{-i\omega_n u} du \right] e^{i\omega_nx}$](img301.png) |
(5.65) |
Use
where
 |
(5.68) |
If
goes to zero, a limit of a sum becomes an integral
Define
by
 |
(5.71) |
Then
 |
(5.72) |
Fourier Transform
 |
(5.73) |
and
are called a pair of Fourier transforms. Usually,
is called the Fourier transform of
, and
is called
the inverse Fourier transform of
.
In engineering, functions are often represented by finite sets of discrete
values and data is often collected in or converted to such a discrete
format. For the discrete time system, a discrete Fourier transform can be
written as
 |
(5.74) |
and the inverse Fourier transform as
 |
(5.75) |
where
.
The fast Fourier transform (FFT) is an algorithm that has been developed to
compute the DFT in an extremely economical fashion.
A power spectrum is developed from the Fourier transform and it is derived
from the analysis of the power output of electrical systems. The power of a
periodic signal can be defined as
 |
(5.76) |
A power spectrum can be calculated by the power associated with each
frequency component.
- Matlab:
- polyfit
- polyval
- poly2sym
- interp1
- spline
- fft
- IMSL: various routines are exist to solve curve fitting and fft problems
See the textbook
Next: Numerical Differentiation and Integration
Up: Numerical Analysis for Chemical
Previous: Optimization
Taechul Lee
2001-11-29