Professional Documents
Culture Documents
Dr. Trani
Civil and Environmental Engineering
Virginia Polytechnic Institute and State University
1 of 53
Spring 2001
Purpose of this Section
2 of 53
Let
434
A = 468
366
and
35
b = 22
40
A = [4 3 4; 4 6 8; 3 6 6];
b = [35 22 40]';
y = A*b;
Results in column vector y,
y=
366
592
477
3 of 53
Ax = b
4 of 53
x1
x = x2
x3
and
35
b = 22
40
5 of 53
6 of 53
7 of 53
8 of 53
Array Operators
Operation
MATLAB Operators
Array multiplication
.*
Array power
.^
.\
./
Matrix multiplication
Matrix power
Matrix division
9 of 53
10 of 53
11 of 53
12 of 53
13 of 53
Comparison of Results
The following table summarizes the array manipulation
results
CPU Timea
(seconds)
Procedure
Ratiob
Standard for-loop
2.43610
Array
Pre allocation
0.12167
20
Vectorization
0.00364
669
14 of 53
Graphs in MATLAB
There are many ways to build plots in MATLAB. Two of
the most popular procedures are:
1) Using built-in MATLAB two and three dimensional
graphing commands
2) Use the MATLAB Handle Graphics (object-oriented)
procedures to modify properties of every object of a
graph
Handle Graphics is a fairly advanced topic that is also
used to create Graphic User Interfaces (GUI) in
MATLAB. For now, we turn our attention to the first
procedure.
15 of 53
16 of 53
% plot command
% builds the x label
% builds the y label
% adds a title
% adds hor. and vert.
% grids
17 of 53
bar plot
fplot
semilog plots
loglog
logarithmic plot
polar
plotyy
errorbar
hist
histogram plot
18 of 53
More 2D Plots
stem
stairs
comet
contour
quiver
19 of 53
10 -2
10 -4
10 -6
10 -8
10 -10
10 -12
0
0.5
1.5
2.5
3.5
4.5
20 of 53
10 -1 -3
10
10 -2
10 -1
10 0
21 of 53
-2
-1
22 of 53
23 of 53
0.5
-0.5
-1
-1.5
-2.5
-2
-1.5
-1
-0.5
0.5
1.5
2.5
24 of 53
0.5
120
60
0.375
0.25
150
30
0.125
180
210
330
240
300
270
25 of 53
0.5
1.5
2.5
3.5
26 of 53
250
200
150
100
50
0
-4
-3
-2
-1
27 of 53
-0.5
-2
-1.5
-1
-0.5
0.5
1.5
-1
28 of 53
29 of 53
MD11
A330
4%
A310
2%
3%
2% 1%
B747
19%
B777
14%
55%
B767
30 of 53
Quiver Plot
The quiver plot is good to represent vector fields.
In the example below a quiver plot shows the gradient of
a function called peaks
t=-3:.1:3;
[x,y]=meshgrid(t,t);
z= 3*(1-x).^2.*exp(-(x.^2) - (y+1).^2) ...
- 10*(x/5 - x.^3 - y.^5).*exp(-x.^2-y.^2) ...
- 1/3*exp(-(x+1).^2 - y.^2);
[dx,dy]=gradient(z,.2,.2);
quiver(x,y,dx,dy,3)
Note: peaks is a built-in MATLAB function
31 of 53
-1
-2
-3
-4
-4
-3
-2
-1
32 of 53
8
6
4
2
0
-2
-4
-6
3
2
2
0
1
0
-1
-1
-2
y
-3
-2
-3
33 of 53
34 of 53
-1
-2
-3
-3
-2
-1
35 of 53
36 of 53
Aircraft Tracks
Miami Intl. Airport
Gulf of Mxico
-84
-83
-82
-81
-80
-79
-78
-77
Longitude (deg.)
37 of 53
-81
-80.8
-80.6
-80.4
-80.2
-80
-79.8
Longitude (deg.)
38 of 53
subplot(2,1,2)
plot(x,z); grid
39 of 53
Resulting Subplot
0.6
0.4
0.2
0
-0.2
0.5
1.5
2.5
3.5
0.5
1.5
2.5
3.5
0.5
-0.5
-1
40 of 53
Latitude (deg)
-130
-120
-110
-100
-90
Longitude (deg)
-80
-70
-60
12
Traffic (acft)
10
8
6
4
2
0
1100
1120
1140
1160
1240
1260
1280
1300
41 of 53
Zoom Command
Latitude (deg)
The zoom
command is used to examine a smaller area
31
30
29
28
27
-90
-88
-86
-84
-82
Longitude (deg)
-80
-78
-76
12
Traffic (acft)
10
8
6
4
2
0
1100
1120
1140
1160
1240
1260
1280
1300
42 of 53
43 of 53
Viewing Control
44 of 53
45 of 53
Volume (veh/hr)
2500
2000
1500
1000
TextEnd
500
0
80
60
150
40
100
20
Density (veh/la-km)
50
0
Speed (km/hr)
46 of 53
Rotate Command
The rotate3d command is useful to visualize 3D data
interactively
3500
3000
Volume (veh/hr)
2500
2000
1500
1000
TextEnd
500
0
80
60
40
20
Density (veh/la-km)
20
40
60
80
100
120
140
Speed (km/hr)
47 of 53
-5
-10
50
40
50
30
40
30
20
20
10
10
0
48 of 53
25
15
20
15
10
10
5
0
49 of 53
25
15
20
15
10
10
5
0
50 of 53
51 of 53
20
15
10
0
20
15
20
15
10
10
5
0
52 of 53
3500
Volume (veh/hr)
3000
2500
2000
1500
1000
TextEnd
500
0
80
60
150
40
100
20
Density (veh/la-km)
50
0
0
Speed (km/hr)
53 of 53