4.1: Introduction to Graphing in MFile Environments
One of the reasons that mfile 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 mfile environments through a series of examples. This section uses some fundamental operations on vectors that are explained in Vectors and Arrays in MFile 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
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.
Distance (ft)  Velocity (ft/s) 






















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]

plot(dist,vel)
Figure 1 shows the graph created by these commands.
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 mfile 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
Note: As in Example 1, this data was not measured; it was computed using the stopping distance reported for a Hummer
Distance (ft)  Velocity (ft/s) 






















Example 2
An mfile environment can also be used to plot functions. For example, the following commands plot

x = 0:0.1:2*pi;

y=cos(x);

plot(x,y);

xlabel('x')

ylabel('cos(x)')

title('Plot of cos(x)')
Figure 3 shows the graph created by these commands.
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
Exercise 3
In electrical circuit analysis, the equivalent resistance
\begin{align*}R_{eq} = \tfrac{1} {\tfrac{1}{R_1} + \tfrac{1}{R_2}}\end{align*}
Set \begin{align*}R_2 = 1000 \;\mathrm{Ohms}\end{align*} and plot \begin{align*}R_{eq}\end{align*} for values of \begin{align*}R_1\end{align*} from \begin{align*}100 \;\mathrm{Ohms}\end{align*} to \begin{align*}3000 \;\mathrm{Ohms}\end{align*}.
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.
Time (s)  Height (in) 

\begin{align*}0.0300\end{align*}  \begin{align*}22.0\end{align*} 
\begin{align*}0.0633\end{align*}  \begin{align*}21.5\end{align*} 
\begin{align*}0.0967\end{align*}  \begin{align*}20.5\end{align*} 
\begin{align*}0.1300\end{align*}  \begin{align*}18.8\end{align*} 
\begin{align*}0.1633\end{align*}  \begin{align*}17.0\end{align*} 
\begin{align*}0.1967\end{align*}  \begin{align*}14.5\end{align*} 
\begin{align*}0.2300\end{align*}  \begin{align*}12.0\end{align*} 
\begin{align*}0.2633\end{align*}  \begin{align*}8.0\end{align*} 
\begin{align*}0.2967\end{align*}  \begin{align*}3.0\end{align*} 
This experimental data is to be compared to the theoretically expected values given by the following equation:
\begin{align*}h = 22  \tfrac{1}{2}gt^2\end{align*}
where \begin{align*}h\end{align*} is in inches, \begin{align*}t\end{align*} is in seconds,and \begin{align*}g = 386.4 \tfrac{in}{s^2}\end{align*}. 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.
Notes/Highlights Having trouble? Report an issue.
Color  Highlighted Text  Notes  

Please Sign In to create your own Highlights / Notes  
Show More 