Inside Collection (Course): Freshman Engineering Problem Solving with MATLAB
Summary: This module provides a tutorial introduction to graphing data in m-file environments.
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 module, we introduced the basics of graphing data in m-file environments through a series of examples. This module uses some fundamental operations on vectors that are explained in Vectors and Arrays in M-File Environments.
The table below shows speed as a function of distance for a braking Dodge Viper decelerating from 70MPH to 0MPH.
| 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 |
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)
|
xlabel('Distance (ft)')
ylabel('Velocity (ft/s)')
title('Velocity vs Distance for the Dodge Viper')
|
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.
Repeat Example 1 using the following data for a Hummer H2:
| 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 |
Figure 3 shows the graph of the Hummer H2 stopping data.
|
An m-file 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)')
|
The module Exercises for Basic Mathematical Operations 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 40kg to 500kg.
In electrical circuit analysis, the equivalent resistance
In an experiment, a small steel ball is dropped and videoed against a checkered background. The video sequence is analyzed to determine the height of the ball as a function of time to give the data in the following table:
| 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 |