Download presentation
Presentation is loading. Please wait.
1
Two-Dimensional Plots
Islamic University of Gaza Faculty of Engineering Civil Engineering Department Chapter 5 Two-Dimensional Plots Plots are a very useful tool for presenting information. This is true in any field, but especially in science and engineering, where MATLAB is mostly used. Computer Programming Dr.Moayed Almobaied Lecture 12
2
Islamic University of Gaza
Faculty of Engineering Civil Engineering Department MATLAB has many commands that can be used for creating different types of plots. These include standard plots with linear axes, plots with logarithmic and semi-logarithmic axes, three-dimensional contour surface… The plots can be formatted to have a desired appearance. The line type (solid, dashed, etc.), color, and thickness can be prescribed, line markers and grid lines can be added, as can titles and text comments. Computer Programming Computer Programming Dr.Moayed Almobaied Lecture 11
3
Islamic University of Gaza
Faculty of Engineering Civil Engineering Department Several graphs can be created in the same plot, and several plots can be placed on the same page. When a plot contains several graphs and/or data points, a legend can be added to the plot as well. Computer Programming Computer Programming Dr.Moayed Almobaied Lecture 11
4
Islamic University of Gaza Faculty of Engineering
Civil Engineering Department Computer Programming Dr.Moayed Almobaied Computer Programming Lecture 11
5
Plot Command The plot command is used to create two-dimensional plots.
Islamic University of Gaza Faculty of Engineering Civil Engineering Department Plot Command The plot command is used to create two-dimensional plots. The simplest form of the command is: Computer Programming Computer Programming Dr.Moayed Almobaied Lecture 11
6
The arguments x and y are each a vector (one-dimensional array).
Islamic University of Gaza Faculty of Engineering Civil Engineering Department The arguments x and y are each a vector (one-dimensional array). 2. The two vectors must have the same number of elements. 3. When the plot command is executed, a figure is created in the Figure Window. If not already open, the Figure Window opens automatically when the command is executed. 5. The figure has a single curve with the x values on the horizontal axis and the y values on the vertical axis. Computer Programming Dr.Moayed Almobaied Computer Programming Lecture 11
7
Islamic University of Gaza
Faculty of Engineering Civil Engineering Department 6. The curve is constructed of straight-line segments that connect the points whose coordinates are defined by the elements of the vectors x and y. 7. Each of the vectors, of course, can have any name. The vector that is typed first in the plot command is used for the horizontal axis, and the vector that is typed second is used for the vertical axis. 8. If only one vector is entered as an input argument in the plot command (for example plot (y)) then the figure will show a plot of the values of the elements of the vector ( y(l), y(2), y(3), ... ) versus the element number ( 1, 2, 3, ... ). Computer Programming Dr.Moayed Almobaied Computer Programming Lecture 11
8
Islamic University of Gaza
Faculty of Engineering Civil Engineering Department For example, if a vector x has the elements 1, 2, 3, 5, 7, 7.5, 8, 10, and a vector y has the elements 2, 6.5, 7, 7, 5.5, 4, 6, 8, a simple plot of y versus x can be created by typing the following in the Command Window: Computer Programming Dr.Moayed Almobaied Computer Programming Lecture 11
9
Islamic University of Gaza Faculty of Engineering
Civil Engineering Department Computer Programming Dr.Moayed Almobaied Computer Programming Lecture 11
10
Islamic University of Gaza
Faculty of Engineering Civil Engineering Department The plot appears on the screen in blue, which is the default line color. Computer Programming Dr.Moayed Almobaied Computer Programming Lecture 11
11
Islamic University of Gaza Faculty of Engineering
Civil Engineering Department Computer Programming Dr.Moayed Almobaied Computer Programming Lecture 11
12
Islamic University of Gaza Faculty of Engineering
Civil Engineering Department Computer Programming Dr.Moayed Almobaied Computer Programming Lecture 11
13
Islamic University of Gaza Faculty of Engineering
Civil Engineering Department Computer Programming Dr.Moayed Almobaied Computer Programming Lecture 11
14
Islamic University of Gaza Faculty of Engineering
Civil Engineering Department Computer Programming Dr.Moayed Almobaied Computer Programming Lecture 11
15
Islamic University of Gaza Faculty of Engineering
Civil Engineering Department Computer Programming Dr.Moayed Almobaied Computer Programming Lecture 11
16
Islamic University of Gaza Faculty of Engineering
Civil Engineering Department Computer Programming Dr.Moayed Almobaied Computer Programming Lecture 11
17
Islamic University of Gaza Faculty of Engineering
Civil Engineering Department Computer Programming Dr.Moayed Almobaied Computer Programming Lecture 11
18
Islamic University of Gaza Faculty of Engineering
Civil Engineering Department Computer Programming Dr.Moayed Almobaied Computer Programming Lecture 11
19
Example: Plot of Given Data
Islamic University of Gaza Faculty of Engineering Civil Engineering Department As with any command, the plot command can be typed in the Command Window, or it can be included in a script file. It also can be used in a function file. Example: Plot of Given Data Computer Programming Computer Programming Dr.Moayed Almobaied Lecture 11
20
Islamic University of Gaza Faculty of Engineering
Civil Engineering Department Computer Programming Dr.Moayed Almobaied Computer Programming Lecture 11
21
Then a vector y is created with the corresponding values of f(x) by
Islamic University of Gaza Faculty of Engineering Civil Engineering Department Plot of Function In order to plot a function y=f(x) with the plot command, the user needs to first create a vector of values of x for the domain over which the function will be plotted. Then a vector y is created with the corresponding values of f(x) by using element-by-element calculations. Example Computer Programming Dr.Moayed Almobaied Computer Programming Lecture 11
22
Islamic University of Gaza Faculty of Engineering
Civil Engineering Department Computer Programming Dr.Moayed Almobaied Computer Programming Lecture 11
23
Islamic University of Gaza
Faculty of Engineering Civil Engineering Department 0.3 instead of 0.01‘with much larger spacing’ the plot that is obtained, gives a distorted picture of the function Computer Programming Dr.Moayed Almobaied Computer Programming Lecture 11
24
The Fplot Command Islamic University of Gaza Faculty of Engineering
Civil Engineering Department The Fplot Command Computer Programming Dr.Moayed Almobaied Computer Programming Lecture 11
25
Islamic University of Gaza Faculty of Engineering
Civil Engineering Department Computer Programming Dr.Moayed Almobaied Computer Programming Lecture 11
26
Islamic University of Gaza Faculty of Engineering
Civil Engineering Department Computer Programming Dr.Moayed Almobaied Computer Programming Lecture 11
27
Plotting Multiple Graphs In The Same Plot
Islamic University of Gaza Faculty of Engineering Civil Engineering Department Plotting Multiple Graphs In The Same Plot Using the plot Command Computer Programming Computer Programming Dr.Moayed Almobaied Lecture 11
28
Islamic University of Gaza Faculty of Engineering
Civil Engineering Department Computer Programming Dr.Moayed Almobaied Computer Programming Lecture 11
29
Islamic University of Gaza Faculty of Engineering
Civil Engineering Department Computer Programming Dr.Moayed Almobaied Computer Programming Lecture 11
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.