Graphics Programs Reference
In-Depth Information
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.
Improper use of built-in functions.
CAUSE:
SOLUTION: Always use the names of built-in functions exactly as MATLAB specifies
them;alwaysencloseinputsinparentheses,notbracketsandnotbraces;
always list the inputs in the required order.
See Managing Variables and Online Help in Chapter 2.
Inattention to precedence of arithmetic operations.
CAUSE:
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 5 2 / 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
Mismatched parentheses, quote marks, braces, or brackets.
CAUSE:
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
Search WWH ::




Custom Search