<meta http-equiv="refresh" content="1; url=/nojavascript/"> Introduction to Graphing in M-File Environments | CK-12 Foundation
Skip Navigation
You are reading an older version of this FlexBook® textbook: Engineering: An Introduction to Solving Engineering Problems with Matlab Go to the latest version.

4.1: Introduction to Graphing in M-File Environments

Difficulty Level: At Grade Created by: CK-12

One of the reasons that m-file environments are extensively used by engineers is their capability to provide graphical representations of data and computed values. In this section, we introduced the basics of graphing data in m-file environments through a series of examples. This section uses some fundamental operations on vectors that are explained in Vectors and Arrays in M-File Environments in the chapter Basic Mathematical Computations.

Example 1

Table 1 shows speed as a function of distance for a braking Dodge Viper decelerating from 70 \;\mathrm{MPH} to 0 \;\mathrm{MPH}.

Note: This data was not measured; it was computed using the stopping distance reported for a Dodge Viper (http://www.caranddriver.com/article.asp?section_id=33&article_id=2420&page_number=2) and assuming constant deceleration. Thus, it may not accurately reflect the braking characteristics of a real Dodge Viper.

Dodge Viper Stopping Data.
Distance (ft) Velocity (ft/s)
0 102.7
29.1 92.4
55.1 82.1
78.0 71.9
97.9 61.6
114.7 51.3
128.5 41.1
139.2 30.8
146.9 20.5
151.5 10.3
153.0 0.0

The following commands will create a graph of velocity as a function of distance:

dist = [0 29.1 55.1 78.0 97.9 114.7 128.5 139.2 146.9 151.5 153.0]
vel = [102.7 92.4 82.1 71.9 61.6 51.3 41.1 30.8 20.5 10.3 0.0]

Figure 1 shows the graph created by these commands.

Graph of the Viper's velocity as a function of distance.

Graph of the Viper's velocity as a function of distance.

This graph shows the data, but violates several important conventions of engineering practice. The axes are not labeled with quantities and units, and the graph does not have a title. The following commands, when executed after the plot command, will label the axes and place a title on the graph.

xlabel('Distance (ft)')
ylabel('Velocity (ft/s)')
title('Velocity vs Distance for the Dodge Viper')

The results of these commands are shown in Figure 2.

Graph of the Viper's velocity as a function of distance. The graph has a title and labels on the axes.

After creating a figure, you may wish to insert it into a document. The method to do this depends on the m-file environment, the document editor and the operating system you are using.

MATLAB, Word, and Windows: To paste a figure into a Word document on Windows, pull down the Edit menu of the window of the MATLAB figure you wish to paste, and select Copy Figure. Then go to the Word document into which you wish to insert the figure and use the paste command.

Exercise 1

Repeat Example 1 using the following data for a Hummer H2 (http://www.caranddriver.com/article.asp?section_id=33&article_id=2420&page_number=2).

Note: As in Example 1, this data was not measured; it was computed using the stopping distance reported for a Hummer H2 and assuming constant deceleration.

Distance (ft) Velocity (ft/s)
0 102.7
46.3 92.4
87.8 82.1
124.4 71.9
156.1 61.6
182.9 51.3
204.9 41.1
222.0 30.8
234.2 20.5
241.5 10.3
244.0 0.0

Example 2

An m-file environment can also be used to plot functions. For example, the following commands plot \cos(x) over one period.

x = 0:0.1:2*pi;
title('Plot of cos(x)')

Figure 3 shows the graph created by these commands.

Graph of one period of the cosine function.

Graph of one period of the cosine function.

Exercise 2

Exercise 3 in the chapter Basic Mathematical Computations describes how to compute the terminal velocity of a falling sky diver. Plot the terminal velocity as a function of the sky diver's weight; use weights from 40 \;\mathrm{kg} to 500 \;\mathrm{kg}.

Exercise 3

In electrical circuit analysis, the equivalent resistance R_{eq} of the parallel combination of two resistors R_1 and R_2 is given by the equation

R_{eq} = \tfrac{1} {\tfrac{1}{R_1} + \tfrac{1}{R_2}}

Set R_2 = 1000 \;\mathrm{Ohms} and plot R_{eq} for values of R_1 from 100 \;\mathrm{Ohms} to 3000 \;\mathrm{Ohms}.

Exercise 4

In an experiment, a small steel ball is dropped and its trajectory is recorded using a video camera with a checkered background behind the ball. The video sequence is analyzed to determine the height of the ball as a function of time to give the data in Table 3.

Height and time data for the falling ball.
Time (s) Height (in)
0.0300 22.0
0.0633 21.5
0.0967 20.5
0.1300 18.8
0.1633 17.0
0.1967 14.5
0.2300 12.0
0.2633 8.0
0.2967 3.0

This experimental data is to be compared to the theoretically expected values given by the following equation:

h = 22 - \tfrac{1}{2}gt^2

where h is in inches, t is in seconds,and g = 386.4 \tfrac{in}{s^2}. Create a graph that compares the measured data with the theoretically expected values; your graph should conform to good conventions for engineering graphics. Plot the measured data using red circles, and plot the theoretically expected values using a blue line.

Image Attributions

Files can only be attached to the latest version of None


Please wait...
Please wait...
Image Detail
Sizes: Medium | Original

Original text