Getting Started |
Functions
MATLAB provides a large number of standard elementary mathematical functions, including abs
, sqrt
, exp
, and sin
. Taking the square root or logarithm of a negative number is not an error; the appropriate complex result is produced automatically. MATLAB also provides many more advanced mathematical functions, including Bessel and gamma functions. Most of these functions accept complex arguments. For a list of the elementary mathematical functions, type
For a list of more advanced mathematical and matrix functions, type
Some of the functions, like sqrt
and sin
, are built in. They are part of the MATLAB core so they are very efficient, but the computational details are not readily accessible. Other functions, like gamma
and sinh
, are implemented in M-files. You can see the code and even modify it if you want.
Several special functions provide values of useful constants.
pi |
3.14159265... |
i |
Imaginary unit, -1 |
j |
Same as |
eps |
Floating-point relative precision, 2-52 |
realmin
|
Smallest floating-point number, 2-1022 |
realmax |
Largest floating-point number, (2-)21023 |
Inf |
Infinity |
NaN |
Not-a-number |
Infinity is generated by dividing a nonzero value by zero, or by evaluating well defined mathematical expressions that overflow, i.e., exceed realmax
. Not-a-number is generated by trying to evaluate expressions like 0/0
or Inf
-Inf
that do not have well defined mathematical values.
The function names are not reserved. It is possible to overwrite any of them with a new variable, such as
and then use that value in subsequent calculations. The original function can be restored with
Operators | Examples of Expressions |