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

(Steven Felgate) #1
MATLAB also provides the elseifcommand that could be used with the ifand elsestate-
ments. It is left for you to learn about it. Try the MATLAB help menu: type help elseifto learn
about the elseif statement.

Example 14.5 The pipeline shown in Figure 15.7 is connected to a control (check) valve that opens when
(Revisited) the pressure in the line reaches 20 psi. Various readings were taken at different times and
recorded. Using MATLAB’s logical functions, create a list that shows the corresponding open
and closed positions of the check valve.

15.2 Using MATLAB Built-in Functions 477


■Figure 15.7
A schematic diagram for
Example 14.5 (Revisited).

■Figure 15.8
The solution of Example
14.5 (Revisited).

The solution to Example 14.5 (Revisited) is shown in Figure 15.8. The commands lead-
ing to the solution are:

>> pressure=[20 18 22 26 19 19 21 12];
>> fprintf('\t Line Pressure (psi) \t Valve Position\n\n');
for i=1:8
if pressure(i) >=20
fprintf('\t %g \t\t\t\t\t OPEN\n',pressure(i))
else
fprintf('\t %g \t\t\t\t\t CLOSED\n',pressure(i))
end
end

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