Skip to main content

Section A.1 Glossary of Select MATLAB Commands

Subsection A.1.1 Mathematical Operations

+ Addition. Type help plus for information.
- Subtraction. Type help minus for information.
* Scalar or matrix multiplication. Type help mtimes for information.
/ Scalar or right matrix division. Type help slash for information. For matrices, the command A/B is equivalent to A*inv(B).
^ Scalar or matrix powers. Type help mpower for information.
.* Element by element multiplication. Type help times for information.
.^ Element by element exponentiation. Type help power for information.
./ Element by element division.

Subsection A.1.2 Built-in Mathematical Constants

eps Machine epsilon, i.e. approximately the computer’s floating point roundoff error.
i \(\sqrt{-1}\text{.}\)
Inf \(\infty\text{.}\)
NaN Not a number. Indicates an invalid operation such as \(0/0\text{.}\)
pi \(\pi = 3.14159 \ldots\text{.}\)

Subsection A.1.3 Built-in Mathematical Functions

abs(x) Absolute value \(|x|\text{.}\)
acos(x) Inverse cosine \(\arccos{x}\text{.}\)
asin(x) Inverse sine \(\arcsin{x}\text{.}\)
atan(x) Inverse tangent \(\arctan{x}\text{.}\)
cos(x) Cosine \(\cos{x}\text{.}\)
cosh(x) Hyperbolic cosine \(\cosh{x}\text{.}\)
cot(x) Cotangent \(\cot{x}\text{.}\)
exp(x) Exponential function \(e^{x} = \exp{x}\text{.}\)
log(x) Natural logarithm \(\ln{x}= \log_{e}{x}\text{.}\)
sec(x) Secant \(\sec{x}\text{.}\)
sin(x) Sine \(\sin{x}\text{.}\)
sinh(x) Hyperbolic sine \(\sinh{x}\text{.}\)
sqrt(x) Square root \(\sqrt{x}\text{.}\)
tan(x) Tangent \(\tan{x}\text{.}\)
tanh(x) Hyperbolic tangent \(\tanh{x}\text{.}\)
max Computes maximum of the rows of a matrix.
mean Computes the average of the rows of a matrix.
min Computes the minimum of the rows of a matrix.

Subsection A.1.4 Built-in Numerical Mathematical Operations

fzero Tries to find a zero of the specified function near a starting point or on a specified interval.
inline Define a function in the command window.
ode113 Numerical multiple step ODE solver.
ode45 Runga-Kutta 45 numerical ODE solver.
quad Numerical integration using an adaptive Simpson’s rule.
dblquad Double integration.
triplequad Triple integration.

Subsection A.1.5 Built-in Symbolic Mathematical Operations

collect Collects powers of the specified variable is a given symbolic expression.
compose Composition of symbolic functions.
diff Symbolic differentiation.
double Displays double-precision representation of a symbolic expression.
dsolve Symbolic ODE solver.
expand Expands an algebraic expression.
factor Factor a polynomial.
int Symbolic integration; either definite or indefinite.
limit Finds two-sided limit, if it exists.
pretty Displays a symbolic expression in a nice format.
simple Simplifies a symbolic expression.
subs Substitutes for parts a a symbolic expression.
sym or syms Create symbolic variables.
symsum Performs a symbolic summation, possibly with infinitely many entries.
taylor Gives a Taylor polynomial approximation of a given order at a specified point.

Subsection A.1.6 Graphics Commands

contour Plots level curves of a function of two variables.
contourf Filled contour plot.
ezcontour Easy contour plot.
loglog Creates a log-log plot.
mesh Draws a mesh surface.
meshgrid Creates arrays that can be used as inputs in graphics commands such as contour, mesh, quiver, and surf.
ezmesh Easy mesh surface plot.
plot Plots data vectors.
ezplot Easy plot for symbolic functions.
plot3 Plots curves in 3-D.
polar Plots in polar coordinates.
quiver Plots a vector field.
semilogy Semilog plot, with logarithmic scale along the vertical direction.
surf Solid surface plot.
trimesh Plot based on a triangulation
trisurf Surface plot based on a triangulation

Subsection A.1.7 Special MATLAB Commands

: Range operator, used for defining vectors and in loops. Type help colon for information.
; Suppresses output. Also separates rows of a matrix.
= Assigns the variable on the left hand side the value of the right hand side.
ans The value of the most recent unassigned.
cd Change directory.
clear Clears all values and definitions of variables and functions. You may also use to clear only specified variables.
diary Writes a transcript of a MATLAB session to a file.
dir Lists the contents in the current working directory. Same as ls.
help
inline Define an inline function.
format Specifies output format, e.g. format long.
load Load variables from a file.
save Saves workspace variables to a file.

Subsection A.1.8 MATLAB Programming

== Is equal?
~= Is not equal?
< Less than?
> Greater than?
<= Less than or equal?
break Breaks out of a for or while loop.
end Terminates an if, for or while statement.
else Alternative in an if statement.
error Displays and error message and ends execution of a program.
for Repeats a block of commands a specified number of times.
function First word in a function program.
if Checks a condition before executing a block of statements.
return Terminates execution of a program.
warning Displays a warning message.
while Repeats a block of commands as long as a condition is true.

Subsection A.1.9 Commands for Matrices and Linear Algebra

Matrix arithmetic:
A = [ 1 3 -2 5 ; -1 -1 5 4 ; 0 1 -9 0] Manually enter a matrix.
u = [ 1 2 3 4]'
A*u
B = [3 2 1; 7 6 5; 4 3 2]
B*A multiply \(B\) times \(A\text{.}\)
2*A multiply a matrix by a scalar.
A + A add matrices.
A + 3 add a number to every entry of a matrix.
B.*B component-wise multiplication.
B.^3 component-wise exponentiation.
Special matrices:
I = eye(3) identity matrix
D = ones(5,5)
O = zeros(10,10)
C = rand(5,5) random matrix with uniform distribution in \([0,1]\text{.}\)
C = randn(5,5) random matrix with normal distribution.
hilb(6)
pascal(5)
General matrix commands:
size(C) gives the dimensions (\(m \times n\)) of \(A\text{.}\)
norm(C) gives the norm of the matrix.
det(C) the determinant of the matrix.
max(C) the maximum of each row.
min(C) the minimum in each row.
sum(C) sums each row.
mean(C) the average of each row.
diag(C) just the diagonal elements.
inv(C) inverse of the matrix.
Matrix decompositions:
[L U P] = lu(C)
[Q R] = qr(C)
[U S V] = svd(C) singular value decomposition.