In addition to the standard arithmetic operators,
MATLAB provides an extensive collection of built-in functions.
For example, most elementary mathematical functions
(sin, cos, log, sqrt,
) are available.
>> cos(pi/4)
ans = 7.0711e-01pi is an example of a function that does not require parameters and simply returns a commonly used constant.
ans =
3.1416
Other functions are available in libraries of M-files grouped into
toolboxes. Section 11 briefly describes
how to create your own functions.
So far we have only seen functions that return a single matrix, but some
functions return two or more matrices. To save these matrices, we surround
the output variables by brackets [ ] and separate them by commas.
For example,
>> [V,D] = eig(A)
returns the eigenvectors and eigenvalues of A in matrices V and D.
Several additional MATLAB functions are described in the remainder of this guide. For extensive lists of MATLAB functions consult the MATLAB primer or explore the list of topics provided by entering the command help with no arguments. In addition, the MATLAB demos provide examples of the use of many interesting functions.