matlab file

Page 239

220

Chapter 11: Troubleshooting

again. (The UP-ARROW key or Command History window is useful for recalling the command to edit it.) Do not rely on ans as it is likely to be overwritten before you execute the command that references the prior output. CAUSE:

Improper use of built-in functions.

SOLUTION:

Always use the names of built-in functions exactly as MATLAB specifies them; always enclose inputs in parentheses, not brackets and not braces; always list the inputs in the required order.

☞ See Managing Variables and Online Help in Chapter 2. CAUSE:

Inattention to precedence of arithmetic operations.

SOLUTION:

Use parentheses liberally and correctly when entering arithmetic or algebraic expressions.

EXAMPLE:

MATLAB, like any calculator, first exponentiates, then divides and multiplies, and finally adds and subtracts, unless a different order is specified by using parentheses. So if you attempt to compute 52/3 − 25/(2 ∗ 3) by typing >> 5ˆ2/3 - 25/2*3 ans = -29.1667

the answer MATLAB produces is not what you intended because 5 is raised to the power 2 before the division by 3, and 25 is divided by 2 before the multiplication by 3. Here is the correct calculation: >> 5ˆ(2/3) - 25/(2*3) ans = -1.2426

Syntax Error CAUSE:

Mismatched parentheses, quote marks, braces, or brackets.

SOLUTION:

Look carefully at the input line to find a missing or an extra delimiter.

MATLAB usually catches this kind of mistake. In addition, the MATLAB 6 Desktop automatically highlights matching delimiters as you type and color-codes strings (expressions enclosed in single quotes) so that you can see


Issuu converts static files into: digital portfolios, online yearbooks, online catalogs, digital photo albums and more. Sign up and create your flipbook.