0% found this document useful (0 votes)
35 views

Lecsson 03_Matrix_Plotting_2 (1)

Uploaded by

rajithsjc
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
35 views

Lecsson 03_Matrix_Plotting_2 (1)

Uploaded by

rajithsjc
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 23

AMAT 21552

AMAT 21262

LESSON 03
Part II

Matrix Calculations
and Plotting
1

J Munasinghe, Department of Mathematics Department of Mathematics


• Recap
Multiple Plots with Optional Arguments
• Built-in Functions
for Matrices
t = ;
• Graphics and plot( ’ );
Plotting
1

• Lecture Summary 0.8

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;

J Munasinghe, Department of Mathematics


3
AMAT 21262
21552
More Plotting Arguments
• Markersize, Markerfacecolor, Markeredgecolor
hold on
x2 =

J Munasinghe, Department of Mathematics 4


• Recap

• 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(‘’);

• Showing OR Hiding the grid


grid on; OR grid off;

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

• Multiple plots in one figure


subplot(rows, columns, index);

• Setting range of x and y axis


axis([xmin xmax ymin ymax]);

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

J Munasinghe, Department of Mathematics


• Recap

• 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

x(t ) = 8e −0.5t sin( 5t + 2)

• The following code calculates and plots the above


using MATLAB
t =

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

Plot the data as red diamonds


– Limit the range of the x-axis to 0 and 100
– Limit the range of the y-axis to 0 and 1500

J Munasinghe, Department of Mathematics 10


AMAT 21262
21552
Example 1

v (m/s) 10 20 30 40 50 60 70 80
F 25 70 380 550 610 1220 830 1450

J Munasinghe, Department of Mathematics 11


AMAT 21262
21552
Example 2
A simply supported beam that is subjected to a constant
distributed load w over two-thirds of its length is shown

The deflection y(x), is given by

where E is the elastic modulus, I is the moment of inertia and L is


the length of the beam

J Munasinghe, Department of Mathematics 12


AMAT 21262
21552
Example 2
Consider L=35 m, E=200x109 Pa, I = 348x10-6 m4 and w=5.3x103
N/m

Plot the deflection of the


– First segment of the beam using a magenta dashed line
– Second segment of the beam using a red dashed line

J Munasinghe, Department of Mathematics 13


AMAT 21262
21552
Example 2
Consider L=35 m, E=200x109 Pa, I = 348x10-6 m4 and w=5.3x103
N/m

Determine the maximum deflection and corresponding x location


– Mark this point on the plot as a blue asterisk
J Munasinghe, Department of Mathematics 14
AMAT 21262
21552
Example 3
• A water tank consists of a cylindrical part of radius r and height
h, and a hemispherical top. The tank is to be constructed to
hold 800m3 of fluid when filled. The surface area of the
cylindrical part is 2πrh, and its volume is πr2h. The surface area
of the hemispherical top is given by 2πr2, and its volume is
given by 2πr3/3. The total cost to construct the cylindrical part of
the tank is $300/m2 of surface area; the hemispherical part
costs $400/m2.

• Plot the radius against total cost


• Determine the minimum cost and corresponding radius and
height
• Plot the minimum point
J Munasinghe, Department of Mathematics 15
• Recap

• 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

• As with 2D plots, 3D plots lets us visualize


data and compare multiple data sets

• Syntax of commonly used 3D plotting


functions
– 3D Line plot: plot3(x, y, z);
– Mesh plot: mesh(x, y, z);
– Surface plot: surf(x, y, z);
– Contour plot: contour(z, num_lines);

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

• Next week, I will show how to execute a


series of MATLAB command automatically by
using M-file.

Department
J Munasinghe, of Mathematics
Department of Mathematics
23

You might also like