Professional Documents
Culture Documents
EngAn3 CFD 2013 14 Lect - 3
EngAn3 CFD 2013 14 Lect - 3
Engineering Analysis 3
2013-2014 / 2nd semester
Lecture 3
2
Dr Edmondo Minisci EngAn3-CFD
Class exercise
dT
For T ( x) Sin(x / 2) , obtain (x) at x=0.5 with x 0.1 using
dx
dT ( x) T ( xi 1 ) T ( xi )
1. = 1.0191e+00 Err = 8.2486e-02
dx x
dT ( x) T ( xi 1 ) T ( xi 1 )
2. = 1.1062e+00 Err = 4.1073e-03
dx 2x
dT ( x) T ( xi 2 ) 8T ( xi 1 ) 8T ( xi 1 ) T ( xi 2 )
3. = 1.1107e+00
dx 12x
Err = 2.0234e-05
Cos x / 2 / 2
dT ( x)
= 1.1107e+00
dx
3
Dr Edmondo Minisci EngAn3-CFD
f f ( xi x ) f ( xi )
T .E .
x i x
4
Dr Edmondo Minisci EngAn3-CFD
Does the finite difference equation approach the partial differential equation in
the limit of zero Δx (or Δt)?
5
Dr Edmondo Minisci EngAn3-CFD
Class exercise
1. Using the central difference, derive finite differences for the following derivatives
d and
d xi
1
x 1
where x
i
1 x xi x
dx x dx x 1
2 2 i
1
2
1 i 2
i 2
2
6
Dr Edmondo Minisci EngAn3-CFD
2x 3
3!
from which
f ( x x) f ( x x) x 2 ( 3)
f ' ( x) f ( x) ...
2x 3!
f ( x x) f ( x x)
2x
f ' ( x) O x 2
f ( xi 1 ) f ( xi 1 ) f second order
central difference
2x x i
7
Dr Edmondo Minisci EngAn3-CFD
Class exercise
1. Using the central difference, derive finite differences for the following derivatives
d and
d xi
1
x 1
where x
i
1 x xi x
dx x dx x 1
2 2 i
1
2
1 i 2
i 2
2
d i 1 i i 1 i d i i 1 i i 1
dx x 1
xi 1 xi x dx x xi xi 1 x
i 1
2 i
2
8
Dr Edmondo Minisci EngAn3-CFD
Class exercise
d d
d i 1 i
d 2 d d dx xi1 / 2 dx xi1 / 2
2 dx x x
dx xi dx dx xi xi xi 1/ 2 xi 1/ 2 i
1
d i i 1
2
d 2 2
x x 2 i i 1
i 1
dx 2 x x 2
xi
9
Dr Edmondo Minisci EngAn3-CFD
Class exercise:
The three point asymmetric formula
Class exercise:
The three point asymmetric formula
( xi ) ( xi )
x 2 2 x 3 3
( xi 1 ) ( xi ) x ( xi ) ( xi ) ( xi ) ...
x 2 x 2
6 x 3
4x
2 2
8x 3 3
( xi 2 ) ( xi ) 2x ( xi ) ( xi ) ( xi ) ..
x 2 x 2
6 x 3
Class exercise:
The three point asymmetric formula
a ( xi ) a ( xi )
x 2 2
b ( xi 1 ) b ( xi ) bx ( xi ) b ( xi )
x 2 x 2
x 3 3
b ( xi ) ...
6 x 3
4x 2 2
c ( xi 2 ) c ( xi ) c 2x ( xi ) c ( xi )
x 2 x 2
8x 3 3
c ( xi ) ...
6 x 3
Class exercise:
The three point asymmetric formula
a ( xi ) b ( xi 1 ) c ( xi 2 ) ( a b c ) ( xi )
(bx c 2x ) ( xi )
x
bx 2 c ( 2x ) 2 2
2
( xi )
x
2
2
bx 3 c ( 2x ) 3 3
6
x 3 ( xi ) ...
6
If we want
( xi ) a( xi ) b( xi 1 ) c( xi 2 ) (x m )
x
then
13
Dr Edmondo Minisci EngAn3-CFD
Class exercise:
The three point asymmetric formula
3
a
a b c 0 2x
b 2c x 1
2
b
b x
4c
0 1
2 2 c
2x
3 1
( xi ) 2 ( xi 1 ) ( xi 2 )
2 2 x 2
3
( xi ) ( xi ) ...
x x 3 x 3
3 1
( xi ) 2( xi 1 ) ( xi 2 )
2 2
( xi ) (x 2 )
x x
14
Dr Edmondo Minisci EngAn3-CFD
before solving any partial differential equation, boundary conditions and/or initial
conditions have to be prescribed. These provide values of the unknown function at
some initial position and time (usually the boundary of the domain)
xL T ( xi ) xR
Dirichlet boundary conditions: some values of the function are known at the edges
T ( xL ) TL T ( xL ) TR
Neumann boundary conditions: values of the gradient (flux) are known at the edge
dT dT
( xL ) dT
( xR )
dT
dx dx L dx dx R
Mixed boundary conditions
dT dT
T ( xL ) TL ( xR )
dx dx R
15
Dr Edmondo Minisci EngAn3-CFD
for a 1-dimensional conduction the PDE describing temperature within the domain is
2T ph
T TLS
x 2
Ak
discretise the second derivative involved using the second central finite difference
f ( xi 1 ) 2 f ( xi ) f ( xi 1 ) 2 f
x 2
x 2
to get
i
Ti 1 2Ti Ti 1 ph
(Ti TLS )
x 2
Ak
16
Dr Edmondo Minisci EngAn3-CFD
For
T2 2T1 T0
i 1
ph
(T1 TLS )
x 2
Ak
T3 2T2 T1
ph
(T2 TLS ) i2
x 2
Ak
T4 2T3 T2
ph
(T3 TLS ) i 3
x 2
Ak
17
Dr Edmondo Minisci EngAn3-CFD
For
2 x
2 ph
Ak
T1 T2 x
2 ph
Ak
TLS T0 i 1
ph
i2
2 ph
T1 2 x 2 T2 T3 x TLS
Ak Ak
ph 2 ph
T2 2 x 2
T3 x
Ak Ak
TLS T4
i 3
18
Dr Edmondo Minisci EngAn3-CFD
1 TLS T0
2
2 1
2 0 T
1 2 2 1 T 2T
2
LS
0 1 2 T3 TLS T4
2
2
ph
M Y B x
2
Ak
2
3-diagonal Matrix 19
Dr Edmondo Minisci EngAn3-CFD
( x x4 ) Q4
x
dT Ti Ti 1
use first order difference Q Ak Ak
to discretise the flux dx x
T3 T4
replace equation at Ak Q 4
the specified positions x
20
Dr Edmondo Minisci EngAn3-CFD
2
2
1 0 0 T1 TLS T0
2
1 0
T 2
2 1
2
2 TLS
T3
2T
0 1 2 1
2
LS
0 T x
0 1 1 4 Ak Q4
Is the use of first order difference methodologically correct?
21
Dr Edmondo Minisci EngAn3-CFD
Loosely based on material for “Introduction to Matlab”, Luke Dickens, Imperial College London
22
Dr Edmondo Minisci EngAn3-CFD
All or part of a MATLAB session (commands and output) can be recorded in text
format, with the diary command.
To do so type what follows at the beginning of the session you wish to record:
>> diary <filename>
23
Dr Edmondo Minisci EngAn3-CFD
The commands save and load can be used to save and load variables in files called
a Mat-files. Mat-files are binary format and always have the .mat extension.
Sequences of commands can be grouped in a file, and call be called from within
MATLAB. Called m-files, their filename extension must be “.m”.
There are two types:
Script files
A sequence of MATLAB commands that are executed (in order) once the script is
called. E.g., for the script file compute.m , executing the command compute will
cause the statements in that file to be executed.
Function files
Allow user's to define commands with input and/or output. These have the same
status as other MATLAB commands.
25
Dr Edmondo Minisci EngAn3-CFD
Flow control can be used at the command prompt, but is particularly useful in m-
files.
26