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

(Steven Felgate) #1
Note that in MATLAB language, the range is defined by a starting value, followed by a
colon :, the increment followed by another colon, and the end value. As another example, if
you were to type

Countdown = 5:-1:0


then the countdown row matrix will consist of values 5 4 3 2 1 0.


Creating Formulas in MATLAB


As we have said before, engineers use formulas that represent physical and chemical laws gov-
erning our surroundings to analyze various problems. You can use MATLAB to input engi-
neering formulas and compute the results. When typing your formula, use parentheses to dictate
the order of operation. For example, in MATLAB’s Command Window, if you were to type
count=100+5*2, MATLAB will perform the multiplication first, which results in a value
of 10, and then this result is added to 100, which yields an overall value of 110 for the variable
count. If, however, you wanted MATLAB to add the 100 to 5 first and then multiply the re-
sulting 105 by 2, you should have placed parentheses around the 100 and 5 in the following
manner count=(100+5)*2, which results in a value of 210. The basic MATLAB arith-
metic operations are shown in Table 15.3.

Element by Element Operation


In addition to basic scalar (arithmetic) operations, MATLAB provides element-by-element op-
erations and matrix operations. MATLAB’s symbols for element-by-element operations are
shown in Table 15.4. To better understand their use, suppose you have measured and recorded
the mass (kg) and speed (m/s) of 5 runners who are running along a straight path: m 
[60 55 70 68 72]and s [4 4.5 3.8 3.6 3.1]. Note that the mass marray and speed sarray
each have 5 elements. Now suppose you are interested in determining the magnitude of each
runner’s momentum. We can calculate the momentum for each runner using MATLAB’s
element-by-element multiplication operation in the following manner: momentum m.*s
resulting in momentum [240 247.5 266 244.8 223.2]. Note the multiplication symbol (.*)
for element-by-element operation.
To improve your understanding of the element-by-element operations, in the MATLAB’s
Command Window type a [7 4 3 1]and b [1, 3,5, 7]and then try the following
operations.

15.1 MATLAB —Basic Ideas 467


TABLE 15.3 The Basic MATLAB Arithmetic Operations


z, the Result
of the Formula
Example: x10 Given in the
Operation Symbol and y 2 Example

Addition  zxy 20 32
Subtraction  zxy8
Multiplication * z(x*y) 929
Division / z(x /2.5)y6
Raised to a power ^ z(x^y)^0.5 10

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