Glossary for Differential Equations with MATLAB, 3rd edition

This glossary is divided into the following sections:

  1. MATLAB Operators: the special symbols used by MATLAB,
  2. MATLAB Commands: commands that manipulate data or expressions, or that initiate a process,
  3. Built-in Functions: basic mathematical functions that can be evaluated or plotted,
  4. Graphics Commands: commands using in creating or modifying figures,
  5. Built-in Constants,
  6. MATLAB Programming: commands used for programming and structuring M-files,
  7. Simulink Blocks: the Simulink blocks most useful for the Simulink problems in this book. For a more extensive listing of Simulink blocks, see the Simulink documentation.
  8. Useful MuPAD Commands: for using MuPAD directly (rather than through the Symbolic Math Toolbox interface).

The distinction among these various categories, especially among commands and programming constructs, is somewhat artificial.

Each item is followed by a brief description of its effect and then (in most cases) one or more examples. To get more information on a command, you can use the help command or the Help Browser. This glossary is not a comprehensive list of MATLAB commands, but it includes the commands most useful for studying differential equations.

MATLAB Operators

@
Marker for a function handle, used to refer to a built-in function or to create an anonymous function.
  f = @(x, y) x.^2.*y + y.^2
  quadl(@atan, 0, 1)
\
Left matrix division. X = A\B is the solution of A*X = B. Type help slash for more information.
    A = [1 0; 2 1]; B = [3; 5]; A\B
/
Ordinary division or right matrix division. Type help slash for more information.
./
Element-by-element division of arrays. Type help rdivide for more information.
*
Scalar or matrix multiplication, depending on context. Type help mtimes for more information.
.*
Element-by-element multiplication of arrays. Type help times for more information.
^
Scalar or matrix power, depending on context. Type help mpower for more information.
.^
Element-by-element power. Type help power for more information.
:
Range operator, used for defining vectors. Type help colon for more information.
'
Single quote mark, used for beginning and ending strings. Also used to denote the conjugate transpose of a matrix (see ctranspose).
.'
Denotes the transpose of a matrix (see also transpose).
;
Suppresses output of a MATLAB command. Also used to separate rows of a matrix.
    X = 0:0.1:30;
    A = [1 2 3; 4 5 6; 7 8 9]
...
Line continuation operator. Cannot be used inside strings.
    1 + 3 + 5 + 7 + 9 + 11 ...
        + 13 + 15 + 17
    ['This is a way to create very long strings ', ...
        'that span more than one line. Note the ', ...
        'square brackets.']

MATLAB Commands

addpath
Adds the specified directory to MATLAB's file search path.
    addpath('C:\my_mfiles')
    addpath C:\my_mfiles
ans
A variable holding the value of the most recent unassigned output.
bvp4c
Boundary value problem solver. Usually requires use of bvpinit to set the ``initial guess'' argument. The example below solves and plots the solution of y''+y=0 with boundary values y(0)=0, y(π/2)=1.
    solinit = bvpinit((0:0.1:1)*pi/2, [1, 0]);
    sol = bvp4c(@(x, y) [y(2); –y(1)], ...
        @(ya, yb) [ya(1); yb(1) – 1], solinit);
    plot(sol.x, sol.y(1,:))
cd
Makes the specified directory the current (working) directory.
    cd C:\mydocs\mfiles
char
Converts a symbolic expression to a string. Useful for defining inline functions or for defining input to dsolve.
    syms x y
    f = inline(char(sin(x)*sin(y)), 'x', 'y')
clear
Clears values and definitions for variables and functions. If you specify one or more variables, then only those variables are cleared.
    clear
    clear f, g
collect
Collects coefficients of powers of the specified symbolic variable in a given symbolic expression.
    syms x y
    collect(x^2 – 2*x^2 + 3*x + x*y, x)
conj
Gives the complex conjugate of a complex number.
    conj(2 + 3*i)
ctranspose
Conjugate transpose of a matrix. Usually invoked with the ' operator. Equivalent to transpose for real matrices.
    A = [1 3 i]; A'
D
Not a true MATLAB command. Used in the dsolve command to denote differentiation. See diff.
    dsolve('t*Dy + y = sin(t)')
deal
Distributes its arguments to different variables.
    [r, t] = deal(sqrt(x^2 + y^2), atan2(y, x))
delete
Deletes a file from the disk.
    delete filename
det
The determinant of a matrix.
    det([1 3; 4 5])
deval
Evaluates a numerical solution to an ODE at specified points.
    sol = ode45(@(t, y) t.*y, [0, 5], 1)
    deval(sol, 1)
diff
Symbolic differentiation operator (and difference operator).
    syms x; diff(x^3)
    syms x y; diff(x*y^2, y)
dir
Lists the files in a directory.
disp
Displays a string or the value of a variable.
    disp('The answer is:'), disp(a)
doc
Displays details about a specific command in the Help Browser.
    doc print
double
Gives a double precision value for either a numeric or symbolic quantity. Applied to a string, double returns a vector of ASCII codes for the characters in the string.
    z = sym('pi'); double(z)
dsolve
Symbolic ODE solver. By default, the independent variable is t, but a different variable can be specified as the last argument. The input must be a string, not a symbolic expression.
    dsolve('D2y – t*y = 0')
    dsolve('Dy + y^2 = 0', 'y(0) = 1', 'x')
    [x, y] = dsolve('Dx = 2*x + y', 'Dy = – x')
echo
Turns on or off the echoing of commands inside script M-files.
edit
Opens an M-file in the Editor/Debugger.
    edit mymfile
eig
Computes eigenvalues and eigenvectors of a square matrix.
    eig([2, 3; 4, 5])
    [e, v] = eig([1, 0, 0; 1, 1, 1; 1, 2, 4])
end
Last entry of a vector. (Also a programming construct.)
    v(end)
    v(3:end)
eval
Evaluates a string or symbolic expression. Useful in M-files or in defining anonymous functions.
    sol = dsolve('Dy = t^2 + y', 'y(0) = 2', 't');
    fsol = @(t) eval(vectorize(sol))
eye
The identity matrix of the specified size.
factor
Factors a polynomial or integer.
    syms x y; factor(x^4 – y^4)
feval
Evaluates a function specified by a string. Useful in function M-files.
    feval('exp', 1)
format
Specifies the output format for numerical variables.
    format short
    format long
fzero
Tries to find a zero of the specified function or expression (given as a string) near a given starting point or on a specified interval. If the first argument is a string, the independent variable must be x.
    fzero(@cos, [–pi 0])
    fzero('cos(x) – x', 1)
help
Asks for documentation for a MATLAB command. See also lookfor.
    help factor
ilaplace
Inverse Laplace Transform.
    syms s t; ilaplace(1/s, s, t)
inline
Constructs a MATLAB inline function from a string expression. Useful in MATLAB 6, but discouraged in later versions, in which it is better to use anonymous functions.
    sol = dsolve('Dy = t^2 + y', 'y(0) = 2', 't')
    fsol = inline(vectorize(sol), 't')
int
Integration operator for both definite and indefinite integrals.
    int('1/(1 + x^2)', 'x')
    syms x; int(exp(–x), x, 0, Inf)
inv
Inverse of a square matrix.
    inv([1 2; 3 5])
jacobian
Computes the Jacobian matrix, i.e., the matrix of partial derivatives with respect to the indicated variables.
    syms x y; jacobian([x^2*y y–x], [x y])
laplace
Computes the Laplace Transform.
    syms t s; laplace(t^5, t, s)
length
Returns the number of elements in a vector or string.
    length('abcde')
limit
Finds a two-sided limit, if it exists. Use right or left for one-sided limits.
    syms x; limit(sin(x)/x, x, 0)
    syms x; limit(1/x, x, Inf, 'left')
load
Loads Workspace variables from a disk file with a .mat suffix.
    load filename
lookfor
Searches for a specified string in the first line of all M-files found in the MATLAB path. Can be slow if many toolboxes are installed.
    lookfor ode
more
Turns on (or off) page-by-page scrolling of MATLAB output. Use the space bar to advance to the next page, the ENTER or RETURN key to advance line-by-line, and q to abort the output.
    more on
    more off
num2str
Converts a number to a string. Useful in programming.
    constant = ['a' num2str(1)]
ode45
Numerical ODE solver for first order equations. See MATLAB's online help for ode45 for a list of other MATLAB ODE solvers.
    [t, y] = ode45(@(t, y) t^2 + y, [0 10], 1);
    plot(t, y)
odeset
Used to set options for ode45, such as Events, AbsTol, and RelTol.
    options = odeset('Events', @eventfile)
ones
Creates a matrix of ones.
    ones(3), ones(3,1)
path
Without an argument, displays the search path. With an argument, sets the search path.
pause
Suspends execution of an M-file until the user presses a key.
pretty
Displays a symbolic expression in a more readable format.
    syms x y; expr = x/(x – 3)/(x + 2/y)
    pretty(expr)
publish
Runs the specified M-file and assembles input, comments, and output into a finished document in specified format. (The default is a web page, i.e., html format.)
    publish('mymfile', 'doc')
pwd
Shows the name of the current (working) directory.
quadl
Numerical integrator. The input function must be ``vectorized.''
    quadl(@(x) (1–x.^2).^(1/2), –1, 1)
quit
Terminates a MATLAB session.
roots
Finds the roots of a polynomial whose coefficients are given by the elements of the vector argument of roots.
    roots([1 1 –2])
save
Saves Workspace variables to a specified file. See load.
    save filename
sim
Runs a Simulink model. Specifying the time interval is optional.
    sim('mymodel', [0, 5])
simplify
Simplifies an algebraic expression.
    syms x; simplify((x+1)^2 – x^2)
size
Returns the number of rows and the number of columns in a matrix.
    A = [1 3 2; 4 1 5]
    [r, c] = size(A)
solve
Solves an algebraic equation. Will guess what the independent variable is if it is not specified.
    solve('x^2 + 3*x + 1')
strcat
Concatenates two or more strings.
    strcat('This ', 'is ', 'a ', 'long ', 'string')
str2num
Converts a string to a number. Useful in programming.
    constant = 'a7'
    index = str2num(constant(2))
struct
Used to create a ``structure.''
    x = struct; x.first = 'a'; x.second = 'b'; x
subs
Substitutes for parts of an expression.
    subs('x^3 – 4*x + 1', 'x', 2)
    subs('sin(x)^2 + cos(x)', 'sin(x)', 'z')
sum
Sums a vector, or sums the columns of a matrix.
    k = 1:10; sum(k)
sym
Creates a symbolic variable or number.
    pi = sym('pi')
    x = sym('x')
    constant = sym('1/2')
syms
Shortcut for creating symbolic variables. The command syms x is equivalent to x = sym('x').
    syms x y z
symsum
Evaluates a symbolic sum in closed form.
    syms x n; symsum(x^n/n, n, 1, inf)
taylor
Gives a Taylor polynomial approximation of order one less than a specified number (the default is 6) around a specified point (default 0). Will guess what the independent variable is if it is not specified.
    syms x; taylor(cos(x), 8, 0)
    taylor(exp(1/x), 10, x, inf)
transpose
Transpose of a matrix. Converts a column vector to a row vector, and vice versa. Usually invoked with the .' operator. See also ctranspose.
    A = [1 3 4]
    A.'
type
Displays the contents of a specified file.
    type myfile.m
vectorize
Vectorizes a symbolic expression. Useful in defining functions; see also eval and inline.
    f = inline(vectorize('x^2 – 1/x'))
vpa
Evaluates an expression to the specified degree of accuracy using variable precision arithmetic.
    vpa('1/3', 20)
whos
Lists current information on all the variables in the Workspace.
zeros
Creates a matrix of zeros.
    zeros(10), zeros(1,10)

Built-in MATLAB Functions

abs
absolute value
acos
inverse cosine
airy
Airy functions; airy(0, x) and airy(2, x) are linearly independent solutions of Airy's equation
asin
inverse sine
atan
inverse tangent
atan2
atan2(y,x) is the polar coordinate θ of the point (x, y).
besselj, bessely
Bessel functions. besselj(n, x) and bessely(n, x) are linearly independent solutions of Bessel's equation of order n.
cos
cosine
cosh
hyperbolic cosine
dirac
the unit impulse "function"
erf
the error function, the integral from 0 to x of (2/√π)exp(−t2).
exp
the exponential function ex
expm
the matrix exponential function, defined like ex, but using matrix multiplication
gamma
the gamma function Γ(x) = ∫0tx−1etdt
heaviside
the unit step function
hypgeom
the hypergeometric function of Gauss, 2F1(a,b;c;z)
imag
the imaginary part of a complex number
log
the natural logarithm
real
the real part of a complex number
sin
the sine
sinh
the hyperbolic sine
sinint
the sine integral ∫0x (sin t/t) dt
sqrt
the square root
tan
the tangent
tanh
the hyperbolic tangent

MATLAB Graphics Commands

axis
Sets axis scaling and appearance.
    axis([xmin xmax ymin ymax]) -- sets ranges for the axes.
    axis tight -- sets the axis limits to the full range of the data.
    axis equal -- makes the horizontal and vertical scales equal.
    axis square -- makes the axis box square.
    axis off -- hides the axes and tick marks.
close
Closes the current figure window; close all closes all figure windows.
contour
Plots the level curves of a function of two variables; usually used with the meshgrid command.
    [X, Y] = meshgrid(–3:0.1:3, –3:0.1:3);
    contour(X, Y, X.^2 – Y.^2)
ezplot
Basic plot command for symbolic expressions. Can also be used for implicit plots of f(x,y)=0.
    ezplot('exp(–x^2)', [–5, 5])
    syms x; ezplot(sin(x))
    syms x y; ezplot(x^3 – x – y^2, [–2, 2])
figure
Creates a new figure window.
gca
Get current axes. Returns the identifier (``handle'') of the axes properties of the active figure window.
gcf
Get current figure. Returns the number of the active figure window.
ginput
Gathers coordinates from a figure using the mouse (press the Enter or Return key to finish).
    [X, Y] = ginput
gtext
Places a text label using the mouse.
    gtext('Region of instability')
hold
Holds the current graph. Superimpose any new graphics generated by MATLAB on top of the current figure.
    hold on
    hold off
legend
Creates a legend for a figure.
    t = (0:0.1:2)*pi;
    plot(t, cos(t), t, sin(t))
    legend('cos(t)', 'sin(t)')
meshgrid
Creates a vector array that can be used as input to commands such as contour or quiver.
    [X, Y] = meshgrid(0:0.1:1, 0:0.1:2);
    contour(X, Y, X.^2 + Y.^2)
plot
Plots vectors of data. Specifying the plot style is optional.
    X = [0:0.1:2];
    plot(X, X.^3)
    plot(X, X.^3), 'rx–', 'LineWidth', 2)
plot3
Creates 3-dimensional (line) plots.
    t = [0:0.1:30];
    plot3(t, t.*cos(t), t.*sin(t))
print
Sends the contents of the current figure window to the printer or to a file. With the –s option, prints the current Simulink model.
    print
    print –deps picture.eps
    print –s
quiver
Plots a vector field for a pair of functions of two variables. It takes numerical, rather than symbolic, data. It is often useful to normalize vectors so that they have length close to 1 and to scale them by a factor of about 1/2.
    [X, Y] = meshgrid(–2:0.2:2, –2:0.2:2);
    U = X.*(X – Y – 2); V = Y.*(–X + Y + 1);
    L = sqrt(1 + U.^2 + V.^2));
    quiver(X, Y, U./L, V./L, 0.5)
set
Sets a property of a figure window.
    set(gca, 'FontSize', 14)
simplot
Similar to plot, but uses the style of a Simulink Scope window.
    t = [0:0.1:10]'; simplot(t, [sin(pi*t), cos(pi*t)])
subplot
Breaks the figure window into a grid of smaller plots.
    subplot(2, 2, 1), ezplot('x^2')
    subplot(2, 2, 2), ezplot('x^3')
    subplot(2, 2, 3), ezplot('x^4')
    subplot(2, 2, 4), ezplot('x^5')
text
Annotates a figure, by placing text at specified coordinates.
    text(x, y, 'string')
title
Assigns a title to the current figure window.
    title 'Nice Picture'
xlabel
Assigns a label to the horizontal coordinate axis.
    xlabel 'Year'
ylabel
Assigns a label to the vertical coordinate axis.
    ylabel 'Population'
zoom
Rescales a figure by a specified factor; zoom by itself enables use of the mouse for zooming in or out.
    zoom
    zoom(4)

Built-in MATLAB Constants

i
the imaginary unit
Inf
pi
the number π

MATLAB Programming

end
Terminates an if, for, while, or switch statement.
else
Alternative in a conditional statement. See if.
elseif
Nested alternative in a conditional statement. See the online help for if.
error
Displays an error message and aborts execution of an M-file.
for
Repeats a block of expressions a specified number of times. Must be terminated by end.
    figure, hold on
    t = –1:0.05:1;
    for k = 0:10
        plot(t, t.^k)
    end
function
Always used at the top of a function M-file to define a new function.
    function y = myfunction(x)
if
Conditional execution of MATLAB statements. Must be terminated by end.
    if (x >= 0)
        sqrt(x)
    else
        error('Invalid input')
    end
input
Used in a script M-file to prompt for user input.
    answer = input('Please enter [x, y] coordinates: ')
isa
Used in programs to check whether an object is of a given class (double, sym, etc.).
    isa(x, 'sym')
keyboard
Used in an M-file to return control to the keyboard. Useful for debugging M-files.
nargin
In M-files, returns the number of arguments passed to the function.
    if (nargin 2); error('Wrong numberof arguments'); end

MATLAB has many other programming constructs, including while, switch, case, otherwise, break, nargout, and return. Looking at MATLAB's built-in M-files is a good way to learn how to use these.

Useful Simulink Blocks

Continuous Library

  • Integrator: the most important block for differential equations, computes the integral. Also used to set initial conditions.

Math Operations Library

  • Sum, Add, Subtract: all can be used for addition and subtraction
  • Gain: used to multiply by a constant
  • Trigonometric Function: used for sin, cos, sinh, tan, etc.
  • Sqrt: square root
  • Abs: absolute value
  • MinMax: takes min or max
  • Polynomial: can compute any polynomial function
  • Product: self-explanatory
  • Divide: self-explanatory
  • Math Function: can compute many mathematical functions, such as exp and log

Sources Library

  • Constant: used to input a constant
  • Sine Wave: used to input a trigonometric signal
  • Step: used for a Heaviside function
  • Ramp: used for a ramp signal (Heaviside × linear)

Sinks Library

  • To Workspace: sends Simulink output back to MATLAB
  • Scope: used for plotting a signal
  • XY Graph: used for plotting one signal against another

Useful MuPAD Commands