Home
Project Description
Authors

Differential Equations
  with MATLAB


Differential Equations
  with Mathematica


Differential Equations
  with Maple

Glossary, Differential Equations with MATLAB

Updated for MATLAB 2019a

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 scripts,
  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.

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
integral(@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.
=
Equal sign, used for an assignment.
==
Double equal sign, used for defining an equation (to be solved).
'
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
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'
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. The independent variable should be a symbolic function. The options 'ExpansionPoint' and 'Implicit' enable you to request series or implicit solutions (MATLAB 2020a or later). See the page Series for more details.
syms t y(t); dsolve(diff(y,2) - t*y == 0)
dsolve(diff(y) + y^2 == 0, y(0) == 1)
syms x(t) y(t); [x, y]=dsolve(diff(x)==2*x + y, diff(y)==-x)
echo
Turns on or off the echoing of commands inside scripts.
edit
Opens a script or live script 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)
eye
The identity matrix of the specified size.
factor
Factors a polynomial or integer.
syms x y; factor(x^4 - y^4)
factor(1111)
format
Specifies the output format for numerical variables.
format short
format long
fzero
Tries to find a zero of the specified function near a given starting point or on a specified interval.
fzero(@cos, [-pi 0])
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)
int
Integration operator for both definite and indefinite integrals.
syms x; int(1/(1 + x^2), x)
syms x; int(exp(-x), x, 0, Inf)
integral
Numerical integrator. The input function must be "vectorized."
integral(@(x) (1-x.^2).^(1/2), –1, 1)
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 scripts found in the MATLAB path. Can be slow if many toolboxes are installed.
lookfor ode
matlabFunction
Converts a symbolic expression to a vectorized function.
syms x; f = matlabFunction(int(x^2))
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 a script 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)
prod
Multiplies elements of a vector.
tenfactorial = prod(1:10)
publish
Runs the specified script 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.
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
series
Gives the first terms of a series expansion of a function. Similarly to taylor, but more robust in that it will give series involving fractional or negative exponents. Will guess what the independent variable is if it is not specified.
syms x; series(sin(x)^(1/2)*log(x), 'Order', 8)
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.
syms x y z; 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 or symbolic functions. The command syms x is equivalent to x = sym('x').
syms x y(t) 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 around a specified point (default 0) of order one less than a specified order (the default is 6). Will guess what the independent variable is if it is not specified.
syms x; taylor(cos(x), 'Order', 8)
taylor(exp(1/x), 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
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
hypergeom
the generalized hypergeometric function, pFq(a;b;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)
copyobj
Copies a graphic so it can be pasted into another figure.
h1 = fplot(@sin, [-pi, pi]); figure
h2 = fplot(@cos, [-pi, pi], 'r');
copyobj(h1, gca)
fcontour
Basic contour plot command for functions or symbolic expressions of two variables.
syms x y; fcontour(sin(x)*cos(y), [-2*pi, 2*pi, -2*pi, 2*pi])
figure
Creates a new figure window.
fimplicit
Basic implicit plotting command.
syms x y; fimplicit(y^2 == x^3 - x)
fmesh
Basic plotting command for functions of two variables.
syms x y; fmesh(sin(x)*cos(y), [-2*pi, 2*pi, -2*pi, 2*pi])
fplot
Basic plotting command for functions or symbolic expressions.
fplot(@(x) exp(–x.^2), [–5, 5])
syms x; fplot(sin(x))
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. Always follow by a semicolon.
[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)
subplot
Breaks the figure window into a grid of smaller plots.
subplot(2, 2, 1), fplot(@(x) x.^2)
subplot(2, 2, 2), fplot(@(x) x.^3)
subplot(2, 2, 3), fplot(@(x) x.^4)
subplot(2, 2, 4), fplot(@(x) 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

eulergamma
the Euler γ constant, limn→∞k=1n1/k) − ln n
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 a script.
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 script 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 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 a script to return control to the keyboard. Useful for debugging.
nargin
In scripts, returns the number of arguments passed to the function.
if (nargin > 2); error('Wrong number of arguments'); end
warning
Displays a warning message. Or can be used to suppress warning messages.
warning('Possible singularity')
warning off

MATLAB has many other programming constructs, including while, switch, case, otherwise, break, nargout, and return. Looking at MATLAB's built-in scripts 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

  • Clock: used to input the value of the time
  • 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