Engineering Fundamentals: An Introduction to Engineering, 4th ed.c

(Steven Felgate) #1

480 Chapter 15 MATLAB


15.3 Plotting with MATLAB


MATLAB offers many choices when it comes to creating charts. For example, you can create
x–ycharts, column charts (or histograms), contour, or surface plots. As we mentioned in Chap-
ter 14, as an engineering student, and later as a practicing engineer, most of the charts that you
will create will be x–ytype charts. Therefore, we will explain in detail how to create an x–y
chart.

Example 15.4 Starting with a 10 cm10 cm sheet of paper, what is the largest volume you can create
by cutting outxcmxcm from each corner of the sheet and then folding up the sides? See
Figure 15.11. Use MATLAB to obtain the solution.
The volume created by cutting outxcmxcm from each corner of the 10 cm10 cm
sheet of paper is given byV(10  2 x)(10  2 x)x. Moreover, we know that, forx0 and
x5, the volume will be zero. Therefore, we need to create a range ofxvalues from 0 to 5 using
some small increments, such as 0.1. We then plot the volume versusxand look for the maxi-
mum value of volume. The MATLAB commands that lead to the solution are:

>> x = 0:0.1:5;
>> volume = (10-2*x).*(10-2*x).*x;
>> plot (x,volume)
>> title ('Volume as a function of x')
>> xlabel ('x (cm)')
>> ylabel ('Volume (cm^3)')
>> grid minor
>>

10 2 x


10 2 x


10 cm


10 cm


x


x


■Figure 15.11
The 10 cm 10 cm sheet in
Example 15.4.

■Figure 15.12 The MATLAB Command Window for Example 15.4.


The MATLAB Command Window for Example 15.4 is shown in Figure 15.12. The plot
of volume versusxis shown in Figure 15.13.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).

圀圀圀⸀夀䄀娀䐀䄀一倀刀䔀匀匀⸀䌀伀䴀圀圀圀⸀夀䄀娀䐀䄀一倀刀䔀匀匀⸀䌀伀䴀

Free download pdf