MATLAB has many
arithmetic operations and functions built in. Most of them are
straightforward to use. The Table below lists some commonly used
scalar operations; in this table, x and y are scalars. (A scalar is a single number.)
| Operation | MATLAB |
|---|---|
x-y |
|
x+y |
|
x*y |
|
x/y |
|
x^y |
|
exp(x) |
|
log10(x) |
|
log(x) |
|
log2(x) |
Expressions are formed from numbers, variables, and these operations. The operations have different precedences. The ^ operation has the highest precedence; ^ operations are evaluated before any other operations. Multiplication and division have the next highest precedence, and addition and subtraction have the lowest precedence. Precedence is altered by parentheses; expressions within parenthesesare evaluated before expressions outside parentheses.
Example 1
The Table below shows several mathematical formulas, the corresponding MATLAB expressions, and the values that MATLAB would compute for the expressions.
| formula | MATLAB Expression | Computed Value |
|---|---|---|
|
|
5^2+4^2 |
41 |
|
|
(5+4)^2 |
81 |
|
|
(2 + 3)/(4 - 5) |
-5 |
|
|
log10(100) |
2 |
|
|
log(4*(2+3)) |
2.9957 |




