Professional Documents
Culture Documents
CFD I
Hochschule Magdeburg-Stendal
Fachbereich Wasser und Kreislaufwirtschaft
Universidad de A Corua
Escuela Tcnica Superior de Ingenieros de Caminos, Canales y Puertos
CFD I
Computational Fluid Dynamics I
0.
1.
4.
1.
2.
Saint-Venant equations.
3.
Introduction to CFD
4.
Mathematical preliminaries
CW3 (2h)
1. MATLAB
CW4 (6h)
1. Navier-Stokes
2. Potential, stream function, stokes flow
4. Convection-diffusion eq
2.
3.
4. SMS//RMA2
CFD I
Computational Fluid Dynamics I
What is MATLAB?
Mathematical tool:
Diagram of main
features and
capabilities of MATLAB
MATrix LABoratory
CFD I
Computational Fluid Dynamics I
CFD I
Computational Fluid Dynamics I
CFD I
Computational Fluid Dynamics I
CFD I
Computational Fluid Dynamics I
CFD I
Computational Fluid Dynamics I
+ - * / ^
>> 234*485
ans =
113490
>> 5^7
ans =
78125
Several operations PRIORITY RULES: - First inside parenthesis and after outside
1
7
0.25 3(1 3)
212 +
>> (2^12+1/7)/(0.25-3*(1-3^0.5))
ans = 1.6745e+03
- 1st exponentiation,
2nd multiplication & division
3rd addition & substration
CFD I
Computational Fluid Dynamics I
F1
CFD I
Computational Fluid Dynamics I
>> tan(pi/3)
ans =
1.7321
Use of semicolon ( ; )
>> x=tan(pi/3);
>>
Variable value
>> x
x=
1.7321
CFD I
Computational Fluid Dynamics I
>> x
x=
1.7321
>> format long
>> x
x=
1.732050807568877
>> format rat
>> x
x=
1351/780
>> format short e
>> x
x=
1.7321e+00
>> format short
>> x
x=
1.7321
CFD I
Computational Fluid Dynamics I
CFD I
Computational Fluid Dynamics I
Creating an array:
Between square braquets [ ]
Rows are separated by ;
Columns are separated by , or spaces
>> a=[2 3 0 1]
a=
2 3 0 1
>> b=[2;3;0;1]
b=
2
3
0
1
CFD I
Computational Fluid Dynamics I
Elementary matrices:
>> eye (5)
1
0
0
0
0
0
1
0
0
0
0
0
1
0
0
>> ones(4,3)
1
1
1
1
1
1
1
1
1
1
1
1
0
0
0
0
0
0
0
1
0
>> logspace
Logspace(X1, X2, N)
generates generates a
row vector of N
logarithmically equally
spaced points between
decades 10^X1 and
10^X2.
0
0
0
0
1
0.9058 0.6324
0.1270 0.0975
0.9134 0.2785
9 10
>> x = 0:2:10
x= X1: E : X2 generates a row vector of points
between X1 and X2 which are spaced E
0
8 10
>> meshgrid(a,b)
or meshgrid (a,b,c)
Rectangular grid in 2-D
and 3D space
Replicates vectors a, b &c
to produce a full grid.
CFD I
Computational Fluid Dynamics I
Operations
Matrix addition:
>> A+E
ans =
0.5469
2.9575
3.9649
5.1576
-0.0294
1.9572
0.4854
0.8003
Matrices definition:
3.1419
7.4218
6.9157
10.7922
2.9595
2.6557
3.0357
6.8491
>> A+D
Error using +
Matrix dimensions must agree.
Multiplication by a scalar
>> 4*D
ans =
8 -4 12 0
0 0 4 20
>> A
A=
0
2
3
5
-1 3 2
1 7 2
0 6 3
0 10 6
0.1419
0.4218
0.9157
0.7922
0.9595
0.6557
0.0357
0.8491
CFD I
Computational Fluid Dynamics I
Matrix multiplication: *
Matrices definition:
0.1419
0.4218
0.9157
0.7922
Operations
>> D*E
ans =
3.0309 2.4401 2.6092 1.3704
1.7530 4.4868 4.8768 4.2814
0.9595
0.6557
0.0357
0.8491
>> E*D
Error using *
Inner matrix dimensions must agree.
CFD I
Computational Fluid Dynamics I
Transposition of a matrix: DT
Matrix definition:
D=
2 -1 3 0
0 0 1 5
Notice than for a complex number
array D is the conjugate
inverse matrix
>> D
ans =
2
-1
3
0
0
0
1
5
>> D.*F
ans =
18.6799 -7.5774 11.7668
0
0
0
6.5548 35.3023
CFD I
Computational Fluid Dynamics I
B = A*A*A*A
C (i,j) = A (i,j) ^4
>> B = F./D
>> F./D
ans =
4.6700 -7.5774 1.3074
Inf
Inf
Inf 6.5548 1.4121
Warning: Divide by zero Not an error but Inf (infinity)
Matrix definition:
D=
2 -1 3 0
0 0 1 5
F=
9.3399 7.5774 3.9223 1.7119
6.7874 7.4313 6.5548 7.0605
CFD I
Computational Fluid Dynamics I
>> exp(D)
ans =
7.3891 0.3679 20.0855 1.0000
1.0000 1.0000 2.7183 148.4132
CFD I
Computational Fluid Dynamics I
EXERCISE
Test than
Create a vector n containing the following terms
CFD I
Computational Fluid Dynamics I
A(i, j:k)
A (i,:)
A (:,j)
>> A(2,4)
ans = 2
>> A(2,1:3)
ans = 2 1
>> A(2:4,3)
ans =
7
6
10
>> A(4,:)
ans = 5
0 10
Matrix definition
>> A
A=
0 -1 3 2
2 1 7 2
3 0 6 3
5 0 10 6
CFD I
Computational Fluid Dynamics I
row addition
column addition
Row/column deletion:
equal to empty matrix: [ ]
(artefact)
>> G=[A;u]
G=
0 -1 3
2 1 7
3 0 6
5 0 10
3 4 1
2
2
3
6
5
>> G=A;
>> G(3,:)=[]
G=
0 -1 3 2
2 1 7 2
5 0 10 6
>> G(:,[1 3])=[]
G=
-1 2
1 2
0 3
0 6
CFD I
Computational Fluid Dynamics I
>> G=zeros(6,6)
G=
0 0 0 0
0 0 0 0
0 0 0 0
0 0 0 0
0 0 0 0
0 0 0 0
>> A=[2 6;3 9];
>> B=[1 2;3 4];
>> C=[-5 5;5 3];
>> G(1:2,1:2)=A;
>> G(3:4,3:4)=B;
>> G(5:6,5:6)=C;
0
0
0
0
0
0
0
0
0
0
0
0
B
>> G(1:4,1:4)
C
>>H=G
>> H(5,5)=4
D
>> G([1 3 6],[2 5])