15.1 MATLAB —Basic Ideas 469
■Figure 15.4 The result of Example 14.1. (Revisited).
Using MATLAB, we want to create a table that shows the density of air as a function of tem-
perature in the range of 0C (273.15 K) to 50C (323.15 K) in increments of 5C.
In the MATLAB’s Command Window, we type the following commands.
>> Temperature = 0:5:50;
>> Density = 101300./((286.9)*(Temperature+273));
>> fprintf('\n\n');disp(' Temperature(C)
Density(kg/m^3)');disp([Temperature',Density'])
In the commands just shown, the semicolon ;suppresses MATLAB’s automatic display ac-
tion. If you type Temperature = 0:5:50without the semicolon at the end, MATLAB will
display the values of temperature in a row. It will show
Temperature =
0 5 10 15 20 25 30 35 40 45 50
The ./is a special element by element division operation that tells MATLAB to carry the
division operation for each temperature value.
In the dispcommand, the prime or the single quotation mark over the variables
Temperature'and Density'will change the values of the temperature and the density,
which are stored in rows, to column format before they are displayed. In matrix operations, the
process of changing the rows into columns is called the Transpose of the matrix. The final results
for Example 14.1 (Revisited) are shown in Figure 15.4. Note that the values of the temperature
and the density are shown in columns. Also note the use of the fprintfand dispcommands.
Matrix Operations
MATLAB offers many tools for matrix operations and manipulations. Table 15.5 shows ex-
amples of these capabilities. We will explain MATLAB’s matrix operations in more detail in
Section 15.5.
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).
圀圀圀⸀夀䄀娀䐀䄀一倀刀䔀匀匀⸀䌀伀䴀圀圀圀⸀夀䄀娀䐀䄀一倀刀䔀匀匀⸀䌀伀䴀