Appendix A

MATLAB Functions

This appendix provides you with an overview of the MATLAB functions. It would be impossible to provide a complete list of every function here, but these functions see common use for solving math problems. To see an exhaustive list of MATLAB functions, check out https://www.mathworks.com/help/matlab/referencelist.html?type=function.

Each function helps you perform a specific task within MATLAB. Tables A-1 through A-21 contain function names and a short description of the task that each function performs. If you need more information than this appendix gives you, you can obtain additional information by typing help <function_name> in the MATLAB command window and pressing Enter. Of course, you also have the information found in this book, and you can search in Help. See the “Getting additional help with MATLAB” section of Chapter 2 for some useful information on using the Help resources that MATLAB provides.

TABLE A-1 Arithmetic Functions

Function

Description

ceil

Rounds toward positive infinity

diff

Differences and approximate derivatives

fix

Rounds toward zero

floor

Rounds toward negative infinity

idivide

Integer division with rounding option

ldivide

Left-array division — comparable to .\

minus

Minus — comparable to – subtracting two objects

mldivide

Solves systems of linear equations Ax = B for x — comparable to \

mod

Modulus after division

mpower

Matrix power — comparable to ^

mrdivide

Solves systems of linear equations xA = B for x — comparable to /

mtimes

Matrix multiplication — comparable to *

plus

Plus — comparable to + adding two objects

power

Array power — comparable to .^

prod

Product of array elements

rdivide

Right-array division — comparable to ./

rem

Remainder after division

round

Rounds to nearest integer

sum

Sum of array elements

times

Array multiply — comparable to .*

uminus

Unary minus — comparable to – acting on one object

uplus

Unary plus — comparable to + acting on one object

TABLE A-2 Trigonometric Functions

Function

Description

acos

Inverse cosine; result in radians

acosd

Inverse cosine; result in degrees

acosh

Inverse hyperbolic cosine

acot

Inverse cotangent; result in radians

acotd

Inverse cotangent; result in degrees

acoth

Inverse hyperbolic cotangent

acsc

Inverse cosecant; result in radians

acscd

Inverse cosecant; result in degrees

acsch

Inverse hyperbolic cosecant

asec

Inverse secant; result in radians

asecd

Inverse secant; result in degrees

asech

Inverse hyperbolic secant

asin

Inverse sine; result in radians

asind

Inverse sine; result in degrees

asinh

Inverse hyperbolic sine

atan

Inverse tangent; result in radians

atan2

Four-quadrant inverse tangent in radians

atan2d

Four-quadrant inverse tangent; result in degrees

atand

Inverse tangent; result in degrees

atanh

Inverse hyperbolic tangent

cos

Cosine of argument in radians

cosd

Cosine of argument in degrees

cosh

Hyperbolic cosine

cot

Cotangent of argument in radians

cotd

Cotangent of argument in degrees

coth

Hyperbolic cotangent

csc

Cosecant of argument in radians

cscd

Cosecant of argument in degrees

csch

Hyperbolic cosecant

hypot

Square root of sum of squares

sec

Secant of argument in radians

secd

Secant of argument in degrees

sech

Hyperbolic secant

sin

Sine of argument in radians

sind

Sine of argument in degrees

sinh

Hyperbolic sine of argument in radians

tan

Tangent of argument in radians

tand

Tangent of argument in degrees

tanh

Hyperbolic tangent

TABLE A-3 Exponentials, Logarithms, Powers, and Roots

Function

Description

exp

Exponential

expm1

Computes exp(x)–1 accurately for small values of x

log

Natural logarithm

log10

Common (base 10) logarithm

log1p

Computes log(1+x) accurately for small values of x

log2

Determines base 2 logarithm and dissects floating-point numbers into exponent and mantissa

nextpow2

Computes the exponent of the next higher power of 2

nthroot

Real nth root of real numbers

pow2

Base 2 power and scale floating-point numbers

reallog

Natural logarithm for nonnegative real arrays

realpow

Array power for real-only output

realsqrt

Square root for nonnegative real arrays

sqrt

Square root

TABLE A-4 Complex Number Functions

Function

Description

abs

Absolute value and complex magnitude

angle

Phase angle

complex

Construct complex data from real and imaginary components

conj

Complex conjugate

cplxpair

Sorts complex numbers into complex conjugate pairs

i

Imaginary unit

imag

Imaginary part of complex number

isreal

Checks whether input is a real array

j

Imaginary unit

real

Real part of complex number

sign

The sign() (or signum) function returns 1 if the corresponding element is greater than 0, 0 if the corresponding element is zero, and –1 if the corresponding element is less than 0

unwrap

Shifts the phase angles of vector P

TABLE A-5 Discrete Math Functions

Function

Description

factor

Prime factors

factorial

Factorial function

gcd

Greatest common divisor

isprime

Array elements that are prime numbers

lcm

Least common multiple

matchpairs

Solves a linear assignment problem

nchoosek

Binomial coefficient or all combinations

perms

All possible permutations

primes

Generates list of prime numbers

rat, rats

Rational fraction approximation

TABLE A-6 Polynomial Functions

Function

Description

poly

Polynomial with specified roots

polyder

Polynomial derivative

polyeig

Polynomial eigenvalue problem

polyfit

Polynomial curve fitting

polyint

Integrates the polynomial analytically

polyval, polyvalm

Polynomial evaluation

roots

Polynomial roots

TABLE A-7 Special Functions

Function

Description

erf

Error function

erfc

Complementary error function

erfcinv

Inverse complementary error function

erfcx

Scaled complementary error function

erfinv

Inverse error function

TABLE A-8 Cartesian, Polar, and Spherical Functions

Function

Description

cart2pol

Transforms Cartesian coordinates to polar or cylindrical coordinates

cart2sph

Transforms Cartesian coordinates to spherical coordinates

pol2cart

Transforms polar or cylindrical coordinates to Cartesian coordinates

sph2cart

Transforms spherical coordinates to Cartesian coordinates

TABLE A-9 Constants and Test Matrix Functions

Function

Description

compan

Returns the corresponding companion matrix

eps

Floating-point relative accuracy

i,j

Imaginary units

Inf

Infinity

pi

Ratio of circle’s circumference to its diameter

NaN

Not-a-Number

isfinite

Array elements that are finite

isinf

Array elements that are infinite

isnan

Array elements that are NaN

gallery

Test matrices

magic

Magic square

TABLE A-10 Matrix Operation Functions

Function

Description

cross

Vectors cross product

ctranpose

Performs complex conjugate transpose

dot

Vectors dot product

funm

Evaluates a general matrix function

kron

Kronecker tensor product

transpose

Transposes

TABLE A-11 Linear Equation Functions

Function

Description

inv

Matrix inverse

linsolve

Solves linear system of equations

TABLE A-12 Eigenvalue Functions

Function

Description

eig

Eigenvalues and eigenvectors

eigs

Largest eigenvalues and eigenvectors of matrix

TABLE A-13 Matrix Analysis Functions

Function

Description

det

Matrix determinant

norm

Vector and matrix norms

rank

Rank of matrix

rref

Reduced row echelon form

trace

Sum of diagonal elements

TABLE A-14 Matrix Functions

Function

Description

arrayfun

Applies function to each element of array

expm

Matrix exponential

logm

Matrix logarithm

sqrtm

Matrix square root

TABLE A-15 Statistical Functions

Function

Description

bounds

Obtains the smallest and largest elements of an array

corrcoef

Correlation coefficients

cov

Covariance matrix

max, maxk

Largest elements in array

mean

Average or mean value of array

median

Median value of array

min, mink

Smallest elements in array

mode

Most frequent values in array

std

Standard deviation

var

Variance

TABLE A-16 Random Number Generator

Function

Description

rng

Controls random number generation

rand

Uniformly distributed pseudo-random numbers

randn

Normally distributed pseudo-random numbers

randi

Uniformly distributed pseudo-random integers

TABLE A-17 Interpolation

Function

Description

interp1

1-D data interpolation (table lookup)

interp2

2-D data interpolation (table lookup)

interp3

3-D data interpolation (table lookup)

interpn

nD data interpolation (table lookup)

griddedInterpolant

Interpolant for gridded data

griddata

Interpolates scattered data

ndgrid

Rectangular grid in nD space

meshgrid

Rectangular grid in 2D and 3D space

spline

Cubic spline data interpolation

TABLE A-18 Optimization Functions

Function

Description

fminbnd

Finds minimum of single-variable function on fixed intervals

fminsearch

Finds minimum of unconstrained multivariable function using derivative-free method

fzero

Finds root of continuous function of one variable

lsqnonneg

Solves a non-negative linear least-squares problem

TABLE A-19 Ordinary Differential Equation Functions

Function

Description

ode23, ode45, ode113

Solve nonstiff differential equations

ode15s, od23s, ode23t, od23tb

Solve stiff differential equations

ode15i, decic

Solve fully implicit differential equations

TABLE A-20 Sparse Matrix Manipulation Functions

Function

Description

spy

Visualizes a sparsity pattern

find

Finds indices and values of nonzero elements

TABLE A-21 Elementary Polygons

Function

Description

polyarea

Area of polygon

inpolygon

Determines whether points are inside or on the edges of a polygon

rectint

Rectangle intersection area

If you find an error or have any questions, please email us at admin@erenow.org. Thank you!