Lecsson 03_Matrix_Plotting_2 (1)
Lecsson 03_Matrix_Plotting_2 (1)
AMAT 21262
LESSON 03
Part II
Matrix Calculations
and Plotting
1
0.6
0.4
0.2
-0.2
-0.4
-0.6
-0.8
-1
0 50 100 150 200 250 300 350 400
J Munasinghe,
Department
Department
of Mathematics
of Mathematics 2
AMAT 21262
21552
More Plotting Arguments
• RGB(Red Green Blue) triplets and linewidth
clear all; close all; clc;
• Built-in Functions
Labelling Plots
for Matrices
• Adding a title to your plot
• Graphics and title();
Plotting
• Lecture Summary
• Adding labels to axes
xlabel(‘’);
ylabel(‘’);
• Adding a legend
legend(‘’);
J Munasinghe,Department
DepartmentofofMathematics
Mathematics 5
21552
AMAT 21262
Remember to Label your Plots
• On the 23rd of September 1999, NASA lost its US$125
million Mars orbiter climate satellite. The satellite
crashed into Mars.
• The mistake:
– NASA uses metric units (metres) for everything,
including its orbiter satellite calculations
– Lockheed Martin, the company controlling the satellite
on a day-to-day basis, was working in Imperial units
(feet, inches etc.,)
– 1 metre is 3.28 feet
• The lesson: Data labels and units are important,
especially in group work
6
J Munasinghe, Department of Mathematics
AMAT 21262
AMAT 21552
31053
• Recap
• Built-in Functions
Built-in Functions for Plotting
for Matrices • Close all opened Figures (plots etc)
close all
• Graphics and
Plotting
• To reuse last plot without erasing it
• Lecture Summary hold on
<other plotting commands>
hold off
J Munasinghe, Department
Department of Mathematics
of Mathematics
7
AMAT 21262
AMAT 21552
Subplot for multiple graphs
clc;clear; Paraboal
Paraboal Sine
Sine graph
graph
1515 11
x=-3:0.01:3;
1010 0.5
0.5
55 00
00 -0.5
-0.5
-5 -1
-5 -4 -2 0 2 4 -1
-4 -2 0 2 4
-4 -2 0 2 4 -4 -2 0 2 4
x axis x in radian
x axis x in radian
Exponential graph
1500 Exponential graph
1500
1000
1000
500
500
0
0
-500
-4 -2 0 2 4
-500 x axis
-4 -2 0 2 4
grid on x axis
8
• Built-in Functions
Your first Debugging Task
for Matrices
• Oscillations in electrical circuits and vibrations in
• Graphics and
Plotting structures or machines are often modelled using
damped sinusoids such as
• Lecture Summary
J Munasinghe,Department
DepartmentofofMathematics
Mathematics 9
AMAT 21262
21552
Example 1
The velocity and force data are obtained in the wind
tunnel
v (m/s) 10 20 30 40 50 60 70 80
F 25 70 380 550 610 1220 830 1450
v (m/s) 10 20 30 40 50 60 70 80
F 25 70 380 550 610 1220 830 1450
• Built-in Functions
3D Plotting Functions
for Matrices
• Engineers regularly deal with 3D data
• Graphics and
Plotting – We live in a three-dimensional world afterall
• Lecture Summary
J Munasinghe,Department
DepartmentofofMathematics
Mathematics 16
• Recap
• Built-in Functions
3D Line Plot Example
for Matrices
t = linspace()
• Graphics and
Plotting Helix
Figure 6.3: Helix
• Lecture Summary
35
30
plot3(
25
xlabel;
20
t
15
10
0
1
0.5 1
0.5
0
0
-0.5
-0.5
cos(t) -1 -1
sin(t)
J Munasinghe,Department
DepartmentofofMathematics
Mathematics 17
• Recap
• Built-in Functions
Mesh Plot Example
for Matrices
[x,y] = meshgrid(-2:0.2:2);
• Graphics and
Plotting
z =;
z = exp(-x2-y2)
• Lecture Summary
0.9
0.8
0.7
0.6
z 0.5
0.4
0.3
0.2
0.1
0
2
1 2
1.5
1
0
0.5
0
-1 -0.5
-1
-1.5
y -2 -2
x
J Munasinghe,
Department
Department
of of
Mathematics
Mathematics 18
• Recap
• Built-in Functions
Surface Plot Example
for Matrices
[x,y] = meshgrid(-2:0.2:2);
• Graphics and
Plotting
z = exp(-x.^2 - y.^2); z = exp(-x2-y2)
• Lecture Summary
0.9
0.8
0.7
0.6
0.5
z
0.4
0.3
0.2
0.1
0
2
1 2
1.5
1
0
0.5
0
-1 -0.5
-1
-1.5
y -2 -2
x
J Munasinghe,Department
DepartmentofofMathematics
Mathematics 19
• Recap
• Built-in Functions
Contour Plot Example
for Matrices
[x,y] = meshgrid(-2:0.2:2);
• Graphics and
Plotting z = exp(-x.^2 - y.^2);
• Lecture Summary
z = exp(-x2-y2)
2
1.5
0.5
0
y
-0.5
-1
-1.5
-2
-2
Department
J Munasinghe,
-1.5 -1
of of
Department Mathematics
-0.5 0 0.5
Mathematics
x
1 1.5
20 2
• Recap
• Built-in Functions
MATLAB 2D Plotting Help
for Matrices
• Graphics and
Plotting
• Lecture Summary
J Munasinghe,Department
DepartmentofofMathematics
Mathematics 21
• Recap
• Built-in Functions
MATLAB 3D Plotting Help
for Matrices
• Graphics and
Plotting
• Lecture Summary
J Munasinghe,Department
DepartmentofofMathematics
Mathematics 22
AMAT 21262
AMAT 21552
31053
• Recap
Lecture Summary
• Built-in Functions
for Matrices • This lecture covered the following topics
• Graphics and – Matrix calculations
Plotting
– Built-in functions that operate on matrices
• Lecture Summary – Visualizing data using MATLAB plots
– Labelling MATLAB plots
– 3D plots and the importance presentation
Department
J Munasinghe, of Mathematics
Department of Mathematics
23