29
Islamic University of Gaza Faculty of Engineering Civil Engineering Department Computer Programming Dr. Jawdat Abu Taha Lecture 12 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.

Faculty of Engineering Civil Engineering Department ...site.iugaza.edu.ps › jtaha › ... › 09 › Presentation10-Two-Dimensional-… · Faculty of Engineering Civil Engineering

  • Upload
    others

  • View
    3

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Faculty of Engineering Civil Engineering Department ...site.iugaza.edu.ps › jtaha › ... › 09 › Presentation10-Two-Dimensional-… · Faculty of Engineering Civil Engineering

Islamic University of GazaFaculty of EngineeringCivil Engineering Department

Computer Programming Dr. Jawdat Abu Taha Lecture 12

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.

Page 2: Faculty of Engineering Civil Engineering Department ...site.iugaza.edu.ps › jtaha › ... › 09 › Presentation10-Two-Dimensional-… · Faculty of Engineering Civil Engineering

Islamic University of GazaFaculty of EngineeringCivil Engineering Department

Computer Programming Lecture 11

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 Dr. Jawdat Abu Taha

Page 3: Faculty of Engineering Civil Engineering Department ...site.iugaza.edu.ps › jtaha › ... › 09 › Presentation10-Two-Dimensional-… · Faculty of Engineering Civil Engineering

Islamic University of GazaFaculty of EngineeringCivil Engineering Department

Computer Programming Lecture 11

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 Dr. Jawdat Abu Taha

Page 4: Faculty of Engineering Civil Engineering Department ...site.iugaza.edu.ps › jtaha › ... › 09 › Presentation10-Two-Dimensional-… · Faculty of Engineering Civil Engineering

Islamic University of GazaFaculty of EngineeringCivil Engineering Department

Computer Programming Lecture 11Computer Programming Dr. Jawdat Abu Taha

Page 5: Faculty of Engineering Civil Engineering Department ...site.iugaza.edu.ps › jtaha › ... › 09 › Presentation10-Two-Dimensional-… · Faculty of Engineering Civil Engineering

Islamic University of GazaFaculty of EngineeringCivil Engineering Department

Computer Programming Lecture 11Computer Programming Dr. Jawdat Abu Taha

Plot Command

The plot command is used to create two-dimensional plots.

The simplest form of the command is:

Page 6: Faculty of Engineering Civil Engineering Department ...site.iugaza.edu.ps › jtaha › ... › 09 › Presentation10-Two-Dimensional-… · Faculty of Engineering Civil Engineering

Islamic University of GazaFaculty of EngineeringCivil Engineering Department

Computer Programming Lecture 11Computer Programming Dr. Jawdat Abu Taha

1. 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.

4. 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.

Page 7: Faculty of Engineering Civil Engineering Department ...site.iugaza.edu.ps › jtaha › ... › 09 › Presentation10-Two-Dimensional-… · Faculty of Engineering Civil Engineering

Islamic University of GazaFaculty of EngineeringCivil Engineering Department

Computer Programming Lecture 11Computer Programming Dr. Jawdat Abu Taha

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, ... ).

Page 8: Faculty of Engineering Civil Engineering Department ...site.iugaza.edu.ps › jtaha › ... › 09 › Presentation10-Two-Dimensional-… · Faculty of Engineering Civil Engineering

Islamic University of GazaFaculty of EngineeringCivil Engineering Department

Computer Programming Lecture 11Computer Programming Dr. Jawdat Abu Taha

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:

Page 9: Faculty of Engineering Civil Engineering Department ...site.iugaza.edu.ps › jtaha › ... › 09 › Presentation10-Two-Dimensional-… · Faculty of Engineering Civil Engineering

Islamic University of GazaFaculty of EngineeringCivil Engineering Department

Computer Programming Lecture 11Computer Programming Dr. Jawdat Abu Taha

Page 10: Faculty of Engineering Civil Engineering Department ...site.iugaza.edu.ps › jtaha › ... › 09 › Presentation10-Two-Dimensional-… · Faculty of Engineering Civil Engineering

Islamic University of GazaFaculty of EngineeringCivil Engineering Department

Computer Programming Lecture 11Computer Programming Dr. Jawdat Abu Taha

The plot appears on the screen in blue, which is the default line color.

Page 11: Faculty of Engineering Civil Engineering Department ...site.iugaza.edu.ps › jtaha › ... › 09 › Presentation10-Two-Dimensional-… · Faculty of Engineering Civil Engineering

Islamic University of GazaFaculty of EngineeringCivil Engineering Department

Computer Programming Lecture 11Computer Programming Dr. Jawdat Abu Taha

Page 12: Faculty of Engineering Civil Engineering Department ...site.iugaza.edu.ps › jtaha › ... › 09 › Presentation10-Two-Dimensional-… · Faculty of Engineering Civil Engineering

Islamic University of GazaFaculty of EngineeringCivil Engineering Department

Computer Programming Lecture 11Computer Programming Dr. Jawdat Abu Taha

Page 13: Faculty of Engineering Civil Engineering Department ...site.iugaza.edu.ps › jtaha › ... › 09 › Presentation10-Two-Dimensional-… · Faculty of Engineering Civil Engineering

Islamic University of GazaFaculty of EngineeringCivil Engineering Department

Computer Programming Lecture 11Computer Programming Dr. Jawdat Abu Taha

Page 14: Faculty of Engineering Civil Engineering Department ...site.iugaza.edu.ps › jtaha › ... › 09 › Presentation10-Two-Dimensional-… · Faculty of Engineering Civil Engineering

Islamic University of GazaFaculty of EngineeringCivil Engineering Department

Computer Programming Lecture 11Computer Programming Dr. Jawdat Abu Taha

Page 15: Faculty of Engineering Civil Engineering Department ...site.iugaza.edu.ps › jtaha › ... › 09 › Presentation10-Two-Dimensional-… · Faculty of Engineering Civil Engineering

Islamic University of GazaFaculty of EngineeringCivil Engineering Department

Computer Programming Lecture 11Computer Programming Dr. Jawdat Abu Taha

Page 16: Faculty of Engineering Civil Engineering Department ...site.iugaza.edu.ps › jtaha › ... › 09 › Presentation10-Two-Dimensional-… · Faculty of Engineering Civil Engineering

Islamic University of GazaFaculty of EngineeringCivil Engineering Department

Computer Programming Lecture 11Computer Programming Dr. Jawdat Abu Taha

Page 17: Faculty of Engineering Civil Engineering Department ...site.iugaza.edu.ps › jtaha › ... › 09 › Presentation10-Two-Dimensional-… · Faculty of Engineering Civil Engineering

Islamic University of GazaFaculty of EngineeringCivil Engineering Department

Computer Programming Lecture 11Computer Programming Dr. Jawdat Abu Taha

Page 18: Faculty of Engineering Civil Engineering Department ...site.iugaza.edu.ps › jtaha › ... › 09 › Presentation10-Two-Dimensional-… · Faculty of Engineering Civil Engineering

Islamic University of GazaFaculty of EngineeringCivil Engineering Department

Computer Programming Lecture 11Computer Programming Dr. Jawdat Abu Taha

Page 19: Faculty of Engineering Civil Engineering Department ...site.iugaza.edu.ps › jtaha › ... › 09 › Presentation10-Two-Dimensional-… · Faculty of Engineering Civil Engineering

Islamic University of GazaFaculty of EngineeringCivil Engineering Department

Computer Programming Lecture 11Computer Programming Dr. Jawdat Abu Taha

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

Page 20: Faculty of Engineering Civil Engineering Department ...site.iugaza.edu.ps › jtaha › ... › 09 › Presentation10-Two-Dimensional-… · Faculty of Engineering Civil Engineering

Islamic University of GazaFaculty of EngineeringCivil Engineering Department

Computer Programming Lecture 11Computer Programming Dr. Jawdat Abu Taha

Page 21: Faculty of Engineering Civil Engineering Department ...site.iugaza.edu.ps › jtaha › ... › 09 › Presentation10-Two-Dimensional-… · Faculty of Engineering Civil Engineering

Islamic University of GazaFaculty of EngineeringCivil Engineering Department

Computer Programming Lecture 11Computer Programming Dr. Jawdat Abu Taha

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

Page 22: Faculty of Engineering Civil Engineering Department ...site.iugaza.edu.ps › jtaha › ... › 09 › Presentation10-Two-Dimensional-… · Faculty of Engineering Civil Engineering

Islamic University of GazaFaculty of EngineeringCivil Engineering Department

Computer Programming Lecture 11Computer Programming Dr. Jawdat Abu Taha

Page 23: Faculty of Engineering Civil Engineering Department ...site.iugaza.edu.ps › jtaha › ... › 09 › Presentation10-Two-Dimensional-… · Faculty of Engineering Civil Engineering

Islamic University of GazaFaculty of EngineeringCivil Engineering Department

Computer Programming Lecture 11Computer Programming Dr. Jawdat Abu Taha

0.3 instead of 0.01‘with much larger spacing’ the plot that is

obtained, gives a distorted picture of the function

Page 24: Faculty of Engineering Civil Engineering Department ...site.iugaza.edu.ps › jtaha › ... › 09 › Presentation10-Two-Dimensional-… · Faculty of Engineering Civil Engineering

Islamic University of GazaFaculty of EngineeringCivil Engineering Department

Computer Programming Lecture 11Computer Programming Dr. Jawdat Abu Taha

The Fplot Command

Page 25: Faculty of Engineering Civil Engineering Department ...site.iugaza.edu.ps › jtaha › ... › 09 › Presentation10-Two-Dimensional-… · Faculty of Engineering Civil Engineering

Islamic University of GazaFaculty of EngineeringCivil Engineering Department

Computer Programming Lecture 11Computer Programming Dr. Jawdat Abu Taha

Page 26: Faculty of Engineering Civil Engineering Department ...site.iugaza.edu.ps › jtaha › ... › 09 › Presentation10-Two-Dimensional-… · Faculty of Engineering Civil Engineering

Islamic University of GazaFaculty of EngineeringCivil Engineering Department

Computer Programming Lecture 11Computer Programming Dr. Jawdat Abu Taha

Page 27: Faculty of Engineering Civil Engineering Department ...site.iugaza.edu.ps › jtaha › ... › 09 › Presentation10-Two-Dimensional-… · Faculty of Engineering Civil Engineering

Islamic University of GazaFaculty of EngineeringCivil Engineering Department

Computer Programming Lecture 11Computer Programming Dr. Jawdat Abu Taha

Plotting Multiple Graphs In The Same Plot

Using the plot Command

Page 28: Faculty of Engineering Civil Engineering Department ...site.iugaza.edu.ps › jtaha › ... › 09 › Presentation10-Two-Dimensional-… · Faculty of Engineering Civil Engineering

Islamic University of GazaFaculty of EngineeringCivil Engineering Department

Computer Programming Lecture 11Computer Programming Dr. Jawdat Abu Taha

Page 29: Faculty of Engineering Civil Engineering Department ...site.iugaza.edu.ps › jtaha › ... › 09 › Presentation10-Two-Dimensional-… · Faculty of Engineering Civil Engineering

Islamic University of GazaFaculty of EngineeringCivil Engineering Department

Computer Programming Lecture 11Computer Programming Dr. Jawdat Abu Taha