0% found this document useful (0 votes)
16 views21 pages

Che334 (Matlab) Lecture 5

The document describes how to create bar charts and 3D plots in MATLAB. It shows an example of a bar chart created from exam score data for 10 students. It then demonstrates how to generate 3D line and surface plots using the plot3, mesh, and surf commands along with examples of plotting a sine wave over time and the exponential function z=xe^(-x^2-y^2). Meshgrids are used to generate the x and y coordinate arrays for the surface plots.
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)
16 views21 pages

Che334 (Matlab) Lecture 5

The document describes how to create bar charts and 3D plots in MATLAB. It shows an example of a bar chart created from exam score data for 10 students. It then demonstrates how to generate 3D line and surface plots using the plot3, mesh, and surf commands along with examples of plotting a sine wave over time and the exponential function z=xe^(-x^2-y^2). Meshgrids are used to generate the x and y coordinate arrays for the surface plots.
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/ 21

• Drawing bar charts

• The bar command draws a two


dimensional bar chart
• Example: ten students obtained
the following scores in CHE317
exam. 75, 58, 90, 87, 50, 85, 92,
75, 60 and 95.
• Represent the data in a bar chart
• >> x = [1:10];
• >> y = [75, 58, 90, 87, 50, 85, 92,
75, 60, 95];
• >> bar(x,y),
• xlabel('Student'),
• ylabel('Score'),
• >> title('First Semester :')
First Semester :
100

90

80

70

60
Score

50

40

30

20

10

0
1 2 3 4 5 6 7 8 9 10
Student
• Two and Three dimensional graphs
• If x, y, and z are vectors with the same
size (length), they can be plotted using
the command plot3.
• Plot3(x,y,z) generates a line in three
dimensions through the points whose
coordinates are the elements of x,y and
z and then produces a 2-dimensional
projection of that line on the screen.
• >> t=(0:0.02*pi:25*pi);
• >> x=sin(t); y=cos(t); z=t;
• >> plot3(x,y,z)
80

60

40

20

0
1
0.5 1
0 0.5
0
-0.5 -0.5
-1 -1
• Three-dimensional plots basically
display a surface defined by a
function in two variables,
• g = f (x, y).
• As before, to define g, we first
create a set of x, y points over the
domain of the function using the
• meshgrid command.
• Next, we assign the function
itself.
• Finally, we use the surf command
to create a surface plot.
• Let us create a 3D surface map
for the function g = xe-(x2 + y2)
• >> [x,y] = meshgrid(-2:.2:2);
• >> g = x.*exp(-x.^2 - y.^2);
• >> surf(x,y,g)
0.5

-0.5
2
1 2
0 1
0
-1 -1
-2 -2
• Remember you can also use the
mesh command to generate a
three-dimensional surface.
However, the surf command
displays both the connecting lines
and the faces of the surface in color,
whereas, the mesh command
creates a wireframe surface with
colored lines connecting the
defining points.
• Example.
• Re-plot the above using the mesh
grid.
• >> [x,y] = meshgrid(-2:.2:2);
• g = x.*exp(-x.^2 - y.^2);
• >> plot3(x,y,g).
• This gives
0.5

-0.5
2
1 2
0 1
0
-1 -1
-2 -2
• Consider a scalar function of two variables Z=
f(x,y). This function defines a surface in the
three-dimensional space. The surface can be
graphically represented using mesh, meshc,
surf. Surfc surfl and other commands and
functions.
• In general, the function Z = f(x,y) is calculated
and stored as the Z matrix, and a grid is
defined.
• To evaluate the functions, meshgrid is used.
Here, the (x,y) data is generated to evaluate Z
= f(x,y).
• We can calculate the nonlinear functions


• The x, y and z can be plotted using a 3-
dimensional plot applying meshgrid.
• [x,y]=meshgrid(-4:0.1:4);
• Z=x.^2*y.*exp(x.^2+y.^4);
• Plot3(x,y,z)
>> [x y] = meshgrid(-4:0.1:4);
>> z = (x.^2.*y)*(exp(x.^2+y.^4));
>> plot3(x,y,z)
>> surf(x,y,z)
>> z = (x.^2.*y)*(exp(x.^2+y.^4));
>> z = ((x.^2).*y).*(exp(x.^2+y.^4)); OR
>> z = (x.^2).*(y).*(exp(x.^2+y.^4));
>> plot3(x,y,z)
Surf(x,y,z)
z = (x.^2).*(y).*(exp(x.^2)+(y.^4));
>> plot3(x,y,z)
>> surf(x,y,z)

Analyse the function, pick or make corrections


and submit

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy