Evaluating Expressions: Unary Operators
Evaluating Expressions: Unary Operators
It is
recommended
that you try all the examples in this guide.
If you get into trouble, you can usually interrupt a MATLAB process by typing Control-C
(usually written C-c for short). C-c gets its name from the fact that you type it by holding
down
CTRL and then pressing c. You will normally return the MATLAB prompt.
To exit MATLAB, type quit or exit at the prompt. You can also exit by clicking on the X in
the
upper right corner. (MATLAB functions like Windows-based programs.)
A great deal of work can be accomplished in the MATLAB command environment.
However,
there are other screens that can be accessed that can help productivity.
Evaluating Expressions
Expressions are evaluated by entering them after the >> followed by a carriage return.
MATLAB
displays the values preceded by “ans =”.
MATLAB follows the algebraic order of operations. Unary operators have right associativity
and
binary operators have left associativity.
Unary Operators
+ (positive)
- (negative)
Binary Operators
+ (addition)
- (subtraction)
* (multiplication) (Multiplication is not inferred.)
/ (left-hand division)
\ (right-hand division)
^ (exponent)
( ) (only grouping symbols allowed.)
>> 2 + 5 – 3
ans =
4
>> ans – 3
ans =
1
>> a = 12, b = 5
a =
12