Lecture 5
Lecture 5
Engineering Applications
(GENG-8030)
By:
Dr. Hassanzadeh
Lecture number:
(5)
Winter 2023
Nomenclature for a typical xy plot:
3.5
3
Height (miles)
2.5
1.5
0.5
0
0 10 20 30 40 50 60
Distance (miles)
Note that using the Alt-Tab key combination in Windows-based systems will
return you to the Command window without closing the figure window.
If you do not close the window, it will not reappear when a new plot command
is executed. However, the figure will still be updated.
You can use the axis command to override the MATLAB selections for the
axis limits. The basic syntax is axis([xmin xmax ymin ymax]). This
command sets the scaling for the x- and y-axes to the minimum and maximum
values indicated. Note that, unlike an array, this command does not use
commas to separate the values.
-0.6
-0.8
-1
-1.2
-1.4
-1.6
-1.8
-2
-2.2
-2.4
-0.5
-1
-1.5
-2
-2.5
-3
1 1.2 1.4 1.6 1.8 2
2.5
Height (miles)
1.5
0.5
0
0 5 10 15 20 25 30 35
Distance (miles)
Computational methods and modeling for engineering applications (GENG-8030) 11
Practice Question 2:
Q2- Use the fplot command to plot and investigate the function
. How many values of x are needed to obtain the same plot using the plot
command?
1.5
0.5
-0.5
-1
-1.5
0 1 2 3 4 5 6
n
Plot of (0.2+0.8i) for n=[0,20]
1
0.5
Imaginary
-0.5
-1
-1 -0.5 0 0.5 1
Real
Computational methods and modeling for engineering applications (GENG-8030) 13
Saving figures:
To save a figure that can be opened in subsequent MATLAB sessions, save it
in a figure file with the .fig file name extension.
To do this, select Save from the Figure window File menu or click the Save
button (the disk icon) on the toolbar.
If this is the first time you are saving the file, the Save As dialog box appears.
Make sure that the type is MATLAB Figure (*.fig). Specify the name you
want assigned to the figure file. Click OK.
1. Start scales from zero whenever possible. This technique prevents a false
impression of the magnitudes of any variations shown on the plot.
3. Minimize the number of zeros in the data being plotted. For example, use
a scale in millions of dollars when appropriate, instead of a scale in
dollars with six zeros after every number.
For example, if the data on the x-axis ranges from 1.2 to 9.6, a good choice
for axis limits is 0 to 10. This choice allows you to use a tick spacing of 1 or
2.
5. Use a different line type for each curve when several are plotted on a
single plot and they cross each other; for example, use a solid line, a
dashed line, and combinations of lines and symbols. Beware of using
colors to distinguish plots if you are going to make black-and-white
printouts and photocopies.
6. Do not put many curves on one plot, particularly if they will be close to
each other or cross one another at several points.
The title function places the text at the top of the plot.
The gtext function places the text at the point on the plot where the cursor is
located when you click the left mouse button.
1
Sin(x)
0.5
Y
-0.5
-1
0 1 2 3 4 5 6 7
X
For example, subplot(3,2,5) creates an array of six panes, three panes deep
and two panes across, and directs the next plot to appear in the fifth pane (in
the bottom-left corner).
To plot y versus x with asterisks (*) connected with a dotted line, you must
plot the data twice by typing plot(x,y,‘*’,x,y,‘:’).
4
sinh(x)
3.5 tanh(x)
3
Hyperbolic functions
2.5
1.5
0.5
0
0 0.5 1 1.5 2
X
0.8
0.6
0.4
0.2
-0.2
-0.4
-0.6
-0.8
-1
0 1 2 3 4 5 6 7
0.5
z
-0.5
-1
0 1 2 3 4 5 6 7 8
t
12
11
10
u
8
-8 -6 -4 -2 0 2 4 6 8
v
10
y1, y2
8
2
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5
x
3.5
2.5
2
y
1.5
1 0.5exp(x)
0.5 sinh(x)
0
0 0.5 1 1.5 2
x
180 0
210 330
240 300
270
,
plot. The power function is , and the exponential function is .
101
y=2*x.-0.5 y=10. 1-x
101
100
y
10-1
100 10-2
10-2 100 0 1 2 3
x x
3
y=8*x.
8
0
y
-2
-4
-6
-8
-1 -0.75 -0.5 -0.25 0 0.25 0.5 0.75 1
x
0.8
0.6
0.5
0.4
0.2
0 0
-0.2
-0.4
-0.5
-0.6
-0.8
-1 -1
-1 -0.5 0 0.5 1 -1 -0.5 0 0.5 1
1
0.5
-0.5
-1
-1 -0.5 0 0.5 1
Computational methods and modeling for engineering applications (GENG-8030) 35
Plotting implicit functions:
MATLAB provides the function fimplicit(f) to plot the implicit function
defined by the equation f(x,y) 0 over the default interval [5 5] for x and y.
For example, to plot the hyperbola defined by x^2 y^2 1 0 over the default
interval of [5 5], you type
If the limits for x are [−2 2] and the limits for y are [−4 4], you would type
4
4
3
3
2
2
1
1
0 0
-1 -1
-2
-2
-3
-3
-4
-4
-5 0 5 -2 -1 0 1 2
over the default interval . You can specify the interval with the syntax .
For example, to plot the upper half of the hyperboloid
you specify the interval as for z as , and for x and y, use the default interval ,
as follows.
axis equal sets the aspect ratio so that the data units are the same in every
direction.
Ampersand curve
0.5
-0.5
-1
0 0.5 1 1.5
Computational methods and modeling for engineering applications (GENG-8030) 42
Practice Question 11:
Q10- Use plot3 and fplot3 to plot the 3-D line plot described by for .