Numerical Methods Notes
Numerical Methods Notes
Gaussian Elimination
Objectives:
Introduction
Gaussian Elimination
Pitfalls in Gauss Elimination Method
Pivoting
Scaling
Introduction
Well see how to solve a set of n linear equations with n
unknowns.
If n 3, the small set of linear equations can be solved
analytically.
Simultaneous linear equations arise in a variety of
engineering problems context i.e. trusses, reactors, electric
circuits,
Broadly there are two types of methods to solve the linear
equations: Direct methods and Iterative methods.
Gaussian Elimination
Solving a set of n linear equations:
a11 x1 a12 x2 ... a1n xn b1
an1 x1 an 2 x2 ... a nn xn bn
Solution consists of two phases:
1. Forward elimination of unknowns
2. Back substitution
x2 ... a2 n xn b2
a22
where the prime indicates the new values for the elements.
x2 a23
x3 ... a2 n xn b2
a22
x2 a33
x3 ... a3n xn b3
a32
.
an 2 x2 an 3 x3 ... ann xn bn
The second unknown x2 is eliminated by multiplying
/ a22
and subtracting
through the next equation by a32
the result from the following equation.
The procedure is continued using the remaining pivot
equations. At the end of the elimination stage, the
original system of equations is transformed to an
upper triangular system:
a11 x1 a12 x2 a13 x3 ... a1n xn b1
x2 a23
x3 ... a2 n xn b2
a22
x3 ... a3n xn b3
a33
.
.
.
( n 1)
ann
xn bn( n 1)
2. Back Substitution
The last unknown xn is now given by:
bn( n 1)
xn ( n 1)
ann
Example 1
Use Gauss elimination to solve:
3 x1 0.1 x2 0.2 x3 = 7.85
(a)
(b)
(c)
Solution of Example 1
1. Forward elimination
Multiply 1st equation (a) by 0.1/3 and subtract from 2nd
equation (b) to eliminate x1 from the latter equation:
7.00333 x2 0.293333 x3 = -19.5617
(a)
(b)
(c)
3 x1
0.1 x2
0.2 x3
= 7.85
(a)
(b)
10.0200 x3 = 70.0843
(c)
2. Back Substitution
Solve last equation (c) to find x3 :
x3 = 70.0843/10.0200 = 7.00003
x2 = -2.50000
x1 = 3.00000
2. Round-off errors
This may be due to some of the following:
Large number of equations to be solved due to the fact
that every result is dependent on previous results.
Errors in early steps will tend to propagate.
Pivoting
This involves the following steps:
(1)
(2)
Solution of example 2
1. Firstly, lets solve these equations the same way we did in
example 1:
Forward elimination:
Multiply equation (1) by 1/0.0003 to get
x1 + 10,000 x2 = 6667
Subtract the resulting equation from equation (2) to get
-9999 x2 = -6666 x2 = 2/3
Back substitution:
0.0003 x1 + 3.0000 x2 = 2.0001
x1 = 2.0001 3(2/3)
0.0003
10
0.667
-3.33
1099
0.6667
0.0000
100
0.66667
0.30000
10
0.666667
0.330000
0.6666667
0.3330000
0.1
(2)
Forward elimination:
Multiply equation (1) by 0.0003 to get
0.0003 x1 + 0.0003 x2 = 0.0003
Subtract the resulting equation from equation (2) to get
x2 = 2/3
2.9997 x2 = 1.9998
Back substitution:
11
x1 + x2 = 1
x1 = 1 (2/3)
1
x1
x1 (%)
0.667
0.333
0.1
0.6667
0.3333
0.01
0.66667
0.33333
0.001
0.666667
0.333333
0.0001
0.6666667
0.3333333
0.00001
12
Scaling
Scaling is necessary when different units are used in the
same system of equations.
Scaling is used to:
1. Standardize the size of the coefficients in the system
of equations.
2. Minimize the round-off errors caused by having much
larger coefficients than others.
Example 3
Use three significant figures to solve
2 x1 + 100000 x2 = 10000
x1 +
x2 = 2.
(1)
(2)
(1)
13
- 50000 x2 = -5000
Back substitution
x2 = 0.10
(2)
and x1 = 0.00
x1 + x2 = 2
(2)
Pivoting
x1 + x2 = 2
(1)
0.00002 x1 + x2 = 0.1
(2)
Forward elimination
x1 + x2 = 2
x2 = 0.1
Back substitution
x1 = 1.90 and x2 = 0.10
14
(1)
Forward elimination
x1 +
x2 = 2
100000 x2 = 10000
Back substitution
x1 = 1.90 and x2 = 0.10
15
Factorization Methods
Objectives:
Introduction
LU Decomposition
Computational complexity
The Matrix Inverse
Extending the Gaussian Elimination Process
Introduction
Provides an efficient way to compute matrix inverse by
separating the time consuming elimination of the Matrix
[A] from manipulations of the right-hand side {B}.
Gauss elimination, in which the forward elimination
comprises the bulk of the computational effort, can be
implemented as an LU decomposition.
LU Decomposition
The matrix [A] for the linear system [A]{X}={B} is
factorized into the product of two matrices [L] and [U] (Llower triangular matrix and U- upper triangular matrix)
[L][U]=[A]
[L][U]{X}={B}
Similar to first phase of Gauss elimination, consider
16
[U]{X}={D}
[L]{D}={B}
The solution can be obtained by
1. First solve [L]{D}={B} to generate an intermediate
vector {D} by forward substitution
2. Then, solve [U]{X}={D} to get {X} by back
substitution.
17
m32
a32
a22
18
0
1
A m21 1
m31 m32
0 a11 a12
0 0 a22
1 0
0
a13
a23
a33
Example :
Use LU decomposition to solve:
3x1 0.1x2 0.2x3 = 7.85
0.1x1 + 7x2 0.3x3 = -19.3
0.3x1 0.2x2 + 10x3 = 71.4
use 6 significant figures in your computation.
Example 1 - Solution
In matrix form
3 0.1 0.2 x1 7.85
0.1
7
0.3 x2 19.3
m32
m31
.3
0.100000
3
0.193
0.0271300
7.00333
19
The LU decomposition is
1
0
0 3
0.1
0.2
A 0.0333333
1
0 0 7.00333 0.293333
0
10.0120
0.100000 0.0271300 1 0
1
0
0 d1 7.85
0.0333333
1
0 d 2 19.3
d1 7.85
d 2 19.3 0.0333333(7.85) 19.5617
d3 71.4 0.1(7.85) 0.02713(19.5617) 70.0843
0.1
0.2 x1 7.85
3
0 7.00333 0.293333 x 19.5617
2
0
10.0120 x3 70.0843
0
20
x3 70.0843 / 10.0120 7.00003
x2 (19.5617 0.293333(7.00003)) / 7.00333 2.5
x1 (7.85 0.1(2.5) 0.2(7.00003)) / 3 3
21
Computational Complexity
The triangular factorization portion of [A]=[L][U] requires
(N3-N)/3 multiplications and divisions
(2N3-3N2+N)/6 subtractions
Finding the solution to [L][U]{X}={B} requires
N2 multiplications and divisions
N2-N subtractions
The bulk of the calculation lies in the triangularization
portion.
LU decomposition is usually chosen over Gauss
elimination when the linear system is to be solved many
times, with the same [A] but with different {B}.
Saves computing time by separating time-consuming
elimination step from the manipulations of the right hand
side.
Provides efficient means to compute the matrix inverse
which provides a means to test whether systems are illconditioned
22
1
The solution of [L][U]{X}={B} with 0
0
will
0
The solution of [L][U]{X}={B} with 1
0
will
0
The solution of [L][U]{X}={B} with 0
1
will
Example 2:
Use LU decomposition to determine the matrix inverse for
the following system and use it to find the solution:
3x1 0.1x2 0.2x3 = 7.85
0.1x1 + 7x2 0.3x3 = -19.3
0.3x1 0.2x2 + 10x3 = 71.4
use 6 significant figures in your computation.
23
Example 2- Solution
3 0.1 0.2
In matrix form
A 0.1 7 0.3
0.3 0.2 10
1
0
0
L 0.0333333
1
0
0.100000 0.0271300 1
0.1
0.2
3
U 0 7.00333 0.293333
0
10.0120
0
1
0
0 d1 1
0.0333333
1
0 d 2 0 D 0.03333
0.1009
0.100000 0.0271300 1 d3 0
0.1
0.2 x1 1
3
0.33249
0 7.00333 0.293333 x 0.03333 X 0.00518
2
0.01008
0
10.0120 x3 0.1009
0
24
1
0
0 d1 0
0.0333333
1
0 d 2 1 D 1
0.02713
0.100000 0.0271300 1 d3 0
0.1
0.2 x1 0
3
0.004944
0 7.00333 0.293333 x 1
0
.
142903
2
0.00271
0
10.0120 x3 0.02713
0
1
0
0 d1 0
0
0.0333333
1
0 d 2 0 D 0
1
0.100000 0.0271300 1 d3 1
0.1
0.2 x1 0
3
0.006798
0 7.00333 0.293333 x 0 X 0.004183
2
0.09988
0
10.0120 x3 1
0
25
26
Example 3 - Solution
In matrix form [A ]{X}={B}
0.0003 3 x1 2.0001
1
x 1
1
27
0 1
1 0
1
0
0.0003 1
1
1
0 2.9997
1 0 1
2.0001
2. Solve [L]{D}=[P]{B}
substitution.
for
{D}
using
forward
0 d1 1
1
0.0003 1 d 2.0001
1.9998
1 x1 1
1
0.33333
0 2.9997 x 1.9998
0
.
66667
28
Iterative Methods
Objectives:
Introduction
Jacobi Method
Gauss-Seidel Method
Introduction
To solve the linear system Ax = b we may use either:
Direct Methods
- Gaussian elimination
- PLU decomposition
Iterative Methods
- Jacobi Method
- Gauss-Seidel Method
Iterative Methods
Suppose we solve Ax = b for a given matrix A by finding
the PLU decomposition
If we change the vector b, we may continue to use the PLU
If we change A, we now have to re-compute the PLU
decomposition: expensive
Instead, suppose we have solved the system Ax = b
for a given matrix A
29
x1
b1 a12 x2 a13 x3
a11
x2
b2 a21 x1 a23 x3
a22
x3
b3 a31 x1 a32 x2
a33
30
a33
31
Gauss-Seidel Method
It is the most commonly used iterative method.
Gauss-Seidel Procedure
1. Assume all the xs are zero
2. Substitute the zeros into the first equation i.e. equation (1)
to give:
b
x1 1
a11
3. Substitute the new value of x1 and x3 = 0 into equation (2)
to compute x2
4. Substitute the value of x1 and the new value of x2 in
equation (3) to estimate x3
5. Return to equation (1) and repeat the entire procedure until
the error criterion is satisfied:
i 1
1
a11
i 1
2
a22
i 1
3
a33
x
x
a, j
x ij x ij1
100% s
x ij
32
Example 1:
Use Gauss-Seidel method to solve the following set of linear
equations:
3 x1 0.1 x2 0.2 x3 = 7.85
(1)
(2)
(3)
Example 1 - Solution
First we have:
33
1st iteration
Assume that x2 = 0 and x3 = 0, we obtain
7.85
x1
2.616667
3
Substitute x1 = 2.616667 and x3 = 0 into equation (2)
19.3 0.1(2.616667) 0
x2
2.794524
7
Substitute x1 = 2.616667 and x2 = -2.794524 into
equation (3)
x3
2nd iteration
x1
x2
34
x3
Error estimate
For x1
2.990557 2.6166667
a ,1
100% 12.5%
2.990557
For x2
a,2
2.499625 (2.794524)
100% 11.8%
2.499625
For x3
a ,3
7.000291 7.005610
100% 0.07%
7.000291
n
aii aij
j 1
j i
35
Convergence
Gauss-Seidel is similar in spirit to the simple fixed-point
iteration.
Gauss-Seidel will converge if for every equation of the
system, we have:
Such system is said to be diagonally dominant.
This criterion is sufficient but not necessary for
convergence.
Relaxation
Designed to Enhance convergence.
After each new value of x is computed, that value is
modified using:
xinew xinew 1 xiold
Where 0 2 is a weighting factor.
The choice of is problem-specific and is often
determined empirically.
36
37
Introduction
Eigenvalue problems are a special class of problems that
are common in engineering contexts involving vibrations
and elasticity.
Many systems of ODEs can be reduced to eigenvalue
problems.
Mathematical Background
So far we learned to solve [A]{x}={b}
Such systems are called nonhomogeneous because of the
presence of {b}.
If det[A] 0 unique solution of {x}
38
a21 x1 (a22 ) x2
...
an1 x1 an 2 x2
...
a2 n xn 0
(ann ) xn 0
39
Physical Background
The following mass-spring system is a simple illustration of
how eigenvalues occur in engineering context.
d 2 x1
m1 2 kx1 k ( x2 x1 )
dt
40
d 2 x2
m2 2 k ( x2 x1 ) kx2
dt
From vibration theory, the solutions to these equations
xi X i sin(t )
where
Xi is the amplitude of the vibration of mi
is the frequency of the vibration given by
2
Tp
Tp is the period.
2k
k
2 ) X1 X 2 0
m1
m1
k
2k
X1 ( 2 ) X 2 0
m2
m2
41
42
Example 1
Use the polynomial method to evaluate the eigenvalues and
eigenvectors of the spring-mass example for the case where m1
= m2 = 40 kg and k = 200 N/m.
Example 1 - Solution
Convert the system to an eigenvalue problem
(10 2 ) X 1 5 X 2 0
5 X 1 (10 2 ) X 2 0
Expand determinant det[[A]- [I]] = 0.
( 2 )2 20 2 75 0
Solve for 2
2 = 15 and 2 = 5 s 2
43
(10 15) X 1 5 X 2 0
5 X 1 (10 15) X 2 0
X1 = - X 2
- Similarly, for the second mode ( 2 = 5) X 1 = X 2
44
45
Example 2
Employ the power method to determine the highest eigenvalue
and its associated eigenvector of a three mass-four spring system
for the case where m1 = m2 = m3 = 1 kg and k1 = k2 = k3 = k4 = k
= 20 N/m.
46
Example 2 - Solution
Convert the system to an eigenvalue problem
2k
k
( 2 ) X1 X 2 0
m1
m1
2k
k
k
X 1 2 X 2
X3 0
m2
m
m
2
2k
k
X 2 2 X 3 0
m3
m3
A{X } {X }
0 X1
40 20
X1
20 40 20 X X
2
2
X
20 40 X 3
0
3
47
Eventually converges
Eigenvalue = 68.28427
0.707107
Eigenvector
1
=
0.707107
eigenvalue and
its
48
Assignment #5
27.11, 28.25, 28.27
49
Polynomial Interpolation
Objectives
Introduction
Newtons Divided Difference Method
i. Linear interpolation
ii. Quadratic interpolation
iii. General Form of Newtons Interpolation
Lagrange Interpolation
Introduction
Techniques to fit curves to discrete values of data to obtain
intermediate estimates.
- Regression (imprecise data)
- Interpolation (precise data)
Curve fitting is widely used in engineering
- Trend analysis: extrapolation and interpolation
- Hypothesis testing: compare a mathematical
model with measured data.
50
Linear Interpolation
Using similar triangles,
f1 ( x) f ( x0 ) f ( x1 ) f ( x0 )
x x0
x1 x0
And rearranging, we get
f1 ( x) f ( x0 )
f ( x1 ) f ( x0 )
( x x0 )
x1 x0
51
f ( x1 ) f ( x0 )
x1 x0
The smaller the interval between data points, the better the
approximation.
Example 1:
Estimate the natural logarithm of 2 using linear interpolation:
1. Interpolate between ln1 and ln6
2. Use interval ln1 to ln4
Example1 - Solution
Linear interpolation
f1 ( x) f ( x0 )
f ( x1 ) f ( x0 )
( x x0 )
x1 x0
f1 (2) ln 1
ln 6 ln 1
(2 1) 0.3583519
6 1
t=48.3%
f1 (2) ln 1
ln 4 ln 1
(2 1) 0.4620981
4 1
t=33.3%
52
Quadratic Interpolation
This is a mean of improving an estimate by introducing a
curvature into the line connecting the points.
Using three data points, a second-order polynomial or
quadratic polynomial or parabola is used to carry out the
estimate:
f2(x) = b0 + b1(x-x0) + b2(x-x0)(x-x1)
= b0 + b1x - b1x0 + b2x2 - b2x0x - b2xx1 + b2x0x1
53
= a0 + a1x + a2x2
Where
a0 = b0 - b1x0 + b2x0x1
a1 = b1 - b2x0 - b2x1
a2 = b2
f (x) = b0 + b1(x-x0) + b2(x-x0)(x-x1)
f ( x1 ) f ( x0 )
x1 x0
Evaluate f at x = x2
f ( x2 ) f ( x1 ) f ( x1 ) f ( x0 )
x2 x1
x1 x0
b2
x2 x0
54
f (x0) = 0
x1 = 4
f (x1) = 1.386294
x2 = 6
f (x2) = 1.791759
Example 2 - Solution
First, lets compute the coefficients b0 , b1 and b2:
b0 f ( x0 ) ln 1 0
b1
f ( x1 ) f ( x0 ) ln 4 ln 1 1.386294 0
0.4620981
x1 x0
4 1
3
f ( x2 ) f ( x1 ) f ( x1 ) f ( x0 )
x2 x1
x1 x0
b2
x2 x0
55
ln 6 ln 4 ln 4 ln 1
4 1 0.0518731
64
6 1
The quadratic polynomial is then:
f2(x) = 0 + 0.4620981(x-1) 0.0518731(x-1)(x-4)
56
b0 f ( x0 )
b1 f [ x1 , x0 ]
b2 f [ x2 , x1 , x0 ]
.
.
bn 1 f [ xn 1 , xn 2 ,..., x1 , x0 ]
The bracketed function evaluations are finite divided
differences
f [ xi , x j ]
f ( xi ) f ( x j )
xi x j
f [ xi , x j , xk ]
f [ xi , x j ] f [ x j , xk ]
xi xk
f [ xn 1 , xn 2 ,..., x1 , x0 ]
f [ xn 1 , xn 2 ,..., x1 ] f [ xn 2 , xn 3 ,..., x0 ]
xn 1 x0
57
f n 1 ( x) f x0 ( x x0 ) f x1 , x0 ( x x0 )( x x1 ) f x2 , x1 , x0
... ( x x0 )( x x1 )...(x xn 2 ) f xn 1 , xn 2 ,..., x1 , x0
Example 3
Fit a third-order Newtons interpolating polynomial to the four
points used to evaluate the natural logarithm of 2
i.e.
x0 = 1
f (x0) = 0
x1 = 4
f (x1) = 1.386294
x2 = 6
f (x2) = 1.791759
x3 = 5
f (x3) = 1.609438
58
Example 3 - Solution
The third-order polynomial is
f 41 ( x) b0 b1 ( x x0 ) b2 ( x x0 )( x x1 ) b3 ( x x0 )( x x1 )( x x2 )
The values of the coefficients of the polynomial are:
b0 f ( x0 ) 0
b1 f [ x1 , x0 ] 0.462098
b2 f [ x2 , x1 , x0 ] 0.051873
b2 f [ x3 , x2 , x1 , x0 ] 0.0078655
f3 (2) 0.6287686
t 9.3%
59
where
x xj
j 0 xi x j
n
Li ( x)
j i
( x x0 )( x x2 )
f ( x1 )
( x1 x0 )( x1 x2 )
( x x0 )( x x1 )
f ( x2 )
( x2 x0 )( x2 x1 )
60
Example 4:
Use a Lagrange interpolating polynomial of the first and second
order to evaluate ln2 given the following data:
x0 = 1
f (x0) = 0
x1 = 4
f (x1) = 1.386294
x2 = 6
f (x2) = 1.791759
Example 4 - Solution
Using first order Lagrange polynomial:
f1 ( x)
24
2 1
0
1.386294 0.4620981
1 4
4 1
1.386294
(4 1)(4 6)
(2 1)(2 4)
1.791759 0.5658444
(6 1are
)(6similar
4) to those of Newtons interpolation.
The results
61
Objectives
Introduction
Linear Splines
Quadratic Splines
Cubic Splines
Introduction
Higher order polynomials can lead to erroneous results
because of round off error and oscillations to be
avoided.
Lower-order polynomial fits should be used.
Alternative approach is to apply lower-order polynomials
to subsets of data points : spline functions.
The drafting technique of using a spline to draw smooth
curves through a series of points. Notice how, at the end
points, the spline straightens out This is natural spline.
62
Why Splines ?
63
1 t Order
h
Polynomial
6
Original
Functio
n
t
4 Order
h
Polynomial
8t Order
h
Polynomial
64
f(x) = 1/(1+25x2)
65
S1 ( x) x [ x1 , x2 ]
S ( x) x [ x , x ]
2
3
S ( x) 2
S n 1 ( x) x [ xn 1 , xn ]
66
Linear Splines
Simplest form of spline interpolation
Given the data ( x1 , f1 ), ( x2 , f 2 ),.....,( xn1 , f n1 ), ( xn , f n )
Consecutive data points connected through straight lines.
Each Si is a linear interpolation function constructed as:
Si ( x) ai bi ( x xi )
67
f ( x2 ) f ( x1 )
S
(
x
)
f
(
x
)
( x x1 ) x [ x1 , x2 ]
1
1
x2 x1
f ( x3 ) f ( x2 )
S
(
x
)
f
(
x
)
( x x2 ) x [ x2 , x3 ]
2
2
x3 x2
S ( x)
S ( x) f ( x ) f ( xn ) f ( xn 1 ) ( x x ) x [ x , x ]
n 1
0
n 1
n
n 1
x
n
n 1
Example 1
Given the following data, evaluate the function at x=5
using linear splines.
i
xi
fi
3.0 2.5
4.5 1.0
7.0 2.5
9.0 0.5
Example 1 - Solution
68
1.0
2.5 - 1.0
( x 4.5)
7.0 - 4.5
2.5-1.0
(5 4.5) 1.3
7.0-4.5
69
Quadratic Splines
Quadratic splines are rarely used for interpolation for
practical purposes
Ideally quadratic splines are only used to understand cubic
splines
Each Si is a second-order polynomial constructed as:
Si ( x) ai bi ( x xi ) ci ( x xi )2
70
S1 ( x) a1 b1 ( x x1 ) c1 ( x x1 ) 2
2
S 2 ( x) a2 b2 ( x x2 ) c2 ( x x2 )
S ( x)
S ( x) a b ( x x ) c ( x x ) 2
n 1
n 1
n 1
n 1
n 1
n 1
x [ x1 , x2 ]
x [ x2 , x3 ]
x [ xn 1 , xn ]
fi bi ( xi 1 xi ) ci ( xi 1 xi )2 fi 1 bi 1 ( xi 1 xi 1 ) ci 1 ( xi 1 xi 1 )2
By setting hi = xi+1 xi, the above equation simplifies to:
2
fi bi hi ci hi fi 1
71
72
Example 2
Given the following data, evaluate the function at x=5
using Quadratic splines.
i
xi
fi
3.0 2.5
4.5 1.0
7.0 2.5
9.0 0.5
Example 2 - Solution
Since there are 4 data points, 3 quadratic splines pass
through them
S1 ( x) a1 b1 ( x 3) c1 ( x 3) 2
x [3,4.5]
S 2 ( x) a2 b2 ( x 4.5) c2 ( x 4.5) 2
x [4.5,7]
S3 ( x) a3 b3 ( x 7) c3 ( x 7) 2
x [7,9]
73
xi
fi
hi
3.0 2.5
4.5 1.0
2.5
0.5
a3 f 3 2.5
f1 b1h1 c1h1 f 2
2
fi bi hi ci hi fi 1
2
f 2 b2 h2 c2 h2 f 3
2
74
bi 2ci hi bi 1
b2 2c2 h2 b3
b2 5c2 b3
0
0
2 4 c2 2
0
b1 1.0
1
1
0
0
0
0
3
b2 1.0
0
1
5
1 0 c3 0
c2 0.64
b3 2.2
c3 1.6
These equations can be solved with the results:
a1 2.5
Along with
a 2 1 .0
and
c1 0
a3 2.5
75
S1 ( x) 2.5 ( x 3)
x [3,4.5]
x [4.5,7]
x [7,9]
76
Cubic Splines
Third-order curves used to connect each pair of data points
are called cubic splines.
si ( x) ai bi ( x xi ) ci ( x xi )2 di ( x xi )3
We have n data points n-1 intervals 4n-4 unknowns
constants 4n-4 conditions are needed
The first 3 conditions are identical to those used for the
quadratic splines:
1. Spline functions must pass through all the data points
2. Function values must be equal at the interior knots
3. First derivatives at the interior knots must be equal
4. Second derivatives at the interior knots must be equal
5. Second derivatives at the end knots are zero
Or
5. First derivatives at the first and last knots are specified
77
ci 3di hi ci 1
c1 0
cn 0
fi bi hi ci hi di hi fi 1
2
(2)
bi 2ci hi 3di hi bi 1
2
78
(3)
ci 3di hi ci 1
(4)
c1 0
cn 0
(5)
(6)
(7)
bi 1 bi hi (ci ci 1 )
(8)
(9)
(2ci 1 ci )
hi 1
3
79
(10)
bi bi 1 hi 1 (ci 1 ci )
(11)
(12)
0
1
c1
h 2(h h ) h
c 3( f [ x , x ] f [ x x ])
1
1
2
2
3
2
2
1
h
2
(
h
h
)
h
n
2
n
2
n
1
n
n 1 3( f [ xn , xn 1 ] f [ xn 1 xn 2 ])
1 cn
0
80
Example 3
Given the following data, evaluate the function at x=5
using Cubic splines.
xi
fi
3.0
2.5
4.5
1.0
7.0
2.5
9.0
0.5
Example 2 - Solution
Since there are 4 data points, 3 quadratic splines pass
through them
S1 ( x) a1 b1 ( x 3) c1 ( x 3) 2 d1 ( x 3)3
x [3,4.5]
x [4.5,7]
S3 ( x) a3 b3 ( x 7) c3 ( x 7) 2 d3 ( x 7)3
x [7,9]
81
0.5
h 2(h h )
c 3( f [ x , x ] f [ x x ])
h2
1
1
2
3
2
2
1
h2
2(h2 h3 ) h3 c3 3( f [ x4 , x3 ] f [ x3 x2 ])
1 c4
0
1
c1 0
1.5 8 2.5 c 4.8
2.5 9 2 c3 4.8
1 c4 0
c1 0
c2 0.8395
c3 0.7665
c4 0
b1 1.42
b2 0.16
b3 0.022
82
bi
f i 1 f i hi
(2ci ci 1 )
hi
3
c c
di i 1 i
3hi
d1 0.187
d 2 0.214
d 3 0.128
x [3,4.5]
x [4.5,7]
x [7,9]
83
Example - Summary
Spline fits of the set of four points given in the example
(a) Linear spline,
(b) quadratic spline, and
(c) cubic spline, with a cubic
84
Objectives
Introduction
Linear regression
Polynomial regression
Multiple linear regression
General linear least squares
Nonlinear regression
Curve Fitting
Experimentation
Data available at discrete points or times
Estimates are required at points between the discrete
values
Curves are fit to data in order to estimate the
intermediate values
Two methods - depending on error in data
Interpolation
- Precise data
- Force through each data point
85
120
Temperature (deg F)
100
80
60
40
20
0
0
Time (s)
Regression
- Noisy data
- Represent trend of the data
9
f(x)
0
0
10
12
14
16
86
2.10
2.90
6.22
3.83
7.17
5.98
10.5
5.71
13.7
7.74
87
f(x)
0
0
10
12
14
16
7
Data points
y3
e3
y4
f(x)
5
e2
4
y1
Residual
e = y - (a 0 + a 1x )
y2
3
Regression Model
y = a 0 + a 1x
0
0
10
12
14
16
88
Use the curve that minimizes the residual between the data
points and the line
Model: y a0 a1 x , yi a0 a1 xi
ei yi a0 a1 xi
n
Sr e [ yi a0 a1 xi ]2
i 1
2
i
i 1
First a0
a a
WRT
i =1
2 2
i =1 a 0
i =1
a 0
2y i a 0 a1x i (1)
i =1
Finally
Second a1
n
n
na0 xi a1 yi
i 1
i 1
Sr n
yi a 0 a1x i 2
=
a1 a1 i =1
2 2
i =1 a 1
i =1
a1
2y i a 0 a1x i ( x i )
i =1
0
89
n x a n x2 a n x y
i i
i 0
i 1
i 1
i 1
i 1
Finally
na0 xi a1 yi
i 1
i 1
n x a n x2 a n x y
i i
i 0
i 1
i 1
i 1
i 1
a1
i 1
i 1
i 1
n xi yi xi yi
n
n x xi
i 1
i 1
n
2
i
a0 y a1 x
90
Example 1:
Fit a straight line to the values in the following table
x
y
2.10
2.90
6.22
3.83
7.17
5.98
10.5
5.71
13.7
7.74
i
xi
yi
xi2
xiyi
2.10
2.90
4.41
6.09
6.22
3.83
38.69
23.82
7.17
5.98
51.41
42.88
10.5
5.71
110.25
59.96
13.7
7.74
187.69
106.04
39.69
26.16
392.32
238.74
y 2.038392 0.4023190x
91
Sr ( yi yi ) 2
i 1
model
St ( y yi ) 2
i 1
92
xi
yi
( yi y )2
( yi a0 a1 xi )2
2.1
2.9
5.4382
0.0003
6.22
3.83
1.9656
0.5045
7.17
5.98
0.5595
1.1183
10.5
5.71
0.2285
0.3049
13.7
7.74
6.2901
0.0363
39.69 26.16
14.4819
1.9643
Sy
St
14.4819
1.9028
n 1
5 1
93
S y| x
Sr
1.9643
0.8092
n2
52
0.8644
St
14.4819
r 0.8644 0.9297
94
ln y ln a bx
Now its a linear relation between ln(y) and x
ln y ln a b ln x
Now its a linear relation between ln(y) and ln(x)
95
96
Polynomial Regression
Minimize the residual between the data points and the
curve -- least-squares regression
Linear
yi a0 a1 xi
Quadratic
yi a0 a1 xi a2 xi2
Cubic
yi a0 a1 xi a2 xi2 a3 xi3
General
Residual
ei yi a0 a1 xi a2 xi2 .... am xim
Sum of squared residuals
Sr e yi a0 a1 xi a x .... a x
n
i 1
2
i
2
2 i
i 1
m
m i
n
xi
in=1
x i2
i =1
n xm
i
i =1
xi
i =1
n
i =1
n
2
i
x i2
x 3i
i =1
n
i =1
n
x 3i
x i4
i =1
i =1
x im 1
x im 2
i =1
i =1
yi
x
i =1
i =1
a
0
n
m 1
x
x
y
i a1 i i
i =1
a in=1
n
m2
2
2
x i x i yi
i =1
i =1
a
n
n
2m
m
x
y
xi
i
i
i =1
i =1
n
m
i
97
Example 3
Fit a third-order polynomial to the data given in the Table
below
x 0 1.0 1.5 2.3 2.5 4.0 5.1 6.0 6.5 7.0 8.1 9.0
y 0.2 0.8 2.5 2.5 3.5 4.3 3.0 5.0 3.5 2.4 1.3 2.0
x 9.3 11.0 11.3 12.1 13.1 14.0 15.5 16.0 17.5 17.8 19.0 20.0
y -0.3 -1.3 -3.0 -4.0 -4.9 -4.0 -5.2 -3.0 -3.5 -1.6 -1.4 -0.1
Example 3 - Solution
229.6
3060.2
46342.79 a 0 1.30
24
229.6
3060.2
46342.79
752835.2 a1 316.88
12780148.0 a 2 6037.242
3060.2 46342.79 752835.2
a 0 0.35934718
a 2.3051112
1
a 2 0.35319014
a 3 0.01206020
98
Regression Equation
y = - 0.359 + 2.305x - 0.353x2 + 0.012x3
6
f(x)
-2
-4
-6
0
10
15
20
25
99
y a0 z0 a1 z1 a2 z2 am zm e
z0 , z1, , zm are m 1 basis functions
Y Z A E
Z matrix of the calculated values of
Sr yi a j z ji
i 1
j 0
100
101
102
Objectives
Introduction
Taylor Series
Forward difference method
Backward difference method
Central difference method
Introduction
Calculus is the mathematics of change. Because engineers
must continuously deal with systems and processes that
change, calculus is an essential tool of engineering.
Standing in the heart of calculus are the mathematical
concepts of differentiation and integration:
y f ( xi x) f ( xi )
x
x
dy
f ( xi x) f ( xi )
x lim 0
dx
x
b
I f ( x)dx
a
103
104
y f ( xi x) f ( xi )
x
x
dy
f ( xi x) f ( xi )
lim
dx x0
x
105
Integration
106
107
f '' xi
xi 1 xi 2
f xi 1 f xi f xi xi 1 xi
2!
f 3 xi
f n xi
3
xi 1 xi ...
xi 1 xi n Rn
3!
n!
'
f n 1
xi 1 xi n1
Rn
n 1!
108
f xi 1 f xi f ' xi xi 1 xi
f xi
xi 1 xi 2
2!
''
Finally
f '' xi
'
xi 1 xi 2
f xi 1 f xi f xi xi 1 xi
2!
f 3 xi
f n xi
3
xi 1 xi ...
xi 1 xi n Rn
3!
n!
where
f n 1
xi 1 xi n1
Rn
n 1!
109
f ' ( xi )
f ( xi 1 ) f ( xi ) f ' ' ( xi )
h O(h 2 )
h
2
110
(2)
f ' ' ( xi )
f ( xi 2 ) 2 f ( xi 1 ) f ( xi )
O ( h)
h2
(3)
f ' ( xi )
f ( xi 1 ) f ( xi ) f ( xi 2 ) 2 f ( xi 1 ) f ( xi )
h O(h 2 )
2
h
2h
f ' ( xi )
f ( xi 2 ) 4 f ( xi 1 ) 3 f ( xi )
O(h 2 )
2h
111
The expression of the second derivative is then:
f ( xi 3 ) 4 f ( xi 2 ) 5 f ( xi 1 ) 2 f ( xi )
f ' ' ( xi )
O(h 2 )
2
h
Backward Difference Formulas- 1st derivative
Using backward difference in the Taylor series expansion,
f ' ' ( xi ) 2
h O( h3 )
2
And given that f (x) can be approximated by:
f ( xi 1 ) f ( xi ) f ' ( xi )h
f ' ' ( xi )
f ( xi ) 2 f ( xi 1 ) f ( xi 2 )
O ( h)
2
h
f ' ( xi )
3 f ( xi ) 4 f ( xi 1 ) f ( xi 2 )
O( h 2 )
2h
112
f ( xi 1 ) f ( xi ) f ' ( xi )h
f ' ' ( xi ) 2
h O( h3 )
2
f ( xi 1 ) f ( xi ) f ' ( xi )h
f ' ' ( xi ) 2
h O( h3 )
2
(4)
(5)
f ' ( xi )
f ( xi 1 ) f ( xi 1 )
O( h 2 )
2h
(6)
f ( xi 2 ) f ( xi 2 ) 4 f ' ( xi )h
(7)
f ' ( xi )
f ( xi 2 ) 8 f ( xi 1 ) 8 f ( xi 1 ) f ( xi 2 )
O( h 4 )
12h
f ( xi 1 ) f ( xi ) f ' ( xi )h
f ( xi 1 ) f ( xi ) f ' ( xi )h
(8)
(9)
114
f ' ' ( xi )
f ( xi 1 ) 2 f ( xi ) f ( xi 1 )
O( h 2 )
2
h
8 f ' ' ( xi ) 2 32 f ( 4 ) ( xi ) 4
f ( xi 2 ) f ( xi 2 ) 2 f ( xi )
h
h O( h 6 )
(11)
2!
4!
Multiply equation (10) by 16, subtract (11) from it, and
solve for f(x)
f ( xi 2 ) 16 f ( xi 1 ) 30 f ( xi ) 16 f ( xi 1 ) f ( xi 2 )
f ' ' ( xi )
O( h 4 )
2
12h
Error Analysis
Generally, if numerical differentiation is performed, only
about half the accuracy of which the computer is capable is
obtained unless we are fortunate to find an optimal step
size.
115
The total error has part due to round-off error plus a part
due to truncation error.
Total Numerical Error
Total numerical error = truncation error + round-off error.
Example 1
Estimate the first and second derivatives of:
116
xi 0.5
f ( xi ) 0.925
xi 1 0.75
f ( xi 1 ) 0.636328
xi 2 1
f ( xi 2 ) 0.2
First derivative:
f ( xi 2 ) 4 f ( xi 1 ) 3 f ( xi )
2h
f (1) 4 f (0.75) 3 f (0.5)
f ' (0.5)
0.859375
2(0.25)
f ' ( xi )
t = 5.82%
True value=-0.9125
117
xi 0.5
f ( xi ) 0.925
xi 1 0.75
f ( xi 1 ) 0.636328
xi 2 1
f ( xi 2 ) 0.2
xi 3 1.25
f ( xi 3 ) 1.94336
Second derivative:
f ( xi 3 ) 4 f ( xi 2 ) 5 f ( xi 1 ) 2 f ( xi )
h2
(1.94336) 4(0.2) 5(0.636328) 2(0.925)
f ' ' (0.5)
39.6
2
(0.25)
f ' ' ( xi )
xi 2 0
f ( xi 2 ) 1.2
xi 1 0.25
f ( xi 1 ) 1.103516
xi 1 0.75
f ( xi 1 ) 0.636328
xi 2 1
f ( xi 2 ) 0.2
118
First derivative:
f ( xi 2 ) 8 f ( xi 1 ) 8 f ( xi 1 ) f ( xi 2 )
12h
(0.2) 8(0.636328) 8(1.103516) (1.2)
f ' ( xi )
12(0.25)
f ' ( xi ) 0.9125
f ' ( xi )
t = 0%.
True value=-0.9125
xi 1 0.25
f ( xi 1 ) 1.103516
xi 0.5
f ( xi ) 0.925
119
First derivative :
3 f ( xi ) 4 f ( xi 1 ) f ( xi 2 )
2h
3(0.925) 4(1.103516) (1.2)
f ' ( xi )
0.878125
2(0.25)
f ' ( xi )
t = 3.77%
True value=-0.9125
120
Objectives
Introduction
Trapezoidal Rule
Multiple-Application Trapezoidal Rule
Simpsons 1/3 Rule
Multiple-Application Simpsons 1/3 Rule
Simpsons 3/8 Rule
Integration with unequal segments
Gauss Quadrature
Integration Graphical representation
121
f ( x)dx
a
122
I a f ( x)dx a f n ( x)dx
b
f n ( x) a0 a1 x a2 x 2 ... an 1 x n 1 an x n
Closed and open forms
Closed: data points at the beginning and end of the
limits of integration are known
Open: integration limits that extend beyond the range
of data
123
Trapezoidal Rule
The Trapezoidal rule is the first of the Newton-Cotes
closed integration formulas, corresponding to the case
where the polynomial is first order i.e. n = 1
I a f ( x)dx a f1 ( x)dx
b
I a f (a)
( x a) dx
ba
124
I (b a)
f (a) f (b)
Trapezoidal rule
2
125
Ea
1
(b a)3 f ' '
12
Example 1
Use Trapezoidal Rule to integrate numerically the following
function:
f (0.8) 0.232
Evaluate the integral
I (0.8 0)
0.2 0.232
0.1728
2
0
f ' ' ( x)
60
0.8
0.8 0
Ea
1
1
f ' ' ( x)(b a)3 (60)(0.8 0)3 2.56
12
12
126
Ea = 2.56
Discrepancy between Et and Ea due to the fact that f (x) is
not an accurate approximation of f ( ) for an interval of
this size.
x2
xn
n 1
127
f ( x0 ) f ( x1 )
f ( x1 ) f ( x2 )
f ( xn 1 ) f ( xn )
h
... h
2
2
2
By grouping terms, we have
I h
n 1
h
I
f ( x0 ) 2 f ( xi ) f ( xn )
2
i 1
128
i 1
f ' ' i 1
n
Approximate error estimate for multiple-application of
trapezoidal rule is then:
(b a)3
Ea
f ''
2
12n
As you double the number of segments error is quartered
Example 2
Apply two segments in the trapezoidal rule to estimate the
integral of:
from a = 0 to b = 0.8
129
Example 2 - Solution
We have n = 2
f (0) 0.2
0.8 0
0.4
2
f (0.4) 2.456
f (0.8) 0.232
I 0.8
(0.8 0)3
Ea
(60) 0.64
12(2) 2
I a f ( x)dx a f 2 ( x)dx
b
( x x0 )( x x1 )
f ( x2 ) dx
( x2 x0 )( x2 x1 )
130
ba
2
( 4)
( ) f
( 4)
( 4)
f
( x)dx
ba
Example 3
Evaluate the integral of:
131
f ( 4 ) ( x) 21600 48000 x
0.8
( 4)
f
( x)dx
( 4)
0
f ( x)
2400
0.8 0
(b a)5 ( 4 )
(0.8)5
Ea
f ( x)
(2400) 0.2730667
2880
2880
I f ( x0 ) 4 f ( xi ) 2 f ( xi ) f ( xn )
3
i 1, 3, 5,...
j 2 , 4 , 6 ,...
(b a)5 ( 4 )
Ea
f
4
180n
Example 4:
Use n = 4 to evaluate the integral of:
132
Example 4 Solution
The integral using composite simpsons 1/3 rule
h = (0.8-0)/4 = 0.2
f(0)=0.2 f(0.2)=1.288
f(0.8)=0.232
f(0.4)=2.456
f(0.6)=3.464
0.2
0.2 4(1.288) 2.456 0.2 2.456 4(3.464) 0.232
3
3
1.623466
133
(b a)5 ( 4 )
Et
f ( )
6480
134
Example 5
1. Use Simpsons 3/8 rule to integrate:
135
h = (0.8-0)/3 = 0.2667
f(0) = 0.2
f(0.2667) = 1.432724
f(0.5333) = 3.487177
f(0.8)=0.232
3(0.2667)
0.2 3(1.432724 3.487177) 0.232 1.51970
8
f(0.16) = 1.296919,
f(0.32) = 1.743393
f(0.8) = 0.232
136
137
Gauss Quadrature
138
I c0 f (a) c1 f (b)
The trapezoidal rule yields exact results when the function
being integrated is a constant or a straight line, such as y=1
and y=x:
139
c0 c1
(ba ) / 2
1 dx
(b a ) / 2
ba
b a (ba ) / 2
c0
c1
x dx
2
2
(b a ) / 2
c0 c1 b a
c0
ba
ba
c1
0
2
2
c0 c1
I
ba
2
ba
ba
f (a)
f (b)
2
2
Solve simultaneously
Trapezoidal rule
140
141
c0 f ( x0 ) c1 f ( x1 ) 1 dx 2
1
1
c0 f ( x0 ) c1 f ( x1 ) x dx 0
1
1
c0 f ( x0 ) c1 f ( x1 ) x 2 dx
1
2
3
c0 f ( x0 ) c1 f ( x1 ) x 3 dx 0
Solved simultaneously
1
1
, x1
3
3
1
1
I f f
3
3
c0 c1 1, x0
Yields an integral
estimate that is third
order accurate
142
Notice that the integration limits are from -1 to 1. This was done
for simplicity and make the formulation as general as possible.
x a0 xd a1
If x=a and x=b correspond to xd=-1 and xd=1 respectively
a a0 a1
b a0 a1
==
ba
2
ba
a1
2
a0
This yields to
(b a) xd (b a)
x
2
dx
(b a)
dxd
2
Example 6
Use two-point Gauss quadrature to integrate:
143
Example 6 - Solution
First, perform a variable change
x 0.4 xd 0.4
dx 0.4dxd
1
1
I f f 0.516741 1.305837 1.822578
3
3
t = 11.1%
144
22 n 3 (n 1)!
Et
f ( 2 n 2 ) ( )
3
(2n 3)(2n 2)!
4
145
146
147
dv F
dt m
q k '
dT
dx
2T
Lapalce equation (steady state) x
Heat conduction
2T
y
T
2T
k' 2
t
x
etc.
One independent variable Ordinary Differential
Equation (ODE)
Two or more independent variables Partial Differential
Equation (PDE)
Order of a differential equation is determined by the
highest derivative.
148
Eulers Method
Solve ordinary differential equations of the form
dy
f ( x, y )
dx
y( xi ) yi
149
yi 1 yi h
yi 1 yi f ( xi , yi ) h
150
151
f ' ( xi , yi ) 2
f ( n 1) ( xi , yi ) n
yi 1 yi f ( xi , yi )h
h ...
h O(h n 1 )
(3)
2!
n!
Et
f ' ( xi , yi )
2!
h 2 ...
f ( n 1) ( xi , yi )
n!
h n O(h n 1 )
Example 1:
1. Use Eulers method to integrate numerically the ODE:
dy
2 x3 12 x 2 20 x 8.5
dx
152
h=0.5,
y(0)=1
yEuler
0.0
1.000
0.5
5.250
1.0
5.875
1.5
5.125
2.0
4.500
2.5
4.750
3.0
5.875
3.5
7.125
4.0
7.000
154
f ' ( xi , yi ) 6 x 2 24 x 20
f ' (0,1) 20
f '' ( xi , yi ) 12 x 24
f '' (0,1) 24
f ( 3) ( xi , yi ) 12
f ( 3) (0,1) 12
Et
20
24
12
(0.5) 2 (0.5)3
(0.5) 4 2.03125
2
6
24
155
yEuler
Et
156
157
Objectives
Introduction
Runge-Kutta Methods
Second-order Runge-Kutta
Heun Method
Midpoint Method
Ralstons Method
Fourth-order Runge-Kutta
System of ODE
Introduction
A fundamental source of error in Eulers method is that the
derivative at the beginning of the interval is assumed to
apply across the entire interval.
Improving the estimate of the slope will improve the
solution.
Runge-Kutta Methods
158
yi 1 yi ( xi , yi , h) h
where ( xi , yi , h)
slope over the interval
a1k1 a2 k 2 a3 k3 ... an k n
where a1, a2, a3,, an are constants and k1, k2, k3,, kn are
k1 f ( xi , yi )
k2 f ( xi p1h, yi q11k1h)
k3 f ( xi p2 h, yi q21k1h q22 k2 h)
.
.
.
kn f ( xi pn 1h, yi qn 1,1k1h qn 1, 2 k2 h ... qn 1,n 1kn 1h)
159
k1 f ( xi , yi )
k2 f ( xi p1h, yi q11k1h)
Evaluate values for a1, a2, p1 and q11 by setting equation (i)
equal to a Taylor series expansion to the second-order term
(see Box 25.1 p.703 for details).
Three equations are derived to solve four unknown
constants
a1 a2 1
a2 p1 1 / 2
a2 q11 1 / 2
160
a1 1 a2
1
p1 q11
2a 2
There are an infinite number of second-order RK methods
Because we can choose an infinite number of values for a2,
there are an infinite number of second-order RK methods.
Every version would yield exactly the same results if the
solution to ODE were quadratic, linear, or a constant.
However, they yield different results if the solution is more
complicated (typically the case).
Three of the most commonly used RK second-order
methods are:
Heuns Method with a Single Corrector (a2=1/2)
The Midpoint Method (a2=1)
Raltsons Method (a2=2/3)
Heun Method with a Single Corrector
a2 is set to a2=1/2
a1 1 a2 1 / 2
p1 q11 1 / 2a2
161
k1 f ( xi , yi )
k2 f ( xi h, yi k1h)
a1 0
p1 q11
1
2
k1 f ( xi , yi )
1
1
k2 f ( xi h, yi k1h)
2
2
162
Ralstons Method
a2 is set to a2=2/3
a1 1 / 3
p1 q11 3 / 4
Substituting into equation (i)
1
2
yi 1 yi ( k1 k2 ) h
3
3
Where
k1 f ( xi , yi )
3
3
k2 f ( xi h, yi k1h)
4
4
163
Fourth-order Runge-Kutta
This is the most popular of the RK methods
1
yi 1 yi (k1 2k2 2k3 k4 ) h
6
Where
k1 f ( xi , yi )
1
1
k2 f ( xi h, yi k1h)
2
2
1
1
k3 f ( xi h, yi k2 h)
2
2
k4 f ( xi h, yi k3h)
164
Example 1
Integrate using fourth-order Runge-Kutta method:
dy
4e0.8 x 0.5 y
dx
Example 1 - Solution
Compute the slope at the beginning of the interval:
165
Use the this slope to compute the slope at the end of the
interval:
y(0.5) 2 3.446785(0.5) 3.723392
1
y (0.5) 2 (3 2 3.510611 2 3.446785 4.105603) 0.5
6
3.751669
System of Equations
Many practical problems in engineering require the
solution of a system of simultaneous ODE rather than a
single equation
dy1
dx f1 ( x, y1 , y2 ,..., yn )
dy2 f ( x, y , y ,..., y )
2
1
2
n
dx
.
.
dy
n f n ( x, y1 , y2 ,..., yn )
dx
166
167
Example 2
Solve the following set of differential equations using the 4th
order RK method, assuming that at x = 0, y1 = 4 and y2 = 6.
Integrate to x = 2 with a step size of 0.5
dy1
dx 0.5 y
dy1
dx 0.5 y f1 ( x, y1 , y2 )
Example 2 - Solution
1. Compute the slopes for all variables at the beginning of the
interval (set of k1s).
k1,1 f1 (0,4,6) 0.5(4) 2
h
0.5
y1 (0.25) y1 (0) k2,1 4 (1.75)( ) 3.5625
2
2
h
0.5
y2 (0.25) y2 (0) k2, 2 6 (1.715)( ) 6.42875
2
2
169
170
y1
y2
0.0
0.5
3.115234
6.857670
1.0
2.426171
7.632106
1.5
1.889523
8.326886
2.0
1.471577
8.946865
171
Objectives
Introduction
Shooting Method
Finite Difference Method
Introduction
An ODE is accompanied by auxiliary conditions. These
conditions are used to evaluate the integral that result
during the solution of the equation. An nth order equation
requires n conditions.
If all conditions are specified at the same value of the
independent variable, then we have an initial-value
problem.
If the conditions are specified at different values of the
independent variable, usually at extreme points or
boundaries of a system, then we have a boundary-value
problem.
Initial-value versus boundary-value problems
172
Determination of eigenvalues: Special class of boundaryvalue problems that are common in engineering involving
vibrations, elasticity, and other oscillating systems.
173
174
L 10 m
h 0.01m 2
T (0) T1 40
T ( L) T2 200
Analytical solution
T 73.4523e0.1x 53.4523e0.1x 20
175
176
T(10) = 168.3797
Second shot
z(0) = 20
T(10) = 285.8980
T(10) = 200
177
200 f ( z0 )
g ( z0 ) f ( z0 ) 200
178
d 2T Ti 1 2Ti Ti 1
2
dx
x 2
Ti 1 2Ti Ti 1
h(Ti Ta ) 0
x 2
Ti 1 (2 hx 2 )Ti Ti 1 hx 2Ta
Finite differences equation applies for each of the interior
nodes. The first and last interior nodes, Ti-1 and Ti+1,
respectively, are specified by the boundary conditions.
Thus, a linear equation transformed into a set of
simultaneous algebraic equations.
It will be tridiagonal which can be solved efficiently.
If we use a segment length x = 2 m (4 interior nodes)
Ti 1 2.04Ti Ti 1 0.8
Thus, a set of simultaneous algebraic equations.
179
0
0 T1 40.8
2.04 1
1 2.04 1
0 T2 0.8
1 2.04 1 T3 0.8
0
0
1 2.04 T4 200.8
0
T T 65.9698
180