Computation

Visualization
Programming
For Use with MATLAB
®
User’s Guide
Version 2
Symbolic Math
Toolbox
How to Contact The MathWorks:
508-647-7000 Phone
508-647-7001 Fax
The Mat hWor ks, Inc. Mail
24 Pr ime Par k Way
Nat ick, MA 01760-1500
http://www.mathworks.com Web
ftp.mathworks.com Anonymous FTP ser ver
comp.soft-sys.matlab Newsgr oup
support@mathworks.com Technical suppor t
suggest@mathworks.com Pr oduct enhancement suggest ions
bugs@mathworks.com Bug r epor t s
doc@mathworks.com Document at ion er r or r epor t s
subscribe@mathworks.com Subscr ibing user r egist r at ion
service@mathworks.com Or der st at us, license r enewals, passcodes
info@mathworks.com Sales, pr icing, and gener al infor mat ion
S ymbolic Math Toolbox User’s Guide
© COPYRIGHT 1993 - 1998 by The Mat hWor ks, Inc.
The soft war e descr ibed in t his document is fur nished under a license agr eement . The soft war e may be used
or copied only under t he t er ms of t he license agr eement . No par t of t his manual may be phot ocopied or r epr o-
duced in any for m wit hout pr ior wr it t en consent fr om The Mat hWor ks, Inc.
U.S. GOVERNMENT: If Licensee is acquir ing t he Pr ogr ams on behalf of any unit or agency of t he U.S.
Gover nment , t he following shall apply: (a) For unit s of t he Depar t ment of Defense: t he Gover nment shall
have only t he r ight s specified in t he license under which t he commer cial comput er soft war e or commer cial
soft war e document at ion was obt ained, as set for t h in subpar agr aph (a) of t he Right s in Commer cial
Comput er Soft war e or Commer cial Soft war e Document at ion Clause at DFARS 227.7202-3, t her efor e t he
r ight s set for t h her ein shall apply; and (b) For any ot her unit or agency: NOTICE: Not wit hst anding any
ot her lease or license agr eement t hat may per t ain t o, or accompany t he deliver y of, t he comput er soft war e
and accompanying document at ion, t he r ight s of t he Gover nment r egar ding it s use, r epr oduct ion, and disclo-
sur e ar e as set for t h in Clause 52.227-19 (c)(2) of t he FAR.
MATLAB, Simulink, St at eflow, Handle Gr aphics, and Real-Time Wor kshop ar e r egist er ed t r ademar ks, and
Tar get Language Compiler is a t r ademar k of The Mat hWor ks, Inc.
Ot her pr oduct or br and names ar e t r ademar ks or r egist er ed t r ademar ks of t heir r espect ive holder s.
Pr int ing Hist or y: August 1993 Fir st pr int ing
Oct ober 1994 Second pr int ing
May 1997 Thir d pr int ing for Symbolic Mat h Toolbox 2.0
Sept ember 1998 Updat ed for Release 11 (online only)
i
Contents
1
Tutori al
Introduct i on . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-2
Ge tt i ng He lp . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-4
Ge tt i ng Starte d . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-5
Symbolic Object s . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-5
Cr eat ing Symbolic Var iables and Expr essions . . . . . . . . . . . . . 1-6
Symbolic and Numer ic Conver sions . . . . . . . . . . . . . . . . . . . . . . 1-7
Const r uct ing Real and Complex Var iables . . . . . . . . . . . . . . 1-9
Cr eat ing Abst r act Funct ions . . . . . . . . . . . . . . . . . . . . . . . . 1-10
Using sym t o Access Maple Funct ions . . . . . . . . . . . . . . . . . 1-11
Example: Cr eat ing a Symbolic Mat r ix . . . . . . . . . . . . . . . . . 1-11
The Default Symbolic Var iable . . . . . . . . . . . . . . . . . . . . . . 1-13
Cr eat ing Symbolic Mat h Funct ions . . . . . . . . . . . . . . . . . . . . . 1-15
Using Symbolic Expr essions . . . . . . . . . . . . . . . . . . . . . . . . . 1-15
Cr eat ing an M-File . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-16
Calculus . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-17
Differ ent iat ion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-17
Limit s . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-21
Int egr at ion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-23
Int egr at ion wit h Real Const ant s . . . . . . . . . . . . . . . . . . . . . 1-26
Real Var iables via sym . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-28
Symbolic Summat ion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-30
Taylor Ser ies . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-31
Ext ended Calculus Example . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-33
Plot t ing Symbolic Funct ions . . . . . . . . . . . . . . . . . . . . . . . . . 1-33
i i
Si mpli fi cat i ons and Subs ti tut i ons . . . . . . . . . . . . . . . . . . . . . 1-47
Simplificat ions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-47
collect . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-48
expand . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-49
hor ner . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-49
fact or . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-50
simplify . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-52
simple . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-52
Subst it ut ions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-56
subexpr . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-56
subs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-59
Vari able-Preci si on Arithmeti c . . . . . . . . . . . . . . . . . . . . . . . . . 1-64
Over view . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-64
Example: Using t he Differ ent Kinds of Ar it hmet ic . . . . . . . . . 1-65
Rat ional Ar it hmet ic . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-65
Var iable-Pr ecision Number s . . . . . . . . . . . . . . . . . . . . . . . . . 1-66
Conver t ing t o Float ing-Point . . . . . . . . . . . . . . . . . . . . . . . . 1-67
Anot her Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-67
Linear Algebra . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-69
Basic Algebr aic Oper at ions . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-69
Linear Algebr aic Oper at ions . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-70
Eigenvalues . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-74
J or dan Canonical For m . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-81
Singular Value Decomposit ion . . . . . . . . . . . . . . . . . . . . . . . . . 1-82
Eigenvalue Tr aject or ies . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-86
Solvi ng Equati ons . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-96
Solving Algebr aic Equat ions . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-96
Sever al Algebr aic Equat ions . . . . . . . . . . . . . . . . . . . . . . . . . . 1-104
Single Differ ent ial Equat ion . . . . . . . . . . . . . . . . . . . . . . . . . . 1-107
Example 1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-108
Example 2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-108
Example 3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-109
Sever al Differ ent ial Equat ions . . . . . . . . . . . . . . . . . . . . . . . . 1-109
Inte gral Transforms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-112
The Four ier and Inver se Four ier Tr ansfor ms . . . . . . . . . . . . 1-112
The Laplace and Inver se Laplace Tr ansfor ms . . . . . . . . . . . . 1-120
i i i
The Z– and Inver se Z–t r ansfor ms . . . . . . . . . . . . . . . . . . . . . . 1-126
Refer ences . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-128
Speci al Mat he mati cal Functi ons . . . . . . . . . . . . . . . . . . . . . . 1-130
Diffr act ion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-132
Using Maple Functi ons . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-136
Simple Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-136
Vect or ized Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-139
Debugging . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-141
Tr ace Mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-141
St at us Out put Ar gument . . . . . . . . . . . . . . . . . . . . . . . . . . 1-141
Exte nded Symbolic Math Toolbox . . . . . . . . . . . . . . . . . . . . 1-143
Packages of Libr ar y Funct ions . . . . . . . . . . . . . . . . . . . . . . . . 1-143
Pr ocedur e Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-145
Pr ecompiled Maple Pr ocedur es . . . . . . . . . . . . . . . . . . . . . . . . 1-148
2
Reference
A
Compati bi li ty Gui de
Compati bi li ty wi th Earli e r Ve rsi ons . . . . . . . . . . . . . . . . . . . . A-2
Obsole te Funct i ons . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . A-3
i v Contents
1
Tut or ial
Introduct i on . . . . . . . . . . . . . . . . . . . . 1-2
Ge tt i ng He lp . . . . . . . . . . . . . . . . . . . . 1-4
Ge tt i ng St arte d . . . . . . . . . . . . . . . . . . 1-5
Calculus . . . . . . . . . . . . . . . . . . . . . . 1-17
Si mpli fi cat i ons and Subs ti t uti ons . . . . . . . . . . 1-47
Vari able -Pre ci s ion Ari thme t ic . . . . . . . . . . . 1-64
Li near Algebra . . . . . . . . . . . . . . . . . . . 1-69
Solvi ng Equations . . . . . . . . . . . . . . . . . 1-96
Inte gral Transforms . . . . . . . . . . . . . . . 1-112
Speci al Mat hemati cal Funct ions . . . . . . . . . . 1-130
Usi ng Maple Functions . . . . . . . . . . . . . . 1-136
Exte nded Symboli c Math Toolbox . . . . . . . . . 1-143
1 Tutorial
1-2
Introduction
The Symbolic Mat h Toolboxes incor por at e symbolic comput at ion int o
MATLAB
®
’s numer ic envir onment . These t oolboxes supplement MATLAB’s
numer ic and gr aphical facilit ies wit h sever al ot her t ypes of mat hemat ical
comput at ion:
The comput at ional engine under lying t he t oolboxes is t he ker nel of Maple
®
, a
syst em developed pr imar ily at t he Univer sit y of Wat er loo, Canada, and, mor e
r ecent ly, at t he Eidgenössiche Technische Hochschule, Zür ich, Swit zer land.
Maple is mar ket ed and suppor t ed by Wat er loo Maple, Inc.
These ver sions of t he Symbolic Mat h Toolboxes ar e designed t o wor k wit h
MATLAB 5 and Maple V Release 4.
Ther e ar e t wo t oolboxes. The basic Symbolic Mat h Toolbox is a collect ion of
mor e t han one-hundr ed MATLAB funct ions t hat pr ovide access t o t he Maple
Facility Covers
Calculus Differ ent iat ion, int egr at ion, limit s, summat ion,
and Taylor ser ies
Linear Algebr a Inver ses, det er minant s, eigenvalues, singular
value decomposit ion, and canonical for ms of
symbolic mat r ices
Simplificat ion Met hods of simplifying algebr aic expr essions
Solut ion of
Equat ions
Symbolic and numer ical solut ions t o algebr aic and
differ ent ial equat ions
Var iable-Pr ecision
Ar it hmet ic
Numer ical evaluat ion of mat hemat ical expr essions
t o any specified accur acy
Tr ansfor ms Four ier , Laplace, z-t r ansfor m, and cor r esponding
inver se t r ansfor ms
Special
Mat hemat ical
Funct ions
Special funct ions of classical applied mat hemat ics
Introduction
1-3
ker nel using a synt ax and st yle t hat is a nat ur al ext ension of t he MATLAB
language. The basic t oolbox also allows you t o access funct ions in Maple’s
linear algebr a package. The Ext ended Symbolic Mat h Toolbox augment s t his
funct ionalit y t o include access t o all nongr aphics Maple packages, Maple
pr ogr amming feat ur es, and user -defined pr ocedur es. Wit h bot h t oolboxes, you
can wr it e your own M-files t o access Maple funct ions and t he Maple wor kspace.
The following sect ions of t his Tut or ial pr ovide explanat ion and examples on
how t o use t he t oolboxes.
Chapt er 2, “Refer ence,” pr ovides det ailed descr ipt ions of each of t he funct ions
in t he t oolboxes.
Section Covers
“Get t ing Help” How t o get online help for Symbolic Mat h
Toolbox funct ions
“Get t ing St ar t ed” Basic symbolic mat h oper at ions
“Calculus” How t o differ ent iat e and int egr at e symbolic
expr essions
“Simplificat ions and
Subst it ut ions”
How t o simplify and subst it ut e values int o
expr essions
“Var iable-Pr ecision
Ar it hmet ic”
How t o cont r ol t he pr ecision of
comput at ions
“Linear Algebr a” Examples using t he t oolbox funct ions
“Solving Equat ions” How t o solve symbolic equat ions
“Int egr al Tr ansfor ms” Four ier, Laplace, and z-t r ansfor ms
“Special Mat hemat ical
Funct ions”
How t o access Maple ’s special mat h
funct ions
“Using Maple Funct ions” How t o use Maple ’s help, debugging, and
user-defined pr ocedur e funct ions
“Ext ended Symbolic Mat h
Toolbox”
Feat ur es of t he Ext ended Symbolic Mat h
Toolbox
1 Tutorial
1-4
Getting Help
Ther e ar e t wo ways t o find infor mat ion on using Symbolic Mat h Toolbox
funct ions. One, of cour se, is t o r ead t his manual! The ot her is t o use MATLAB’s
command line help syst em. Gener ally, you can obt ain help on MATLAB
funct ions simply by t yping
help function
wher e function is t he name of t he MATLAB funct ion for which you need help.
This is not sufficient , however , for some Symbolic Mat h Toolbox funct ions. The
r eason? The Symbolic Mat h Toolbox “over loads” many of MATLAB’s numer ic
funct ions. That is, it pr ovides symbolic-specific implement at ions of t he
funct ions, using t he same funct ion name. To obt ain help for t he symbolic
ver sion of an over loaded funct ion, t ype
help sym/function
wher e function is t he over loaded funct ion’s name. For example, t o obt ain help
on t he symbolic ver sion of t he over loaded funct ion, diff, t ype
help sym/diff
To obt ain infor mat ion on t he numer ic ver sion, on t he ot her hand, simply t ype
help diff
How can you t ell whet her a funct ion is over loaded? The help for t he numer ic
ver sion t ells you so. For example, t he help for t he diff funct ion cont ains t he
sect ion
Overloaded methods
help char/diff.m
help sym/diff.m
This t ells you t hat t her e ar e t wo ot her diff commands t hat oper at e on
expr essions of class char and class sym, r espect ively. See t he next sect ion for
infor mat ion on class sym. For mor e infor mat ion on over loaded commands, see
Chapt er 14 of t he Using MATLAB guide.
You can use t he mhelp command t o obt ain help on Maple commands. For
example, t o obt ain help on t he Maple diff command, t ype mhelp diff. This
r et ur ns t he help page for t he Maple diff funct ion. For mor e infor mat ion on t he
Getting Started
1-5
mhelp command, t ype help mhelp or r ead t he sect ion “Using Maple Funct ions”
in t his Tut or ial.
Getting Started
This sect ion descr ibes how t o cr eat e and use symbolic object s. It also descr ibes
t he default symbolic var iable. If you ar e familiar wit h ver sion 1 of t he Symbolic
Mat h Toolbox, please not e t hat ver sion 2 uses subst ant ially differ ent and
simpler synt ax.
(If you alr eady have a copy of t he Maple V Release 4 libr ar y, please see t he
r efer ence page for mapleinit befor e pr oceeding.)
To get a quick online int r oduct ion t o t he Symbolic Mat h Toolbox, t ype demos at
t he MATLAB command line. MATLAB displays t he MATLAB De mos dialog
box. Select Symboli c Math (in t he left list box) and t hen Introducti on (in t he
r ight list box).
Symbolic Objects
The Symbolic Mat h Toolbox defines a new MATLAB dat a t ype called a
symbolic object or sym (see Chapt er 14 in Using MATLAB for an int r oduct ion
1 Tutorial
1-6
t o MATLAB classes and object s). Int er nally, a symbolic object is a dat a
st r uct ur e t hat st or es a st r ing r epr esent at ion of t he symbol. The Symbolic Mat h
Toolbox uses symbolic object s t o r epr esent symbolic var iables, expr essions, and
mat r ices.
Creating Symbolic Variables and Expressions
The sym command let s you const r uct symbolic var iables and expr essions. For
example, t he commands
x = sym('x')
a = sym('alpha')
cr eat e a symbolic var iable x t hat pr int s as x and a symbolic var iable a t hat
pr int s as alpha.
Suppose you want t o use a symbolic var iable t o r epr esent t he golden r at io
The command
rho = sym('(1 + sqrt(5))/2')
achieves t his goal. Now you can per for m var ious mat hemat ical oper at ions on
rho. For example
f = rho^2 – rho – 1
f =

(1/2+1/2*5^(1/2))^2-3/2-1/2*5^(1/2)
simplify(f)
r et ur ns
0
Now suppose you want t o st udy t he quadr at ic funct ion f = ax
2
+ bx + c. The
st at ement
f = sym('a*x^2 + b*x + c')
assigns t he symbolic expr ession ax
2
+ bx + c t o t he var iable f. Obser ve t hat in
t his case, t he Symbolic Mat h Toolbox does not cr eat e var iables cor r esponding
ρ
1 5 +
2
----------------- =
Getting Started
1-7
t o t he t er ms of t he expr ession, a, b, c, and x. To per for m symbolic mat h
oper at ions (e.g., int egr at ion, differ ent iat ion, subst it ut ion, et c.) on f, you need
t o cr eat e t he var iables explicit ly. You can do t his by t yping
a = sym('a')
b = sym('b')
c = sym('c')
x = sym('x')
or simply
syms a b c x
In gener al, you can use sym or syms t o cr eat e symbolic var iables. We
r ecommend you use syms because it r equir es less t yping.
Symbolic and Numeric Conversions
Let ’s r et ur n t o t he golden r at io
The sym funct ion has four opt ions for r et ur ning a symbolic r epr esent at ion of
t he numer ic value rho = (1 + sqrt(5)/2). The 'f' opt ion
sym(rho,'f')
r et ur ns a symbolic float ing-point r epr esent at ion
'1.9e3779b97f4a8'*2^(0)
The 'r' opt ion
sym(rho,'r')
r et ur ns t he r at ional for m
7286977268806824*2^(–52)
ρ
1 5 +
2
----------------- =
1 Tutorial
1-8
This is t he default set t ing for sym. That is, calling sym wit hout a second
ar gument is t he same as using sym wit h t he 'r' opt ion.
sym(rho)

ans =
7286977268806824*2^(–52)

sym(.25)

ans =
1/4
The t hir d opt ion 'e' r et ur ns t he r at ional for m of rho plus t he differ ence
bet ween t he t heor et ical r at ional expr ession for rho and it s act ual (machine)
float ing-point value in t er ms of eps (t he float ing-point r elat ive accur acy)
sym(rho,'e')

ans =
7286977268806824*2^(–52)
In t his case, t he t heor et ical and act ual float ing-point values for rho ar e t he
same. For 1/3, however , we obt ain
sym(1/3,'e')

ans =
1/3-eps/12
The four t h opt ion 'd' r et ur ns t he decimal expansion of rho up t o t he number
of significant digit s specified by digits.
sym(rho,'d')

ans =
1.6180339887498949025257388711907
Getting Started
1-9
The default value of digits is 32 (hence, sym(rho,'d') r et ur ns a number wit h
32 significant digit s), but if you pr efer a shor t er r epr esent at ion, use t he digits
command as follows.
digits(7)
sym(rho,'d')

ans =
1.618034
A par t icular ly effect ive use of sym is t o conver t a mat r ix fr om numer ic t o
symbolic for m. The command
A = hilb(3)
gener at es t he 3-by-3 Hilber t mat r ix.
A =

1.0000 0.5000 0.3333
0.5000 0.3333 0.2500
0.3333 0.2500 0.2000
By applying sym t o A
A = sym(A)
you can obt ain t he (infinit ely pr ecise) symbolic for m of t he 3-by-3 Hilber t
mat r ix.
A =

[ 1, 1/2, 1/3]
[ 1/2, 1/3, 1/4]
[ 1/3, 1/4, 1/5]
Constructing Real and Complex Variables
The sym command allows you t o specify t he mat hemat ical pr oper t ies of
symbolic var iables by using t he 'real' opt ion. That is, t he st at ement s
x = sym('x','real'); y = sym('y','real');
1 Tutorial
1-10
or mor e efficient ly
syms x y real
z = x + i*y
cr eat e symbolic var iables x and y t hat have t he added mat hemat ical pr oper t y
of being r eal var iables. Specifically t his means t hat t he expr ession
f = x^2 + y^2
is st r ict ly nonnegat ive. Hence, z is a (for mal) complex var iable and can be
manipulat ed as such. Thus, t he commands
conj(x), conj(z), expand(z*conj(z))
r et ur n t he complex conjugat es of t he var iables
x, x – i*y, x^2 + y^2
The conj command is t he complex conjugat e oper at or for t he t oolbox. If
conj(x) == x r et ur ns 1, t hen x is a r eal var iable.
To clear x of it s “r eal” pr oper t y, you must t ype
syms x unreal
or
x = sym('x','unreal')
The command
clear x
does not make x a nonr eal var iable.
Creating Abstract Functions
If you want t o cr eat e an abst r act (i.e., indet er minant ) funct ion f(x), t ype
f = sym('f(x)')
Then f act s like f(x) and can be manipulat ed by t he t oolbox commands. To
const r uct t he fir st differ ence r at io, for example, t ype
df = (subs(f,'x','x+h') – f)/'h'
Getting Started
1-11
or
syms x h
df = (subs(f,x,x+h)–f)/h
which r et ur ns
df =
(f(x+h)-f(x))/h
This applicat ion of sym is useful when comput ing Four ier , Laplace, and
z-t r ansfor ms (see t he sect ion “Int egr al Tr ansfor ms”).
Using sym to Access Maple Functions
Similar ly, you can access Maple’s fact or ial funct ion k!, using sym.
kfac = sym('k!')
To comput e 6! or n!, t ype
syms k n
subs(kfac,k,6), subs(kfac,k,n)

ans =
720
ans =
n!
Or , if you want t o comput e, for example, 12!, simply use t he prod funct ion
prod(1:12)
Example: Creating a Symbolic Matrix
A cir culant mat r ix has t he pr oper t y t hat each r ow is obt ained fr om t he pr evious
one by cyclically per mut ing t he ent r ies one st ep for war d. We cr eat e t he
cir culant mat r ix A whose element s ar e a, b, and c, using t he commands
syms a b c
A = [a b c; b c a; c a b]
1 Tutorial
1-12
which r et ur n
A =
[ a, b, c ]
[ b, c, a ]
[ c, a, b ]
Since A is cir culant , t he sum over each r ow and column is t he same. Let ’s check
t his for t he fir st r ow and second column. The command
sum(A(1,:))
r et ur ns
ans =
a+b+c
The command
sum(A(1,:)) == sum(A(:,2)) % This is a logical test.
r et ur ns
ans =
1
Now r eplace t he (2,3) ent r y of A wit h beta and t he var iable b wit h alpha. The
commands
syms alpha beta;
A(2,3) = beta;
A = subs(A,b,alpha)
r et ur n
A =
[ a, alpha, c]
[ alpha, c, beta]
[ c, a, alpha]
Fr om t his example, you can see t hat using symbolic object s is ver y similar t o
using r egular MATLAB numer ic object s.
Getting Started
1-13
The Default Symbolic Variable
When manipulat ing mat hemat ical funct ions, t he choice of t he independent
var iable is oft en clear fr om cont ext . For example, consider t he expr essions in
t he t able below.
If we ask for t he der ivat ives of t hese expr essions, wit hout specifying t he
independent var iable, t hen by mat hemat ical convent ion we obt ain f' = nx
n
,
g' = a cos(at +b), and h' = J
v
(z)(v/z)–J
v+1
(z). Let ’s assume t hat t he independent
var iables in t hese t hr ee expr essions ar e x, t, and z, r espect ively. The ot her
symbols, n, a, b, and v, ar e usually r egar ded as “const ant s” or “par amet er s.” If,
however , we want ed t o differ ent iat e t he fir st expr ession wit h r espect t o n, for
example, we could wr it e
or
t o get x
n
ln x.
By mat hemat ical convent ion, independent var iables ar e oft en lower -case
let t er s found near t he end of t he Lat in alphabet (e.g., x, y, or z). This is t he idea
behind findsym, a ut ilit y funct ion in t he t oolbox used t o det er mine default
symbolic var iables. Default symbolic var iables ar e ut ilized by t he calculus,
simplificat ion, equat ion-solving, and t r ansfor m funct ions. To apply t his ut ilit y
t o t he example discussed above, t ype
syms a b n nu t x z
f = x^n; g = sin(a*t + b); h = besselj(nu,z);
This cr eat es t he symbolic expr essions f, g, and h t o mat ch t he example. To
differ ent iat e t hese expr essions, we use diff.
diff(f)
Mathematical Function MATLAB Command
f = x
n
f = x^n
g = sin(at+b) g = sin(a*t + b)
h = J
v
(z) h = besselj(nu,z)
d
d n
-------f x ( )
d
d n
-------x
n
1 Tutorial
1-14
r et ur ns
ans =
x^n*n/x
See t he sect ion “Differ ent iat ion” for a mor e det ailed discussion of
differ ent iat ion and t he diff command.
Her e, as above, we did not specify t he var iable wit h r espect t o differ ent iat ion.
How did t he t oolbox det er mine t hat we want ed t o differ ent iat e wit h r espect t o
x? The answer is t he findsym command.
findsym(f,1)
which r et ur ns
ans =
x
Similar ly, findsym(g,1) and findsym(h,1) r et ur n t and z, r espect ively. Her e
t he second ar gument of findsym denot es t he number of symbolic var iables we
want t o find in t he symbolic object f, using t he findsym r ule (see below). The
absence of a second ar gument in findsym r esult s in a list of all symbolic
var iables in a given symbolic expr ession. We see t his demonst r at ed below. The
command
findsym(g)
r et ur ns t he r esult
ans =
a, b, t
findsym Rule: The default symbolic var iable in a symbolic expr ession is t he
let t er t hat is closest t o 'x' alphabet ically. If t her e ar e t wo equally close, t he
let t er lat er in t he alphabet is chosen.
Getting Started
1-15
Her e ar e some examples:
Creating Symbolic Math Functions
Ther e ar e t wo ways t o cr eat e funct ions:
•Use symbolic expr essions
•Cr eat e an M-file
Using Symbolic Expressions
The sequence of commands
syms x y z
r = sqrt(x^2 + y^2 + z^2)
t = atan(y/x)
f = sin(x*y)/(x*y)
gener at es t he symbolic expr essions r, t, and f. You can use diff, int, subs,
and ot her Symbolic Mat h Toolbox funct ions t o manipulat e such expr essions.
Expression Variable Returned By
findsym
x^n x
sin(a*t+b) t
besselj(nu,z) z
w*y + v*z y
exp(i*theta) theta
log(alpha*x1) x1
y*(4+3*i) + 6*j y
sqrt(pi*alpha) alpha
1 Tutorial
1-16
Creating an M-File
M-files per mit a mor e gener al use of funct ions. Suppose, for example, you want
t o cr eat e t he sinc funct ion sin(x)/x. To do t his, cr eat e an M-file in t he @sym
dir ect or y.
function z = sinc(x)
%SINC The symbolic sinc function
% sin(x)/x. This function
% accepts a sym as the input argument.
if is equal(x,sym(0))
z = 1;
else
z = sin(x)/x;
end
You can ext end such examples t o funct ions of sever al var iables. For a mor e
det ailed discussion on object -or ient ed pr ogr amming, see Chapt er 14 of t he
Using MATLAB guide.
Calculus
1-17
Calculus
The Symbolic Mat h Toolboxes pr ovide funct ions t o do t he basic oper at ions of
calculus; differ ent iat ion, limit s, int egr at ion, summat ion, and Taylor ser ies
expansion. The following sect ions out line t hese funct ions.
Differentiation
Let ’s cr eat e a symbolic expr ession.
syms a x
f = sin(a*x)
Then
df = diff(f)
differ ent iat es f wit h r espect t o it s symbolic var iable (in t his case x), as
det er mined by findsym.
df =
cos(a*x)*a
To differ ent iat e wit h r espect t o t he var iable a, t ype
dfa = diff(f,a)
which r et ur ns df/ da
dfa=
cos(a*x)*x
Mathematical Function MATLAB Command
f = x
n
f' = nx
n–1
f = x^n
diff(f) or diff(f,x)
g = acos(at+b)
g' = acos(at+b)
g = acos(a*t + b)
diff(g) or diff(g,t)
h = J
v
(z)
h' = J
v
(z)(v/z) – J
v+1
(z)
h = besselj(nu, z)
diff(h) or diff(h,z)
1 Tutorial
1-18
To calculat e t he second der ivat ives wit h r espect t o x and a, r espect ively, t ype
diff(f,2) % or diff(f,x,2)
which r et ur ns
ans =
–sin(a*x)*a^2
and
diff(f,a,2)
which r et ur ns
ans =
–sin(a*x)*x^2
Define a, b, x, n, t, and t het a in t he MATLAB wor kspace, using t he sym
command. The t able below illust r at es t he diff command.
To differ ent iat e t he Bessel funct ion of t he fir st kind, besselj(nu,z), wit h
r espect t o z, t ype
syms nu z
b = besselj(nu,z);
db = diff(b)
which r et ur ns
db =
–besselj(nu+1,z)+nu/z*besselj(nu,z)
f diff(f)
x^n x^n*n/x
sin(a*t+b) a*cos(a*t+b)
exp(i*theta) i*exp(i*theta)
Calculus
1-19
The diff funct ion can also t ake a symbolic mat r ix as it s input . In t his case, t he
differ ent iat ion is done element -by-element . Consider t he example
syms a x
A = [cos(a*x),sin(a*x);–sin(a*x),cos(a*x)]
which r et ur ns
A =
[ cos(a*x), sin(a*x)]
[ –sin(a*x), cos(a*x)]
The command
dy = diff(A)
r et ur ns
dy =
[ –sin(a*x)*a, cos(a*x)*a]
[ –cos(a*x)*a, –sin(a*x)*a]
You can also per for m differ ent iat ion of a column vect or wit h r espect t o a r ow
vect or . Consider t he t r ansfor mat ion fr om Euclidean (x, y, z) t o spher ical (r, λ, ϕ)
coor dinat es as given by x = r cos λ cos ϕ, y = r cos λ sin ϕ, and z = r sin λ. Not e
t hat λ cor r esponds t o elevat ion or lat it ude while ϕ denot es azimut h or
longit ude.
z
y
x
(x,y,z)
ϕ
λ
r
1 Tutorial
1-20
To calculat e t he J acobian mat r ix, J , of t his t r ansfor mat ion, use t he jacobian
funct ion. The mat hemat ical not at ion for J is
=
For t he pur poses of t oolbox synt ax, we use l for λ and f for ϕ. The commands
syms r l f
x = r*cos(l)*cos(f); y = r*cos(l)*sin(f); z = r*sin(l);
J = jacobian([x; y; z], [r l f])
r et ur n t he J acobian
J =

[ cos(l)*cos(f), –r*sin(l)*cos(f), –r*cos(l)*sin(f)]
[ cos(l)*sin(f), –r*sin(l)*sin(f), r*cos(l)*cos(f)]
[ sin(l), r*cos(l), 0]
and t he command
detJ = simple(det(J))
r et ur ns
detJ =
–cos(l)*r^2
Not ice t hat t he fir st ar gument of t he jacobian funct ion must be a column
vect or and t he second ar gument a r ow vect or . Mor eover , since t he det er minant
of t he J acobian is a r at her complicat ed t r igonomet r ic expr ession, we used t he
simple command t o make t r igonomet r ic subst it ut ions and r educt ions
(simplificat ions). The sect ion “Simplificat ions and Subst it ut ions” discusses
simplificat ion in mor e det ail.
J
x y x , , ( ) ∂
r λ ϕ , , ( ) ∂
-----------------------
Calculus
1-21
A t able summar izing diff and jacobian follows.
Limits
The fundament al idea in calculus is t o make calculat ions on funct ions as a
var iable “get s close t o” or appr oaches a cer t ain value. Recall t hat t he definit ion
of t he der ivat ive is given by a limit
pr ovided t his limit exist s. The Symbolic Mat h Toolbox allows you t o comput e
t he limit s of funct ions in a dir ect manner . The commands
syms h n x
dc = limit( (cos(x+h) – cos(x))/h,h,0 )
Mathematical Operator MATLAB Command
f(x) = exp(ax + b)
syms a b x
f = exp(a*x + b)
diff(x) or diff(f,x)
diff(f,a)
diff(f,b,2)
r = u
2
+ v
2
t = arctan(v/ u)
syms r t u v
r = u^2 + v^2
t = atan(v/u)
J = jacobian([r:t],[u,v])
x d
df
a d
df
b
2
2
d
d f
J
r t , ( ) ∂
u v , ( ) ∂
----------------- =
f ′ x ( )
f x h + ( ) f x ( ) –
h
----------------------------------
h 0 →
lim =
1 Tutorial
1-22
which r et ur n
dc =
–sin(x)
and
limit( (1 + x/n)^n,n,inf )
which r et ur ns
ans =
exp(x)
illust r at e t wo of t he most impor t ant limit s in mat hemat ics: t he der ivat ive (in
t his case of cos x) and t he exponent ial funct ion. While many limit s
ar e “t wo sided” (t hat is, t he r esult is t he same whet her t he appr oach is fr om t he
r ight or left of a), limit s at t he singular it ies of f(x) ar e not . Hence, t he t hr ee
limit s,
, , and
yield t he t hr ee dist inct r esult s: undefined, – , and + , r espect ively.
In t he case of undefined limit s, t he Symbolic Mat h Toolbox r et ur ns NaN (not a
number ). The command
limit(1/x,x,0) % Equivalently, limit(1/x)
r et ur ns
ans =
NaN
The command
limit(1/x,x,0,'left')
r et ur ns
ans =
–inf
f x ( )
x a →
lim
1
x
---
x 0 →
lim
1
x
---
x 0


lim
1
x
---
x 0
+

lim
∞ ∞
Calculus
1-23
while t he command
limit(1/x,x,0,'right')
r et ur ns
ans =
inf
Obser ve t hat t he default case, limit(f) is t he same as limit(f,x,0). Explor e
t he opt ions for t he limit command in t his t able. Her e, we assume t hat f is a
funct ion of t he symbolic object x.
Integration
If f is a symbolic expr ession, t hen
int(f)
at t empt s t o find anot her symbolic expr ession, F, so t hat diff(F) = f. That is,
int(f) r et ur ns t he indefinit e int egr al or ant ider ivat ive of f (pr ovided one exist s
in closed for m). Similar t o differ ent iat ion,
int(f,v)
Mathematical Operation MATLAB Command
limit(f)
limit(f,x,a) or
limit(f,a)
limit(f,x,a,'left')
limit(f,x,a,'right')
f x ( )
x 0 →
lim
f x ( )
x a →
lim
f x ( )
x a


lim
f x ( )
x a
+

lim
1 Tutorial
1-24
uses t he symbolic object v as t he var iable of int egr at ion, r at her t han t he
var iable det er mined by findsym. See how int wor ks by looking at t his t able.
In cont r ast t o differ ent iat ion, symbolic int egr at ion is a mor e complicat ed t ask.
A number of difficult ies can ar ise in comput ing t he int egr al. The
ant ider ivat ive, F, may not exist in closed for m; it may define an unfamiliar
funct ion; it may exist , but t he soft war e can’t find t he ant ider ivat ive; t he
soft war e could find it on a lar ger comput er , but r uns out of t ime or memor y on
t he available machine. Never t heless, in many cases, MATLAB can per for m
symbolic int egr at ion successfully. For example, cr eat e t he symbolic var iables
syms a b theta x yn x1 u
This t able illust r at es int egr at ion of expr essions cont aining t hose var iables.
Mathematical Operation MATLAB Command
int(x^n) or
int(x^n,x)
int(sin(2*x),0,pi/2) or
int(sin(2*x),x,0,pi/2)
g = cos(a*t + b)
int(g) or
int(g,t)
int(besselj(1,z)) or
int(besselj(1,z),z)
f int(f)
x^n x^(n+1)/(n+1)
y^(–1) log(y)
n^x 1/log(n)*n^x
x
n
x d

x
n 1 +
n 1 +
------------- =
2x ( ) sin x d
0
π 2 ⁄

1 =
g at b + ( ) cos =
g t ( ) t d

at b + ( ) sin a ⁄ =
J
1
z ( )

d z J –
0
z ( ) =
Calculus
1-25
The last example shows what happens if t he t oolbox can’t find t he
ant ider ivat ive; it simply r et ur ns t he command, including t he var iable of
int egr at ion, unevaluat ed.
Definit e int egr at ion is also possible. The commands
int(f,a,b)
and
int(f,v,a,b)
ar e used t o find a symbolic expr ession for
and
r espect ively.
Her e ar e some addit ional examples.
sin(a*theta+b) –cos(a*theta+b)/a
exp(–x1^2) 1/2*pi^(1/2)*erf(x1)
1/(1+u^2) atan(u)
besselj(nu,z) int(besselj(nu,z),z)
f a, b int(f,a,b)
x^7 0, 1 1/8
1/x 1, 2 log(2)
log(x)*sqrt(x) 0, 1 –4/9
exp(–x^2) 0, inf 1/2*pi^(1/2)
bessel(1,z) 0, 1 –besselj(0,1)+1
f int(f)
f x ( )
a
b

d x f v ( ) v d
a
b

1 Tutorial
1-26
For t he Bessel funct ion (besselj) example, it is possible t o comput e a
numer ical appr oximat ion t o t he value of t he int egr al, using t he double
funct ion. The command
a = int(besselj(1,z),0,1)
r et ur ns
a =
–besselj(0,1)+1
and t he command
a = double(a)
r et ur ns
a =
0.23480231344203
Integration with Real Constants
One of t he subt let ies involved in symbolic int egr at ion is t he “value” of var ious
par amet er s. For example, it would seem evident t hat t he expr ession
is t he posit ive, bell shaped cur ve t hat t ends t o 0 as x t ends t o t∞ for any r eal
number k. An example of t his cur ve is depict ed below wit h
and gener at ed, using t hese commands.
syms x
k = sym(1/sqrt(2));
f = exp(–(k*x)^2);
ezplot(f)
e
k x ( ) –
2
k
1
2
------- =
Calculus
1-27
The Maple ker nel, however , does not , a priori, t r eat t he expr essions k
2
or x
2
as
posit ive number s. To t he cont r ar y, Maple assumes t hat t he symbolic var iables
x and k as a priori indet er minat e. That is, t hey ar e pur ely for mal var iables wit h
no mat hemat ical pr oper t ies. Consequent ly, t he init ial at t empt t o comput e t he
int egr al
in t he Symbolic Mat h Toolbox, using t he commands
syms x k;
f = exp(–(k*x)^2);
int(f,x,–inf,inf) % Equivalently, inf(f,–inf,inf)
−3 −2 −1 0 1 2 3
0
0.2
0.4
0.6
0.8
1
x
exp(−1/2*x^2)
e
k x ( ) –
2
∞ –


d x
1 Tutorial
1-28
r esult in t he out put
Definite integration: Can't determine if the integral is
convergent.
Need to know the sign of --> k^2
Will now try indefinite integration and then take limits.
Warning: Explicit integral could not be found.
ans =
int(exp(–k^2*x^2),x= –inf..inf)
In t he next sect ion, you well see how t o make k a r eal var iable and t her efor e k
2
posit ive.
Real Variables via sym
Not ice t hat Maple is not able t o det er mine t he sign of t he expr ession k^2. How
does one sur mount t his obst acle? The answer is t o make k a r eal var iable, using
t he sym command. One par t icular ly useful feat ur e of sym, namely t he real
opt ion, allows you t o declar e k t o be a r eal var iable. Consequent ly, t he int egr al
above is comput ed, in t he t oolbox, using t he sequence
syms k real % Be sure that x has been declared a sym.
int(f,x,–inf,inf)
which r et ur ns
ans =
signum(k)/k*pi^(1/2)
Not ice t hat k is now a symbolic object in t he MATLAB wor kspace and a r eal
var iable in t he Maple ker nel wor kspace. By t yping
clear k
you only clear k in t he MATLAB wor kspace. To ensur e t hat k has no for mal
pr oper t ies (t hat is, t o ensur e k is a pur ely for mal var iable), t ype
syms k unreal
This var iat ion of t he syms command clear s k in t he Maple wor kspace. You can
also declar e a sequence of symbolic var iables w, y, x, z t o be r eal, using
syms w x y z real
Calculus
1-29
In t his case, all of t he var iables in bet ween t he wor ds syms and real ar e
assigned t he pr oper t y real. That is, t hey ar e r eal var iables in t he Maple
wor kspace.
Mathematical Operation MATLAB Commands
f(x) = e
–kx
syms k x
f = exp(–k*x)
int(f) or int(f,x)
int(f,k)
int(f,x,0,1) or int(f,0,1)
syms k real
g = exp(–(k*x)^2)
int(g,x,–inf,inf) or
int(g,–inf,inf)
f x ( ) x d

f k ( ) k d

f x ( ) x d
0
1

g x ( ) e
k x ( )
2

=
g x ( ) x d
∞ –


1 Tutorial
1-30
Symbolic Summation
You can comput e symbolic summat ions, when t hey exist , by using t he symsum
command. For example, t he p-ser ies
adds t o π
2
/6, while t he geomet r ic ser ies 1 + x +x
2
+ ... adds t o 1/(1-x), pr ovided
| x| < 1. Thr ee summat ions ar e demonst r at ed below.
syms x k
s1 = symsum(1/k^2,1,inf)
s2 = symsum(x^k,k,0,inf)
s1 =

1/6*pi^2
s2 =

-1/(x-1)
1
1
2
2
------
1
3
2
------ … + + +
Calculus
1-31
Taylor Series
The st at ement
T = taylor(f,8)
r et ur ns
T =
1/9+2/81*x^2+5/1458*x^4+49/131220*x^6
which is all t he t er ms up t o, but not including, or der eight (O(x
8
)) in t he Taylor
ser ies for f (x).
Technically, T is a MacLaur in ser ies, since it s basepoint is a = 0.
These commands
syms x
g = exp(x*sin(x))
t = taylor(g,12,2)
gener at e t he fir st 12 nonzer o t er ms of t he Taylor ser ies for g about x = 2.
x a – ( )
n
n 0 =


f
n ( )
a ( )
n!
-----------------
1 Tutorial
1-32
Let ’s plot t hese funct ions t oget her t o see how well t his Taylor appr oximat ion
compar es t o t he act ual funct ion g.
xd = 1:0.05:3; yd = subs(g,x,xd);
ezplot(t, [1,3]); hold on;
plot(xd, yd, 'r-.')
title('Taylor approximation vs. actual function');
legend('Function','Taylor')
Special t hanks t o Pr ofessor Gunnar Bäckst r øm of UMEA in Sweden for t his
example.
Then t he command
pretty(T)
pr int s T in a for mat r esembling t ypeset mat hemat ics.
2 4 49 6
1/9 + 2/81 x + 5/1458 x + ------ x
131220
1 1.2 1.4 1.6 1.8 2 2.2 2.4 2.6 2.8 3
1
2
3
4
5
6
x
Taylor approximation vs. actual function
Function
Taylor
Calculus
1-33
Extended Calculus Example
The funct ion
pr ovides a st ar t ing point for illust r at ing sever al calculus oper at ions in t he
t oolbox. It is also an int er est ing funct ion in it s own r ight . The st at ement s
syms x
f = 1/(5+4*cos(x))
st or e t he symbolic expr ession defining t he funct ion in f.
Plotting Symbolic Functions
The Symbolic Mat h Toolbox offer s a set of easy-t o-use commands for plot t ing
symbolic expr essions, including planar cur ves (ezplot), cont our s (ezcontour
and ezcontourf), sur faces (ezsurf, ezsurfc, ezmesh, and ezmeshc), polar
coor dinat es (ezpolar), and par amet r ically defined cur ves (ezplot and
ezplot3) and sur faces (ezsurf). See Chapt er 2, “Refer ence” for a det ailed
descr ipt ion of t hese funct ions. The r est of t his sect ion illust r at es t he use of
ezplot t o gr aph funct ions of t he for m y=f(x).
f x ( )
1
5 4 x ( ) cos +
------------------------------ =
1 Tutorial
1-34
The funct ion ezplot(f) pr oduces t he plot of f (x) as shown below.
The ezplot funct ion t r ies t o make r easonable choices for t he r ange of t he x-axis
and for t he r esult ing scale of t he y-axis. It s choices can be over r idden by an
addit ional input ar gument , or by subsequent axis commands. The default
domain for a funct ion displayed by ezplot is –2π ≤ x ≤ 2π. To alt er t he domain,
t ype
ezplot(f,[a b])
This pr oduces a gr aph of f(x) for a ≤ x ≤ b.
Let ’s now look at t he second der ivat ive of t he funct ion f.
f2 = diff(f,2)
f2 =
32/(5+4*cos(x))^3*sin(x)^2+4/(5+4*cos(x))^2*cos(x)
−6 −4 −2 0 2 4 6
0.1
0.2
0.3
0.4
0.5
0.6
0.7
0.8
0.9
1
x
1/(5+4*cos(x))
Calculus
1-35
Equivalent ly, we can t ype f2 = diff(f,x,2). The default scaling in ezplot
cut s off par t of f2’s gr aph. Set t he axes limit s manually t o see t he ent ir e
funct ion.
ezplot(f2)
axis([–2*pi 2*pi –5 2])
Fr om t he gr aph, it appear s t hat t he values of f ' ' (x) lie bet ween -4 and 1. As it
t ur ns out , t his is not t r ue. We can calculat e t he exact r ange for f (i.e., comput e
it s act ual maximum and minimum).
The act ual maxima and minima of f ''(x) occur at t he zer os of f ''' (x). The
st at ement s
f3 = diff(f2);
pretty(f3)
−6 −4 −2 0 2 4 6
−5
−4
−3
−2
−1
0
1
2
x
32/(5+4*cos(x))^3*sin(x)^2+4/(5+4*cos(x))^2*cos(x)
1 Tutorial
1-36
comput e f '''(x) and display it in a mor e r eadable for mat .
3
sin(x) sin(x) cos(x) sin(x)
384 --------------- + 96 --------------- – 4 ---------------
4 3 2
(5 + 4 cos(x)) (5 + 4 cos(x)) (5 + 4 cos(x))
We can simplify and t his expr ession using t he st at ement s
f3 = simple(f3);
pretty(f3)
2 2
sin(x) (96 sin(x) + 80 cos(x) + 80 cos(x) – 25)
4 -------------------------------------------------
4
(5 + 4 cos(x))
Now use t he solve funct ion t o find t he zer os of f ''' (x).
z = solve(f3)
r et ur ns a 5-by-1 symbolic mat r ix
z =
[ 0]
[ atan((–255–60*19^(1/2))^(1/2),10+3*19^(1/2))]
[ atan(–(–255–60*19^(1/2))^(1/2),10+3*19^(1/2))]
[ atan((–255+60*19^(1/2))^(1/2)/(10–3*19^(1/2)))+pi]
[ –atan((–255+60*19^(1/2))^(1/2)/(10–3*19^(1/2)))–pi]
each of whose ent r ies is a zer o of f '' '(x). The command
format; % Default format of 5 digits
zr = double(z)
Calculus
1-37
conver t s t he zer os t o double for m.
zr =

0
0+ 2.4381i
0– 2.4381i
2.4483
–2.4483
So far , we have found t hr ee r eal zer os and t wo complex zer os. However , a gr aph
of f3 shows t hat we have not yet found all it s zer os.
ezplot(f3)
hold on;
plot(zr,0*zr,'ro')
plot([–2*pi,2*pi], [0,0],'g-.');
title('Zeros of f3')
−6 −4 −2 0 2 4 6
−3
−2
−1
0
1
2
3
x
Zeros of f3
1 Tutorial
1-38
This occur s because f '' '(x) cont ains a fact or of sin(x), which is zer o at int eger
mult iples of π. The funct ion, solve(sin(x)), however , only r epor t s t he zer o at
x = 0.
We can obt ain a complet e list of t he r eal zer os by t r anslat ing zr
zr = [0 zr(4) pi 2*pi–zr(4)]
by mult iples of 2π
zr = [zr–2*pi zr zr+2*pi];
Now let ’s plot t he t r ansfor med zr on our gr aph for a complet e pict ur e of t he
zer os of f3.
plot(zr,0*zr,'kX')
The fir st zer o of f ' ''(x) found by solve is at x = 0. We subst it ut e 0 for t he
symbolic var iable in f2
f20 = subs(f2,x,0)
−6 −4 −2 0 2 4 6
−3
−2
−1
0
1
2
3
x
Zeros of f3
Calculus
1-39
t o comput e t he cor r esponding value of f ''(0).
f20 =
0.0494
A look at t he gr aph of f ' '(x) shows t hat t his is only a local minimum, which we
demonst r at e by r eplot t ing f2.
clf
ezplot(f2)
axis([–2*pi 2*pi –4.25 1.25])
ylabel('f2');
title('Plot of f2 = f''''(x)')
hold on
plot(0,double(f20),'ro')
text(–1,–0.25,'Local minimum')
The r esult ing plot
−6 −4 −2 0 2 4 6
−4
−3.5
−3
−2.5
−2
−1.5
−1
−0.5
0
0.5
1
x
Plot of f2 = f’’(x)
f
2
Local minimum
1 Tutorial
1-40
indicat es t hat t he global minima occur near x = -π and x = π. We can
demonst r at e t hat t hey occur exact ly at x= tπ, using t he following sequence of
commands. Fir st we t r y subst it ut ing -π and π int o f'' '(x).
simple([subs(f3,x,–pi),subs(f3,x,pi)])
The r esult
ans =
[ 0, 0]
shows t hat -π and π happen t o be cr it ical point s of f''' (x). We can see t hat -π and
π ar e global minima by plot t ing f2(–pi) and f2(pi) against f2(x).
m1 = double(subs(f2,x,-pi)); m2 = double(subs(f2,x,pi));
plot(-pi,m1,'go',pi,m2,'go')
text(-1,-4,'Global minima')
The act ual minima ar e m1, m2
ans =
[ –4, –4]
as shown in t he plot on t he following page.
Calculus
1-41
The for egoing analysis confir ms par t of our or iginal guess t hat t he r ange of
f ''(x) is [-4, 1]. We can confir m t he ot her par t by examining t he four t h zer o of
f '''(x) found by solve. Fir st ext r act t he four t h zer o fr om z and assign it t o a
separ at e variable
s = z(4)
t o obt ain
s =
atan((–255+60*19^(1/2))^(1/2)/(10–3*19^(1/2)))+pi
Execut ing
sd = double(s)
displays the zero’s cor r esponding numer ic value.
sd =
2.4483
−6 −4 −2 0 2 4 6
−4
−3.5
−3
−2.5
−2
−1.5
−1
−0.5
0
0.5
1
x
Plot of f2 = f’’(x)
f
2
Local minimum
Global minima
1 Tutorial
1-42
Plot t ing t he point (s, f2(s)) against f2, using
M1 = double(subs(f2,x,s));
plot(sd,M1,'ko')
text(-1,1,'Global maximum')
visually confir ms t hat s is a maximum.
The maximum is M1 = 1.0051.
Ther efor e, our guess t hat t he maximum of f ''(x) is [–4, 1] was close, but
incor r ect . The act ual r ange is [–4, 1.0051].
Now, let ’s see if int egr at ing f ''(x) t wice wit h r espect t o x r ecover s our or iginal
funct ion f (x) = 1/(5 + 4 cos x). The command
g = int(int(f2))
−6 −4 −2 0 2 4 6
−4
−3.5
−3
−2.5
−2
−1.5
−1
−0.5
0
0.5
1
x
Plot of f2 = f’’(x)
f
2
Local minimum
Global minima
Global maximum
Calculus
1-43
r et ur ns
g =
–8/(tan(1/2*x)^2+9)
This is cer t ainly not t he or iginal expr ession for f (x). Let ’s look at t he differ ence
f(x) – g(x).
d = f – g
pretty(d)
1 8
[ –––––––––––– + ––––––––––––––– ]
5 + 4 cos(x) 2
tan(1/2 x) + 9
We can simplify t his using simple(d) or simplify(d). Eit her command
pr oduces
ans =
1
This illust r at es t he concept t hat differ ent iat ing f (x) t wice, t hen int egr at ing t he
r esult t wice, pr oduces a funct ion t hat may differ fr om f (x) by a linear funct ion
of x.
Finally, int egr at e f (x) once mor e.
F = int(f)
The r esult
F =
2/3*atan(1/3*tan(1/2*x))
involves t he ar ct angent funct ion.
1 Tutorial
1-44
Though F(x) is t he ant ider ivat ive of a cont inuous funct ion, it is it self
discont inuous as t he following plot shows.
ezplot(F)
Not e t hat F(x) has jumps at x = t π. This occur s because t an x is singular at
x = t π.
−6 −4 −2 0 2 4 6
−1
0.8
0.6
0.4
0.2
0
0.2
0.4
0.6
0.8
1
x
2/3*atan(1/3*tan(1/2*x))
Calculus
1-45
In fact , as
ezplot(atan(tan(x)))
shows, t he numer ical value of atan(tan(x))differ s fr om x by a piecewise
const ant funct ion t hat has jumps at odd mult iples of π/2.
To obt ain a r epr esent at ion of F(x) t hat does not have jumps at t hese point s, we
must int r oduce a second funct ion, J (x), t hat compensat es for t he
discont inuit ies. Then we add t he appr opr iat e mult iple of J (x) t o F(x).
J = sym('round(x/(2*pi))');
c = sym('2/3*pi');
F1 = F+c*J
F1 =
2/3*atan(1/3*tan(1/2*x))+2/3*pi*round(1/2*x/pi)
−6 −4 −2 0 2 4 6
−1.5
−1
−0.5
0
0.5
1
1.5
x
atan(tan(x))
1 Tutorial
1-46
and plot t he r esult .
ezplot(F1,[–6.28,6.28])
This r epr esent at ion does have a cont inuous gr aph.
Not ice t hat we use t he domain [–6.28, 6.28] in ezplot r at her t han t he default
domain [–2π, 2π]. The r eason for t his is t o pr event an evaluat ion of
F1 = 2/3 at an(1/3 t an 1/2 x) at t he singular point s x = –π and x = π wher e t he
jumps in F and J do not cancel out one anot her . The pr oper handling of br anch
cut discont inuit ies in mult ivalued funct ions like ar ct an x is a deep and difficult
pr oblem in symbolic comput at ion. Alt hough MATLAB and Maple cannot do
t his ent ir ely aut omat ically, t hey do pr ovide t he t ools for invest igat ing such
quest ions.
−6 −4 −2 0 2 4 6
−2.5
−2
−1.5
−1
−0.5
0
0.5
1
1.5
2
2.5
x
2/3*atan(1/3*tan(1/2*x))+2/3*pi*round(1/2*x/pi)
Simplifications and Substitutions
1-47
Simplifications and Substitutions
Ther e ar e sever al funct ions t hat simplify symbolic expr essions and ar e used t o
per for m symbolic subst it ut ions.
Simplifications
Her e ar e t hr ee differ ent symbolic expr essions.
syms x
f = x^3–6*x^2+11*x–6
g = (x–1)*(x–2)*(x–3)
h = x*(x*(x–6)+11)–6
Her e ar e t heir pr et t ypr int ed for ms, gener at ed by
pretty(f), pretty(g), pretty(h)
3 2
x – 6 x + 11 x – 6
(x – 1) (x – 2) (x – 3)
x (x (x – 6) + 11) – 6
These expr essions ar e t hr ee differ ent r epr esent at ions of t he same
mat hemat ical funct ion, a cubic polynomial in x.
Each of t he t hr ee for ms is pr efer able t o t he ot her s in differ ent sit uat ions. The
fir st for m, f, is t he most commonly used r epr esent at ion of a polynomial. It is
simply a linear combinat ion of t he power s of x. The second for m, g, is t he
fact or ed for m. It displays t he r oot s of t he polynomial and is t he most accur at e
for numer ical evaluat ion near t he r oot s. But , if a polynomial does not have such
simple r oot s, it s fact or ed for m may not be so convenient . The t hir d for m, h, is
t he Hor ner , or nest ed, r epr esent at ion. For numer ical evaluat ion, it involves t he
fewest ar it hmet ic oper at ions and is t he most accur at e for some ot her r anges of
x.
The symbolic simplificat ion pr oblem involves t he ver ificat ion t hat t hese t hr ee
expr essions r epr esent t he same funct ion. It also involves a less clear ly defined
object ive—which of t hese r epr esent at ions is “t he simplest ”?
1 Tutorial
1-48
This t oolbox pr ovides sever al funct ions t hat apply var ious algebr aic and
t r igonomet r ic ident it ies t o t r ansfor m one r epr esent at ion of a funct ion int o
anot her , possibly simpler , r epr esent at ion. These funct ions ar e collect,
expand, horner, factor, simplify, and simple.
collect
The st at ement
collect(f)
views f as a polynomial in it s symbolic var iable, say x, and collect s all t he
coefficient s wit h t he same power of x. A second ar gument can specify t he
var iable in which t o collect t er ms if t her e is mor e t han one candidat e. Her e ar e
a few examples:
f collect(f)
(x–1)*(x–2)*(x–3) x^3–6*x^2+11*x–6
x*(x*(x–6)+11)–6 x^3–6*x^2+11*x–6
(1+x)*t + x*t 2*x*t+t
Simplifications and Substitutions
1-49
expand
The st at ement
expand(f)
dist r ibut es pr oduct s over sums and applies ot her ident it ies involving funct ions
of sums. For example,
horner
The st at ement
horner(f)
t r ansfor ms a symbolic polynomial f int o it s Hor ner , or nest ed, r epr esent at ion.
For example,
f expand(f)
a∗(x + y) a∗x + a∗y
(x–1)∗(x–2)∗(x–3) x^3–6∗x^2+11∗x–6
x∗(x∗(x–6)+11)–6 x^3–6∗x^2+11∗x–6
exp(a+b) exp(a)∗exp(b)
cos(x+y) cos(x)*cos(y)–sin(x)*sin(y)
cos(3∗acos(x)) 4∗x^3 – 3∗x
f horner(f)
x^3–6∗x^2+11∗x–6 –6+(11+(–6+x)*x)*x
1.1+2.2∗x+3.3∗x^2 11/10+(11/5+33/10*x)*x
1 Tutorial
1-50
factor
If f is a polynomial wit h r at ional coefficient s, t he st at ement
factor(f)
expr esses f as a pr oduct of polynomials of lower degr ee wit h r at ional
coefficient s. If f cannot be fact or ed over t he r at ional number s, t he r esult is f
it self. For example,
Her e is anot her example involving factor. It fact or s polynomials of t he for m
x^n + 1. This code
syms x;
n = 1:9;
x = x(ones(size(n)));
p = x.^n + 1;
f = factor(p);
[p; f].'
r et ur ns a mat r ix wit h t he polynomials in it s fir st column and t heir fact or ed
for ms in it s second:
[ x+1, x+1 ]
[ x^2+1, x^2+1 ]
[ x^3+1, (x+1)*(x^2–x+1) ]
[ x^4+1, x^4+1 ]
[ x^5+1, (x+1)*(x^4–x^3+x^2–x+1) ]
[ x^6+1, (x^2+1)*(x^4–x^2+1) ]
[ x^7+1, (x+1)*(1–x+x^2–x^3+x^4–x^5+x^6) ]
[ x^8+1, x^8+1 ]
[ x^9+1, (x+1)*(x^2–x+1)*(x^6–x^3+1) ]
f factor(f)
x^3–6∗x^2+11∗x–6 (x–1)∗(x–2)∗(x–3)
x^3–6∗x^2+11∗x–5 x^3–6∗x^2+11∗x–5
x^6+1 (x^2+1)∗(x^4–x^2+1)
Simplifications and Substitutions
1-51
As an aside at t his point , we ment ion t hat factor can also fact or symbolic
object s cont aining int eger s. This is an alt er nat ive t o using t he factor funct ion
in MATLAB’s specfun dir ect or y. For example, t he following code segment
one = '1'
for n = 1:11
N(n,:) = sym(one(1,ones(1,n)));
end
[N factor(N)]
displays t he fact or s of symbolic int eger s consist ing of 1s.
[ 1, 1 ]
[ 11, (11) ]
[ 111, (3)*(37) ]
[ 1111, (11)*(101) ]
[ 11111, (41)*(271) ]
[ 111111, (3)*(7)*(11)*(13)*(37) ]
[ 1111111, (239)*(4649) ]
[ 11111111, (11)*(73)*(101)*(137) ]
[ 111111111, (3)^2*(37)*(333667) ]
[ 1111111111, (11)*(41)*(271)*(9091) ]
[ 11111111111, (513239)*(21649) ]
1 Tutorial
1-52
simplify
The simplify funct ion is a power ful, gener al pur pose t ool t hat applies a
number of algebr aic ident it ies involving sums, int egr al power s, squar e r oot s
and ot her fr act ional power s, as well as a number of funct ional ident it ies
involving t r ig funct ions, exponent ial and log funct ions, Bessel funct ions,
hyper geomet r ic funct ions, and t he gamma funct ion. Her e ar e some examples.
simple
The simple funct ion has t he unor t hodox mat hemat ical goal of finding a
simplificat ion of an expr ession t hat has t he fewest number of char act er s. Of
cour se, t her e is lit t le mat hemat ical just ificat ion for claiming t hat one
expr ession is “simpler ” t han anot her just because it s ASCII r epr esent at ion is
shor t er , but t his oft en pr oves sat isfact or y in pr act ice.
The simple funct ion achieves it s goal by independent ly applying simplify,
collect, factor, and ot her simplificat ion funct ions t o an expr ession and
keeping t r ack of t he lengt hs of t he r esult s. The simple funct ion t hen r et ur ns
t he shor t est r esult .
f simplify(f)
x∗(x∗(x–6)+11)–6 x^3–6∗x^2+11∗x–6
(1–x^2)/(1–x) x + 1
(1/a^3+6/a^2+12/a+8)^(1/3) ((2*a+1)^3/a^3)^(1/3)
syms x y positive
log(x∗y) log(x) + log(y)
exp(x) ∗ exp(y) exp(x+y)
besselj(2,x) – ...
2*besselj(1,x)/x +
besselj(0,x)
0
gamma(x+1)–x*gamma(x) 0
cos(x)^2 + sin(x)^2 1
Simplifications and Substitutions
1-53
The simple funct ion has sever al for ms, each r et ur ning differ ent out put . The
for m
simple(f)
displays each t r ial simplificat ion and t he simplificat ion funct ion t hat pr oduced
it in t he MATLAB command window. The simple funct ion t hen r et ur ns t he
shor t est r esult . For example, t he command
simple(cos(x)^2 + sin(x)^2)
displays t he following alt er nat ive simplificat ions in t he MATLAB command
window
simplify:
1
radsimp:
cos(x)^2+sin(x)^2
combine(trig):
1

factor:
cos(x)^2+sin(x)^2

expand:
cos(x)^2+sin(x)^2

convert(exp):
(1/2*exp(i*x)+1/2/exp(i*x))^2–1/4*(exp(i*x)–1/exp(i*x))^2

convert(sincos):
cos(x)^2+sin(x)^2


convert(tan):
(1–tan(1/2*x)^2)^2/(1+tan(1/2*x)^2)^2+4*tan(1/2*x)^2/
(1+tan(1/2*x)^2)^2

collect(x):
cos(x)^2+sin(x)^2
1 Tutorial
1-54
and r et ur ns
ans =
1
This for m is useful when you want t o check, for example, whet her t he shor t est
for m is indeed t he simplest . If you ar e not int er est ed in how simple achieves
it s r esult , use t he for m
f = simple(f)
This for m simply r et ur ns t he shor t est expr ession found. For example, t he
st at ement
f = simple(cos(x)^2+sin(x)^2)
r et ur ns
f =
1
If you want t o know which simplificat ion r et ur ned t he shor t est r esult , use t he
mult iple out put for m
[F, how] = simple(f)
This for m r et ur ns t he shor t est r esult in t he fir st var iable and t he simplificat ion
met hod used t o achieve t he r esult in t he second var iable. For example, t he
st at ement
[f, how] = simple(cos(x)^2+sin(x)^2)
r et ur ns
f =
1

how =
combine(trig)
The simple funct ion somet imes impr oves on t he r esult r et ur ned by simplify,
one of t he simplificat ions t hat it t r ies. For example, when applied t o t he
Simplifications and Substitutions
1-55
examples given for simplify, simple r et ur ns a simpler (or at least shor t er )
r esult in t wo cases:
In some cases, it is advant ageous t o apply simple t wice t o obt ain t he effect of
t wo differ ent simplificat ion funct ions. For example, t he st at ement s
f = (1/a^3+6/a^2+12/a+8)^(1/3);
simple(simple(f))
r et ur n
1/a+2
The fir st applicat ion, simple(f), uses radsimp t o pr oduce (2*a+1)/a; t he
second applicat ion uses combine(trig) t o t r ansfor m t his t o 1/a+2.
The simple funct ion is par t icular ly effect ive on expr essions involving
t r igonomet r ic funct ions. Her e ar e some examples:
f simplify(f) simple(f)
(1/a^3+6/a^2+12/a+8)^(1/3) ((2*a+1)^3/a^3)^(1/3) (2*a+1)/a
syms x y positive
log(x∗y) log(x)+log(y) log(x*y)
f simple(f)
cos(x)^2+sin(x)^2 1
2∗cos(x)^2–sin(x)^2 3∗cos(x)^2–1
cos(x)^2–sin(x)^2 cos(2∗x)
cos(x)+(–sin(x)^2)^(1/2) cos(x)+i∗sin(x)
cos(x)+i∗sin(x) exp(i∗x)
cos(3∗acos(x)) 4∗x^3–3∗x
1 Tutorial
1-56
Substitutions
Ther e ar e t wo funct ions for symbolic subst it ut ion: subexpr and subs.
subexpr
These commands
syms a x
s = solve(x^3+a*x+1)
solve t he equat ion x^3+a*x+1 = 0 for x.
s =
[ (–1/2+1/18*(12*a^3+81)^(1/2))^(1/3)–
1/3*a/(–1/2+1/18*(12*a^3+81)^(1/2))^(1/3) ]
[ –1/2*(–1/2+1/18*(12*a^3+81)^(1/2))^(1/3)+
1/6*a/(–1/2+1/18*(12*a^3+81)^(1/2))^(1/3)+
1/2*i*3^(1/2)*((–1/2+1/18*(12*a^3+81)^(1/2))^(1/3)+
1/3*a/(–1/2+1/18*(12*a^3+81)^(1/2))^(1/3)) ]
[ –1/2*(–1/2+1/18*(12*a^3+81)^(1/2))^(1/3)+
1/6*a/(–1/2+1/18*(12*a^3+81)^(1/2))^(1/3)–
1/2*i*3^(1/2)*((–1/2+1/18*(12*a^3+81)^(1/2))^(1/3)+
1/3*a/(–1/2+1/18*(12*a^3+81)^(1/2))^(1/3)) ]
Simplifications and Substitutions
1-57
Use t he pr et t y funct ion t o display s in a mor e r eadable for m.
pretty(s)

s =
[ 1/3 a ]
[ %1 – 1/3 ----- ]
[ 1/3 ]
[ %1 ]
[ ]
[ 1/3 a 1/2 / 1/3 a \ ]
[ – 1/2 %1 + 1/6 ----- + 1/2 i 3 |%1 + 1/3 -----| ]
[ 1/3 | 1/3| ]
[ %1 \ %1 / ]
[ ]
[ 1/3 a 1/2 / 1/3 a \ ]
[ – 1/2 %1 + 1/6 ----- – 1/2 i 3 |%1 + 1/3 -----| ]
[ 1/3 | 1/3| ]
[ %1 \ %1 / ]

3 1/2
%1 := – 1/2 + 1/18 (12 a + 81)
The pretty command inher it s t he %n (n, an int eger ) not at ion fr om Maple t o
denot e subexpr essions t hat occur mult iple t imes in t he symbolic object . The
subexpr funct ion allows you t o save t hese common subexpr essions as well as
t he symbolic object r ewr it t en in t er ms of t he subexpr essions. The
subexpr essions ar e saved in a column vect or called sigma.
Cont inuing wit h t he example
r = subexpr(s)
1 Tutorial
1-58
r et ur ns
sigma =
–108+12*(12*a^3+81)^(1/2)

r =
[ 1/6*sigma^(1/3)–2*a/sigma^(1/3)]
[ –1/12*sigma^(1/3)+a/sigma^(1/3)+
1/2*i*3^(1/2)*(1/6*sigma^(1/3)+2*a/sigma^(1/3))]
[ –1/12*sigma^(1/3)+a/sigma^(1/3)–
1/2*i*3^(1/2)*(1/6*sigma^(1/3)+2*a/sigma^(1/3))]
Not ice t hat subexpr cr eat es t he var iable sigma in t he MATLAB wor kspace.
You can ver ify t his by t yping whos, or t he command
sigma
which r et ur ns
sigma =
–108+12*(12*a^3+81)^(1/2)
Simplifications and Substitutions
1-59
subs
Let ’s find t he eigenvalues and eigenvect or s of a cir culant mat r ix A.
syms a b c
A = [a b c; b c a; c a b];
[v,E] = eig(A)
v =
[ –(a+(b^2–b*a–c*b–c*a+a^2+c^2)^(1/2)–b)/(a–c),
–(a–(b^2–b*a–c*b–c*a+a^2+c^2)^(1/2)–b)/(a–c), 1]
[ –(b–c–(b^2–b*a–c*b–c*a+a^2+c^2)^(1/2))/(a–c),
–(b–c+(b^2–b*a–c*b–c*a+a^2+c^2)^(1/2))/(a–c), 1]
[ 1,
1, 1]
E =
[ (b^2–b*a–c*b–
c*a+a^2+c^2)^(1/2), 0, 0]
[ 0, –(b^2–b*a–c*b–
c*a+a^2+c^2)^(1/2), 0]
[ 0, 0, b+c+a]
Suppose we want t o r eplace t he r at her lengt hy expr ession
(b^2–b*a–c*b–c*a+a^2+c^2)^(1/2)
t hr oughout v and E. We fir st use subexpr:
v = subexpr(v,'S')
which r et ur ns
S =
(b^2–b*a–c*b–c*a+a^2+c^2)^(1/2)
v =
[ –(a+S–b)/(a–c), –(a–S–b)/(a–c), 1]
[ –(b–c–S)/(a–c), –(b–c+S)/(a–c), 1]
[ 1, 1, 1]
1 Tutorial
1-60
Next , subst it ut e t he symbol S int o E wit h
E = subs(E,S,'S')
E =
[ S, 0, 0]
[ 0, –S, 0]
[ 0, 0, b+c+a]
Now suppose we want t o evaluat e v at a = 10. We can do t his using t he subs
command:
subs(v,a,10)
This r eplaces all occur r ences of a in v wit h 10
[ –(10+S–b)/(10–c), –(10–S–b)/(10–c), 1]
[ –(b–c–S)/(10–c), –(b–c+S)/(10–c), 1]
[ 1, 1, 1]
Not ice, however , t hat t he symbolic expr ession r epr esent ed by S is unaffect ed by
t his subst it ut ion. That is, t he symbol a in S is not r eplaced by 10. The subs
command is also a useful funct ion for subst it ut ing in a var iet y of values for
sever al var iables in a par t icular expr ession. Let ’s look at S. Suppose t hat in
addit ion t o subst it ut ing a = 10, we also want t o subst it ut e t he values for 2 and
10 for b and c, r espect ively. The way t o do t his is t o set values for a, b, and c in
t he wor kspace. Then subs evaluat es it s input using t he exist ing symbolic and
double var iables in t he cur r ent wor kspace. In our example, we fir st set
a = 10; b = 2; c = 10;
subs(S)
ans =
64^(1/2)
Simplifications and Substitutions
1-61
To look at t he cont ent s of our wor kspace, t ype whos, which gives
Name Size Bytes Class
A 3x3 878 sym object
E 3x3 888 sym object
S 1x1 186 sym object
a 1x1 8 double array
ans 1x1 140 sym object
b 1x1 8 double array
c 1x1 8 double array
v 3x3 982 sym object
a, b, and c ar e now var iables of class double while A, E, S, and v r emain symbolic
expr essions (class sym).
If you want t o pr eser ve a, b, and c as symbolic var iables, but st ill alt er t heir
value wit hin S, use t his pr ocedur e.
syms a b c
subs(S,{a,b,c},{10,2,10})
ans =
64^(1/2)
Typing whos r eveals t hat a, b, and c r emain 1-by-1 sym object s.
The subs command can be combined wit h double t o evaluat e a symbolic
expr ession numer ically. Suppose we have
syms t
M = (1–t^2)*exp(–1/2*t^2);
P = (1–t^2)*sech(t);
and want t o see how M and P differ gr aphically.
1 Tutorial
1-62
One appr oach is t o t ype
ezplot(M); hold on; ezplot(P)
but t his plot
does not r eadily help us ident ify t he cur ves.
−6 −4 −2 0 2 4 6
−0.8
−0.6
−0.4
−0.2
0
0.2
0.4
0.6
0.8
1
t
(1−t^2)*sech(t)
Simplifications and Substitutions
1-63
Inst ead, combine subs, double, and plot
T = –6:0.05:6;
MT = double(subs(M,t,T));
PT = double(subs(P,t,T));
plot(T,MT,'b',T,PT,'r–.')
title(' ')
legend('M','P')
xlabel('t'); grid
t o pr oduce a mult icolor ed gr aph t hat indicat es t he differ ence bet ween M and P.
Finally t he use of subs wit h st r ings gr eat ly facilit at es t he solut ion of pr oblems
involving t he Four ier , Laplace, or z-t r ansfor ms. See t he sect ion “Int egr al
Tr ansfor ms” for complet e det ails.
−6 −4 −2 0 2 4 6
−1
−0.8
−0.6
−0.4
−0.2
0
0.2
0.4
0.6
0.8
1
t
M
P
1 Tutorial
1-64
Variable-Precision Arithmetic
Overview
Ther e ar e t hr ee differ ent kinds of ar it hmet ic oper at ions in t his t oolbox.
•Numer ic MATLAB’s float ing-point ar it hmet ic
•Rat ional Maple’s exact symbolic ar it hmet ic
•VPA Maple’s var iable-pr ecision ar it hmet ic
For example, t he MATLAB st at ement s
format long
1/2+1/3
use numer ic comput at ion t o pr oduce
0.83333333333333
Wit h t he Symbolic Mat h Toolbox, t he st at ement
sym(1/2)+1/3
uses symbolic comput at ion t o yield
5/6
And, also wit h t he t oolbox, t he st at ement s
digits(25)
vpa(1/2+1/3)
use var iable-pr ecision ar it hmet ic t o r et ur n
.8333333333333333333333333
The float ing-point oper at ions used by numer ic ar it hmet ic ar e t he fast est of t he
t hr ee, and r equir e t he least comput er memor y, but t he r esult s ar e not exact .
The number of digit s in t he pr int ed out put of MATLAB’s double quant it ies is
cont r olled by t he format st at ement , but t he int er nal r epr esent at ion is always
t he eight -byt e float ing-point r epr esent at ion pr ovided by t he par t icular
comput er har dwar e.
In t he comput at ion of t he numer ic r esult above, t her e ar e act ually t hr ee
r oundoff er r or s, one in t he division of 1 by 3, one in t he addit ion of 1/2 t o t he
Variable-Precision Arithmetic
1-65
r esult of t he division, and one in t he binar y t o decimal conver sion for t he
pr int ed out put . On comput er s t hat use IEEE float ing-point st andar d
ar it hmet ic, t he r esult ing int er nal value is t he binar y expansion of 5/6,
t r uncat ed t o 53 bit s. This is appr oximat ely 16 decimal digit s. But , in t his
par t icular case, t he pr int ed out put shows only 15 digit s.
The symbolic oper at ions used by r at ional ar it hmet ic ar e pot ent ially t he most
expensive of t he t hr ee, in t er ms of bot h comput er t ime and memor y. The r esult s
ar e exact , as long as enough t ime and memor y ar e available t o complet e t he
comput at ions.
Var iable-pr ecision ar it hmet ic falls in bet ween t he ot her t wo in t er ms of bot h
cost and accur acy. A global par amet er , set by t he funct ion digits, cont r ols t he
number of significant decimal digit s. Incr easing t he number of digit s incr eases
t he accur acy, but also incr eases bot h t he t ime and memor y r equir ement s. The
default value of digits is 32, cor r esponding r oughly t o float ing-point accur acy.
The Maple document at ion uses t he t er m “har dwar e float ing-point ” for what we
ar e calling “numer ic” or “float ing-point ” and uses t he t er m “float ing-point
ar it hmet ic” for what we ar e calling “var iable-pr ecision ar it hmet ic.”
Example: Using the Different Kinds of Arithmetic
Rational Arithmetic
By default , t he Symbolic Mat h Toolbox uses r at ional ar it hmet ic oper at ions, i.e.,
Maple’s exact symbolic ar it hmet ic. Rat ional ar it hmet ic is invoked when you
cr eat e symbolic var iables using t he sym funct ion.
The sym funct ion conver t s a double mat r ix t o it s symbolic for m. For example, if
t he double mat r ix is
A =
1.1000 1.2000 1.3000
2.1000 2.2000 2.3000
3.1000 3.2000 3.3000
it s symbolic for m, S = sym(A), is
S =
[11/10, 6/5, 13/10]
[21/10, 11/5, 23/10]
[31/10, 16/5, 33/10]
1 Tutorial
1-66
For t his mat r ix A, it is possible t o discover t hat t he element s ar e t he r at ios of
small int eger s, so t he symbolic r epr esent at ion is for med fr om t hose int eger s.
On t he ot her hand, t he st at ement
E = [exp(1) sqrt(2); log(3) rand]
r et ur ns a mat r ix
E =
2.71828182845905 1.41421356237310
1.09861228866811 0.21895918632809
whose element s ar e not t he r at ios of small int eger s, so sym(E) r epr oduces t he
float ing-point r epr esent at ion in a symbolic for m.
[3060513257434037*2^(–50), 3184525836262886*2^(–51)]
[2473854946935174*2^(–51), 3944418039826132*2^(–54)]
Variable-Precision Numbers
Var iable-pr ecision number s ar e dist inguished fr om t he exact r at ional
r epr esent at ion by t he pr esence of a decimal point . A power of 10 scale fact or ,
denot ed by 'e', is allowed. To use var iable-pr ecision inst ead of r at ional
ar it hmet ic, cr eat e your var iables using t he vpa funct ion.
For mat r ices wit h pur ely double ent r ies, t he vpa funct ion gener at es t he
r epr esent at ion t hat is used wit h var iable-pr ecision ar it hmet ic. Cont inuing on
wit h our example, and using digits(4), applying vpa t o t he mat r ix S
vpa(S)
gener at es t he out put
S =
[1.100, 1.200, 1.300]
[2.100, 2.200, 2.300]
[3.100, 3.200, 3.300]
and wit h digits(25)
F = vpa(E)
Variable-Precision Arithmetic
1-67
gener at es
F =
[2.718281828459045534884808, 1.414213562373094923430017]
[1.098612288668110004152823, .2189591863280899719512718]
Converting to Floating-Point
To conver t a r at ional or var iable-pr ecision number t o it s MATLAB
float ing-point r epr esent at ion, use t he double funct ion.
In our example, bot h double(sym(E)) and double(vpa(E)) r et ur n E.
Another Example
The next example is per haps mor e int er est ing. St ar t wit h t he symbolic
expr ession
f = sym('exp(pi*sqrt(163))')
The st at ement
double(f)
pr oduces t he pr int ed float ing-point value
2.625374126407687e+17
Using t he second ar gument of vpa t o specify t he number of digit s,
vpa(f,18)
r et ur ns
262537412640768744.
wher eas
vpa(f,25)
r et ur ns
262537412640768744.0000000
We suspect t hat f might act ually have an int eger value. This suspicion is
r einfor ced by t he 30 digit value, vpa(f,30)
262537412640768743.999999999999
1 Tutorial
1-68
Finally, t he 40 digit value, vpa(f,40)
262537412640768743.9999999999992500725944
shows t hat f is ver y close t o, but not exact ly equal t o, an int eger .
Linear Algebra
1-69
Linear Algebra
Basic Algebraic Operations
Basic algebr aic oper at ions on symbolic object s ar e t he same as oper at ions on
MATLAB object s of class double. This is illust r at ed in t he following example.
The Givens t r ansfor mat ion pr oduces a plane r ot at ion t hr ough t he angle t. The
st at ement s
syms t;
G = [cos(t) sin(t); –sin(t) cos(t)]
cr eat e t his t r ansfor mat ion mat r ix:
G =
[ cos(t), sin(t) ]
[ –sin(t), cos(t) ]
Applying t he Givens t r ansfor mat ion t wice should simply be a r ot at ion t hr ough
t wice t he angle. The cor r esponding mat r ix can be comput ed by mult iplying G
by it self or by r aising G t o t he second power . Bot h
A = G*G
and
A = G^2
pr oduce
A =
[cos(t)^2–sin(t)^2, 2*cos(t)*sin(t)]
[ –2*cos(t)*sin(t), cos(t)^2–sin(t)^2]
The simple funct ion
A = simple(A)
1 Tutorial
1-70
uses a t r igonomet r ic ident it y t o r et ur n t he expect ed for m by t r ying sever al
differ ent ident it ies and picking t he one t hat pr oduces t he shor t est
r epr esent at ion:
A =
[ cos(2*t), sin(2*t)]
[–sin(2*t), cos(2*t)]
A Givens r ot at ion is an or t hogonal mat r ix, so it s t r anspose is it s inver se.
Confir ming t his by
I = G.' *G
which pr oduces
I =
[cos(t)^2+sin(t)^2, 0]
[ 0, cos(t)^2+sin(t)^2]
and t hen
I = simple(I)
I =
[1, 0]
[0, 1]
Linear Algebraic Operations
Let ’s do sever al basic linear algebr aic oper at ions.
The command
H = hilb(3)
gener at es t he 3-by-3 Hilber t mat r ix. Wit h format short, MATLAB pr int s
H =
1.0000 0.5000 0.3333
0.5000 0.3333 0.2500
0.3333 0.2500 0.2000
Linear Algebra
1-71
The comput ed element s of H ar e float ing-point number s t hat ar e t he r at ios of
small int eger s. Indeed, H is a MATLAB ar r ay of class double. Conver t ing H t o
a symbolic mat r ix
H = sym(H)
gives
[ 1, 1/2, 1/3]
[1/2, 1/3, 1/4]
[1/3, 1/4, 1/5]
This allows subsequent symbolic oper at ions on H t o pr oduce r esult s t hat
cor r espond t o t he infinit ely pr ecise Hilber t mat r ix, sym(hilb(3)), not it s
float ing-point appr oximat ion, hilb(3). Ther efor e,
inv(H)
pr oduces
[ 9, –36, 30]
[–36, 192, –180]
[ 30, –180, 180]
and
det(H)
yields
1/2160
We can use t he backslash oper at or t o solve a syst em of simult aneous linear
equat ions. The commands
b = [1 1 1]'
x = H\b % Solve Hx = b
pr oduce t he solut ion
[ –3]
[–24]
[ 30]
1 Tutorial
1-72
All t hr ee of t hese r esult s, t he inver se, t he det er minant , and t he solut ion t o t he
linear syst em, ar e t he exact r esult s cor r esponding t o t he infinit ely pr ecise,
r at ional, Hilber t mat r ix. On t he ot her hand, using digits(16), t he command
V = vpa(hilb(3))
r et ur ns
[ 1., .5000000000000000, .3333333333333333]
[.5000000000000000, .3333333333333333, .2500000000000000]
[.3333333333333333, .2500000000000000, .2000000000000000]
The decimal point s in t he r epr esent at ion of t he individual element s ar e t he
signal t o use var iable-pr ecision ar it hmet ic. The r esult of each ar it hmet ic
oper at ion is r ounded t o 16 significant decimal digit s. When inver t ing t he
mat r ix, t hese er r or s ar e magnified by t he mat r ix condit ion number , which for
hilb(3) is about 500. Consequent ly,
inv(V)
which r et ur ns
[ 9.000000000000082, –36.00000000000039, 30.00000000000035]
[–36.00000000000039, 192.0000000000021, –180.0000000000019]
[ 30.00000000000035, –180.0000000000019, 180.0000000000019]
shows t he loss of t wo digit s. So does
det(V)
which gives
.462962962962958e–3
and
V\b
which is
[ 3.000000000000041]
[–24.00000000000021]
[ 30.00000000000019]
Since H is nonsingular , t he null space of H
null(H)
Linear Algebra
1-73
and t he column space of H
colspace(H)
pr oduce an empt y mat r ix and a per mut at ion of t he ident it y mat r ix,
r espect ively. To make a mor e int er est ing example, let ’s t r y t o find a value s for
H(1,1) t hat makes H singular . The commands
syms s
H(1,1) = s
Z = det(H)
sol = solve(Z)
pr oduce
H =
[ s, 1/2, 1/3]
[1/2, 1/3, 1/4]
[1/3, 1/4, 1/5]
Z =
1/240*s–1/270
sol =
8/9
Then
H = subs(H,s,sol)
subst it ut es t he comput ed value of sol for s in H t o give
H =
[8/9, 1/2, 1/3]
[1/2, 1/3, 1/4]
[1/3, 1/4, 1/5]
Now, t he command
det(H)
r et ur ns
ans =
0
1 Tutorial
1-74
and
inv(H)
pr oduces an er r or message
??? error using ==> inv
Error, (in inverse) singular matrix
because H is singular . For t his mat r ix, Z = null(H) and C = colspace(H) ar e
nont r ivial.
Z =
[ 1]
[ –4]
[10/3]
C =
[ 0, 1]
[ 1, 0]
[6/5, –3/10]
It should be point ed out t hat even t hough H is singular , vpa(H) is not . For any
int eger value d, set t ing
digits(d)
and t hen comput ing
det(vpa(H))
inv(vpa(H))
r esult s in a det er minant of size 10^(–d) and an inver se wit h element s on t he
or der of 10^d.
Eigenvalues
The symbolic eigenvalues of a squar e mat r ix A or t he symbolic eigenvalues and
eigenvect or s of A ar e comput ed, r espect ively, using t he commands
E = eig(A)
[V,E] = eig(A)
Linear Algebra
1-75
The var iable-pr ecision count er par t s ar e
E = eig(vpa(A))
[V,E] = eig(vpa(A))
The eigenvalues of A ar e t he zer os of t he char act er ist ic polynomial of A,
det(A–x*I), which is comput ed by
poly(A)
The mat r ix H fr om t he last sect ion pr ovides our fir st example.
H =
[8/9, 1/2, 1/3]
[1/2, 1/3, 1/4]
[1/3, 1/4, 1/5]
The mat r ix is singular , so one of it s eigenvalues must be zer o. The st at ement
[T,E] = eig(H)
pr oduces t he mat r ices T and E. The columns of T ar e t he eigenvect or s of H.
T =

[ 1, 28/153+2/153*12589^(1/2), 28/153–2/153*12589^(12)]
[ –4, 1, 1]
[ 10/3, 92/255–1/255*12589^(1/2), 292/255+1/255*12589^(12)]
Similar ly, t he diagonal element s of E ar e t he eigenvalues of H.
E =

[0, 0, 0]
[0, 32/45+1/180*12589^(1/2), 0]
[0, 0, 32/45–1/180*12589^(1/2)]
It may be easier t o under st and t he st r uct ur e of t he mat r ices of eigenvect or s, T,
and eigenvalues, E, if we conver t T and E t o decimal not at ion. We pr oceed as
follows. The commands
Td = double(T)
Ed = double(E)
1 Tutorial
1-76
r et ur n
Td =
1.0000 1.6497 -1.2837
-4.0000 1.0000 1.0000
3.3333 0.7051 1.5851
Ed =
0 0 0
0 1.3344 0
0 0 0.0878
The fir st eigenvalue is zer o. The cor r esponding eigenvect or (t he fir st column of
Ts) is t he same as t he basis for t he null space found in t he last sect ion. The
ot her t wo eigenvalues ar e t he r esult of applying t he quadr at ic for mula t o
x^2–64/45*x+253/2160
which is t he quadr at ic fact or in factor(poly(H)).
syms x
g = simple(factor(poly(H))/x);
solve(g)
Closed for m symbolic expr essions for t he eigenvalues ar e possible only when
t he char act er ist ic polynomial can be expr essed as a pr oduct of r at ional
polynomials of degr ee four or less. The Rosser mat r ix is a classic numer ical
analysis t est mat r ix t hat happens t o illust r at e t his r equir ement . The
st at ement
R = sym(gallery('rosser'))
gener at es
R =
[ 611 196 –192 407 –8 –52 –49 29]
[ 196 899 113 –192 –71 –43 –8 –44]
[–192 113 899 196 61 49 8 52]
[ 407 –192 196 611 8 44 59 –23]
[ –8 –71 61 8 411 –599 208 208]
[ –52 –43 49 44 –599 411 208 208]
[ –49 –8 8 59 208 208 99 –911]
[ 29 –44 52 –23 208 208 –911 99]
Linear Algebra
1-77
The commands
p = poly(R);
pretty(factor(p))
pr oduce
2 2 2
[x (x – 1020) (x – 1020 x + 100)(x – 1040500) (x – 1000) ]
The char act er ist ic polynomial (of degr ee 8) fact or s nicely int o t he pr oduct of t wo
linear t er ms and t hr ee quadr at ic t er ms. We can see immediat ely t hat four of
t he eigenvalues ar e 0, 1020, and a double r oot at 1000. The ot her four r oot s ar e
obt ained fr om t he r emaining quadr at ics. Use
eig(R)
t o find all t hese values
[ 0]
[ 1020]
[510+100*26^(1/2)]
[510–100*26^(1/2)]
[ 10*10405^(1/2)]
[ –10*10405^(1/2)]
[ 1000]
[ 1000]
The Rosser mat r ix is not a t ypical example; it is r ar e for a full 8-by-8 mat r ix t o
have a char act er ist ic polynomial t hat fact or s int o such simple for m. If we
change t he t wo “cor ner ” element s of R fr om 29 t o 30 wit h t he commands
S = R; S(1,8) = 30; S(8,1) = 30;
and t hen t r y
p = poly(S)
we find
p =
40250968213600000+51264008540948000*x–
1082699388411166000*x^2+4287832912719760*x^–3–
5327831918568*x^4+82706090*x^5+5079941*x^6–
4040*x^7+x^8
1 Tutorial
1-78
We also find t hat factor(p) is p it self. That is, t he char act er ist ic polynomial
cannot be fact or ed over t he r at ionals.
For t his modified Rosser mat r ix
F = eig(S)
r et ur ns
F =
[ –1020.0532142558915165931894252600]
[ –.17053529728768998575200874607757]
[ .21803980548301606860857564424981]
[ 999.94691786044276755320289228602]
[ 1000.1206982933841335712817075454]
[ 1019.5243552632016358324933278291]
[ 1019.9935501291629257348091808173]
[ 1020.4201882015047278185457498840]
Not ice t hat t hese values ar e close t o t he eigenvalues of t he or iginal Rosser
mat r ix. Fur t her , t he numer ical values of F ar e a r esult of Maple’s float ing-point
ar it hmet ic. Consequent ly, differ ent set t ings of digits do not alt er t he number
of int eger s t o t he r ight of t he decimal place.
It is also possible t o t r y t o comput e eigenvalues of symbolic mat r ices, but closed
for m solut ions ar e r ar e. The Givens t r ansfor mat ion is gener at ed as t he mat r ix
exponent ial of t he element ar y mat r ix
The Symbolic Mat h Toolbox commands
syms t
A = sym([0 1; –1 0]);
G = expm(t*A)
r et ur n
[ cos(t), sin(t)]
[ –sin(t), cos(t)]
A
0 1
1 – 0
=
Linear Algebra
1-79
Next , t he command
g = eig(G)
pr oduces
g =
[ cos(t)+(cos(t)^2–1)^(1/2)]
[ cos(t)–(cos(t)^2–1)^(1/2)]
We can use simple t o simplify t his for m of g. Indeed, r epeat ed applicat ion of
simple
for j = 1:4
[g,how] = simple(g)
end
pr oduces t he best r esult
g =
[ cos(t)+(–sin(t)^2)^(1/2)]
[ cos(t)–(–sin(t)^2)^(1/2)]
how =
simplify
g =
[ cos(t)+i*sin(t)]
[ cos(t)–i*sin(t)]

how =
radsimp

g =
[ exp(i*t)]
[ 1/exp(i*t)]
1 Tutorial
1-80
how =
convert(exp)
g =
[ exp(i*t)]
[ exp(–i*t)]

how =
simplify
Not ice t he fir st applicat ion of simple uses simplify t o pr oduce a sum of sines
and cosines. Next , simple invokes radsimp t o pr oduce cos(t) + i*sin(t) for
t he fir st eigenvect or . The t hir d applicat ion of simple uses convert(exp) t o
change t he sines and cosines t o complex exponent ials. The last applicat ion of
simple uses simplify t o obt ain t he final for m.
Linear Algebra
1-81
Jordan Canonical Form
The J or dan canonical for m r esult s fr om at t empt s t o diagonalize a mat r ix by a
similar it y t r ansfor mat ion. For a given mat r ix A, find a nonsingular mat r ix V,
so t hat inv(V)*A*V, or , mor e succinct ly, J = V\A*V, is “as close t o diagonal as
possible.” For almost all mat r ices, t he J or dan canonical for m is t he diagonal
mat r ix of eigenvalues and t he columns of t he t r ansfor mat ion mat r ix ar e t he
eigenvect or s. This always happens if t he mat r ix is symmet r ic or if it has
dist inct eigenvalues. Some nonsymmet r ic mat r ices wit h mult iple eigenvalues
cannot be diagonalized. The J or dan for m has t he eigenvalues on it s diagonal,
but some of t he super diagonal element s ar e one, inst ead of zer o. The st at ement
J = jordan(A)
comput es t he J or dan canonical for m of A. The st at ement
[V,J] = jordan(A)
also comput es t he similar it y t r ansfor mat ion. The columns of V ar e t he
gener alized eigenvect or s of A.
The J or dan for m is ext r emely sensit ive t o per t ur bat ions. Almost any change in
A causes it s J or dan for m t o be diagonal. This makes it ver y difficult t o comput e
t he J or dan for m r eliably wit h float ing-point ar it hmet ic. It also implies t hat A
must be known exact ly (i.e., wit hout r ound-off er r or , et c.). It s element s must be
int eger s, or r at ios of small int eger s. In par t icular , t he var iable-pr ecision
calculat ion, jordan(vpa(A)), is not allowed.
For example, let
A = sym([12,32,66,116;–25,–76,–164,–294;
21,66,143,256;–6,–19,–41,–73])
A =
[ 12, 32, 66, 116]
[ –25, –76, –164, –294]
[ 21, 66, 143, 256]
[ –6, –19, –41, –73]
Then
[V,J] = jordan(A)
1 Tutorial
1-82
pr oduces
V =
[ 4, –2, 4, 3]
[ –6, 8, –11, –8]
[ 4, –7, 10, 7]
[ –1, 2, –3, –2]
J =
[ 1, 1, 0, 0]
[ 0, 1, 0, 0]
[ 0, 0, 2, 1]
[ 0, 0, 0, 2]
Ther efor e A has a double eigenvalue at 1, wit h a single J or dan block, and a
double eigenvalue at 2, also wit h a single J or dan block. The mat r ix has only
t wo eigenvect or s, V(:,1) and V(:,3). They sat isfy
A*V(:,1) = 1*V(:,1)
A*V(:,3) = 2*V(:,3)
The ot her t wo columns of V ar e gener alized eigenvect or s of gr ade 2. They
sat isfy
A*V(:,2) = 1*V(:,2) + V(:,1)
A*V(:,4) = 2*V(:,4) + V(:,3)
In mat hemat ical not at ion, wit h v
j
= v(:,j), t he columns of V and eigenvalues
sat isfy t he r elat ionships
Singular Value Decomposition
Only t he var iable-pr ecision numer ic comput at ion of t he singular value
decomposit ion is available in t he t oolbox. One r eason for t his is t hat t he
for mulas t hat r esult fr om symbolic comput at ion ar e usually t oo long and
complicat ed t o be of much use. If A is a symbolic mat r ix of float ing-point or
var iable-pr ecision number s, t hen
S = svd(A)
A λ
2
I – ( )v
4
v
3
=
A λ
1
I – ( )v
2
v
1
=
Linear Algebra
1-83
comput es t he singular values of A t o an accur acy det er mined by t he cur r ent
set t ing of digits. And
[U,S,V] = svd(A);
pr oduces t wo or t hogonal mat r ices, U and V, and a diagonal mat r ix, S, so t hat
A = U*S*V';
Let ’s look at t he n-by-n mat r ix A wit h element s defined by
A(i,j) = 1/(i–j+1/2)
Ther e ar e sever al int er est ing ways t o gener at e t his mat r ix A. They ar e
descr ibed below. For n = 5, t he mat r ix is
[ 2 –2 –2/3 –2/5 –2/7]
[2/3 2 –2 –2/3 –2/5]
[2/5 2/3 2 –2 –2/3]
[2/7 2/5 2/3 2 –2]
[2/9 2/7 2/5 2/3 2]
It t ur ns out many of t he singular values of t hese mat r ices ar e close t o π. When
n = 16, t he MATLAB float ing-point comput at ion svd(A) r esult s in
3.14159265358979
3.14159265358979
3.14159265358979
3.14159265358979
3.14159265358976
3.14159265358767
3.14159265349961
3.14159265052655
3.14159256925492
3.14159075458606
3.14155754359918
3.14106044663470
3.13504054399745
3.07790297231120
2.69162158686066
1.20968137605669
The fir st four singular values appear equal t o π t o t he available pr ecision.
1 Tutorial
1-84
The most obvious way of gener at ing t he 5-by-5 mat r ix A whose i-, j-t h element
1/(i–j+1/2) is
for i=1:n
for j=1:n
A(i,j) = sym(1/(i–j+1/2));
end
end
MATLAB’s mat r ix-based comput at ional par adigm, however , per mit s ot her ,
mor e efficient , appr oaches. Consider t he famous (among MATLAB
afficianados) “Tony’s Tr ick.”
m = ones(n,1); i=(1:n)'; j=1:n;
A = sym(1./(i(:,m)–j(m,:)+1/2));
The most efficient way t o gener at e t his mat r ix is wit h t he pur ely numer ic
st at ement s
[J,I] = meshgrid(1:n);
A = sym(1./(I – J+1/2));
Since t he element s of A ar e t he r at ios of small int eger s, vpa(A) pr oduces a
var iable-pr ecision r epr esent at ion, which is accur at e t o digits pr ecision. Hence
S = svd(vpa(A))
Linear Algebra
1-85
comput es t he desir ed singular values t o full accur acy. Wit h n = 16 and
digits(30), t he r esult is
S =
[ 1.20968137605668985332455685357 ]
[ 2.69162158686066606774782763594 ]
[ 3.07790297231119748658424727354 ]
[ 3.13504054399744654843898901261 ]
[ 3.14106044663470063805218371924 ]
[ 3.14155754359918083691050658260 ]
[ 3.14159075458605848728982577119 ]
[ 3.14159256925492306470284863102 ]
[ 3.14159265052654880815569479613 ]
[ 3.14159265349961053143856838564 ]
[ 3.14159265358767361712392612384 ]
[ 3.14159265358975439206849907220 ]
[ 3.14159265358979270342635559051 ]
[ 3.14159265358979323325290142781 ]
[ 3.14159265358979323843066846712 ]
[ 3.14159265358979323846255035974 ]
Ther e ar e t wo ways t o compar e S wit h pi, t he float ing-point r epr esent at ion of
π. In t he vect or below, t he fir st element is comput ed by subt r act ion wit h
var iable-pr ecision ar it hmet ic and t hen conver t ed t o a double. The second
element is comput ed wit h float ing-point ar it hmet ic.
[double(pi*ones(16,1)–S) pi–double(S)]
1 Tutorial
1-86
The r esult s ar e
1.9319e+00 1.9319e+00
4.4997e–01 4.4997e–01
6.3690e–02 6.3690e–02
6.5521e–03 6.5521e–03
5.3221e–04 5.3221e–04
3.5110e–05 3.5110e–05
1.8990e–06 1.8990e–06
8.4335e–08 8.4335e–08
3.0632e–09 3.0632e–09
9.0183e–11 9.0183e–11
2.1196e–12 2.1196e–12
3.8846e–14 3.8636e–14
5.3504e–16 4.4409e–16
5.2097e–18 0
3.1975e–20 0
9.3024e–23 0
Since t he r elat ive accur acy of pi is pi*eps, which is 6.9757e–16, eit her column
confir ms our suspicion t hat four of t he singular values of t he 16-by-16 example
equal π t o float ing-point accur acy.
Eigenvalue Trajectories
This example applies sever al numer ic, symbolic, and gr aphic t echniques t o
st udy t he behavior of mat r ix eigenvalues as a par amet er in t he mat r ix is
var ied. This par t icular set t ing involves numer ical analysis and per t ur bat ion
t heor y, but t he t echniques illust r at ed ar e mor e widely applicable.
In t his example, we consider a 3-by-3 mat r ix A whose eigenvalues ar e 1, 2, 3.
Fir st , we per t ur b A by anot her mat r ix E and par amet er t: A → A + tE. As t
Linear Algebra
1-87
incr eases fr om 0 t o 10
–6
, t he eigenvalues λ
1
= 1, λ
2
= 2, λ
3
= 3 change t o
λ
1
' ≈ 1.5596 + 0.2726i, λ
2
' ≈ 1.5596 – 0.2726i, λ
3
' ≈ 2.8808.
This, in t ur n, means t hat for some value of t = τ, 0 < τ < 10
–6
, t he per t ur bed
mat r ix A(t) = A + tE has a double eigenvalue λ
1
= λ
2
.
Let ’s find t he value of t, called τ, wher e t his happens.
The st ar t ing point is a MATLAB t est example, known as gallery(3).
A = gallery(3)
A =
–149 –50 –154
537 180 546
–27 –9 –25
This is an example of a mat r ix whose eigenvalues ar e sensit ive t o t he effect s of
r oundoff er r or s int r oduced dur ing t heir comput at ion. The act ual comput ed
0 0.5 1 1.5 2 2.5 3 3.5
−0.3
−0.2
−0.1
0
0.1
0.2
0.3
λ(1) λ(2) λ(3)
λ’(1)
λ’(2)
λ’(3)
1 Tutorial
1-88
eigenvalues may var y fr om one machine t o anot her , but on a t ypical
wor kst at ion, t he st at ement s
format long
e = eig(A)
pr oduce
e =
0.99999999999642
2.00000000000579
2.99999999999780
Of cour se, t he example was cr eat ed so t hat it s eigenvalues ar e act ually 1, 2, and
3. Not e t hat t hr ee or four digit s have been lost t o r oundoff. This can be easily
ver ified wit h t he t oolbox. The st at ement s
B = sym(A);
e = eig(B)'
p = poly(B)
f = factor(p)
pr oduce
e =
[1, 2, 3]
p =
x^3–6*x^2+11*x–6
f =
(x–1)*(x–2)*(x–3)
Ar e t he eigenvalues sensit ive t o t he per t ur bat ions caused by r oundoff er r or
because t hey ar e “close t oget her ”? Or dinar ily, t he values 1, 2, and 3 would be
r egar ded as “well separ at ed.” But , in t his case, t he separ at ion should be viewed
on t he scale of t he or iginal mat r ix. If A wer e r eplaced by A/1000, t he
eigenvalues, which would be .001, .002, .003, would “seem” t o be closer
t oget her .
But eigenvalue sensit ivit y is mor e subt le t han just “closeness.” Wit h a car efully
chosen per t ur bat ion of t he mat r ix, it is possible t o make t wo of it s eigenvalues
Linear Algebra
1-89
coalesce int o an act ual double r oot t hat is ext r emely sensit ive t o r oundoff and
ot her er r or s.
One good per t ur bat ion dir ect ion can be obt ained fr om t he out er pr oduct of t he
left and r ight eigenvect or s associat ed wit h t he most sensit ive eigenvalue. The
following st at ement cr eat es
E = [130,–390,0;43,–129,0;133,–399,0]
t he per t ur bat ion mat r ix
E =
130 –390 0
43 –129 0
133 –399 0
The per t ur bat ion can now be expr essed in t er ms of a single, scalar par amet er
t. The st at ement s
syms x t
A = A+t*E
r eplace A wit h t he symbolic r epr esent at ion of it s per t ur bat ion.
A =
[–149+130*t, –50–390*t, –154]
[ 537+43*t, 180–129*t, 546]
[ –27+133*t, –9–399*t, –25]
Comput ing t he char act er ist ic polynomial of t his new A
p = poly(A)
gives
p =
x^3+(–t–6)*x^2+(492512*t+11)*x–6–1221271*t
Pr et t ypr int ing
pretty(collect(p,x))
shows mor e clear ly t hat p is a cubic in x whose coefficient s var y linear ly wit h t
3 2
[ x + (– t – 6) x + (492512 t + 11) x – 6 – 1221271 t ]
1 Tutorial
1-90
It t ur ns out t hat when t is var ied over a ver y small int er val, fr om 0 t o 1.0e–6,
t he desir ed double r oot appear s. This can best be seen gr aphically. The fir st
figur e shows plot s of p, consider ed as a funct ion of x, for t hr ee differ ent values
of t: t = 0, t = 0.5e–6, and t = 1.0e–6. For each value, t he eigenvalues ar e
comput ed numer ically and also plot t ed.
x = .8:.01:3.2;
for k = 0:2
c = sym2poly(subs(p,t,k*0.5e–6));
y = polyval(c,x);
lambda = eig(double(subs(A,t,k*0.5e–6)));
subplot(3,1,3–k)
plot(x,y,'–',x,0*x,':',lambda,0*lambda,'o')
axis([.8 3.2 –.5 .5])
text(2.25,.35,['t = ' num2str( k*0.5e–6 )]);
end
The bot t om subplot shows t he unper t ur bed polynomial, wit h it s t hr ee r oot s at
1, 2, and 3. The middle subplot shows t he fir st t wo r oot s appr oaching each
1 1.5 2 2.5 3
−0.5
0
0.5
t = 0
1 1.5 2 2.5 3
−0.5
0
0.5
t = 5e−07
1 1.5 2 2.5 3
−0.5
0
0.5
t = 1e−06
Linear Algebra
1-91
ot her . In t he t op subplot , t hese t wo r oot s have become complex and only one
r eal r oot r emains.
The next st at ement s comput e and display t he act ual eigenvalues
e = eig(A);
pretty(e)
showing t hat e(2) and e(3) for m a complex conjugat e pair .
[ 1/3 ]
[ 1/3 %1 – 3 %2 + 2 + 1/3 t ]
[ ]
[ 1/3 1/2 1/3 ]
[– 1/6 %1 + 3/2 %2 + 2 + 1/3 t + 1/2 i 3 (1/3 %1 + 3 %2)]
[ ]
[ 1/3 1/2 1/3 ]
[– 1/6 %1 + 3/2 %2 + 2 + 1/3 t – 1/2 i 3 (1/3 %1 + 3 %2)]

2 3
%1 := 3189393 t – 2216286 t + t + 3 (–3 + 4432572 t
2 3
– 1052829647418 t + 358392752910068940 t
4 1/2
– 181922388795 t )

2
– 1/3 + 492508/3 t – 1/9 t
%2 := ---------------------------
1/3
%1
1 Tutorial
1-92
Next , t he symbolic r epr esent at ions of t he t hr ee eigenvalues ar e evaluat ed at
many values of t
tvals = (2:–.02:0)' * 1.e–6;
r = size(tvals,1);
c = size(e,1);
lambda = zeros(r,c);
for k = 1:c
lambda(:,k) = double(subs(e(k),t,tvals));
end
plot(lambda,tvals)
xlabel('\lambda'); ylabel('t');
title('Eigenvalue Transition')
t o pr oduce a plot of t heir t r aject or ies:
Above t = 0.8e
–6
, t he gr aphs of t wo of t he eigenvalues int er sect , while below
t = 0.8e
–6
, t wo r eal r oot s become a complex conjugat e pair . What is t he pr ecise
value of t t hat mar ks t his t r ansit ion? Let τ denot e t his value of t.
1 1.2 1.4 1.6 1.8 2 2.2 2.4 2.6 2.8 3
0
0.2
0.4
0.6
0.8
1
1.2
1.4
1.6
1.8
2
x 10
−6
λ
t
Eigenvalue Transition
Linear Algebra
1-93
One way t o find t he exact value of τ involves polynomial discr iminant s. The
discr iminant of a quadr at ic polynomial is t he familiar quant it y under t he
squar e r oot sign in t he quadr at ic for mula. When it is negat ive, t he t wo r oot s
ar e complex.
Ther e is no discrim funct ion in t he t oolbox, but t her e is one in Maple and it can
be accessed t hr ough t he t oolbox’s maple funct ion. The st at ement
mhelp discrim
pr ovides a br ief explanat ion. Use t hese commands
syms a b c x
maple('discrim', a*x^2+b*x+c, x)
t o show t he gener ic quadr at ic’s discr iminant , b
2
– 4ac
ans =
–4*a*c+b^2
The discr iminant for t he per t ur bed cubic char act er ist ic polynomial is obt ained,
using
discrim = maple('discrim',p,x)
which pr oduces
[discrim =
4–5910096*t+1403772863224*t^2–
477857003880091920*t^3+242563185060*t^4]
The quant it y τ is one of t he four r oot s of t his quar t ic. Let ’s find a numer ic value
for τ
digits(24)
s = solve(discrim);
tau = vpa(s)
tau =
[ 1970031.04061804553618913]
[ .783792490602e–6]
[ .1076924816049e–5+.318896441018863170083895e–5*i]
[ .1076924816049e–5–.318896441018863170083895e–5*i]
1 Tutorial
1-94
Of t he four solut ions, we know t hat
tau = tau(2)
is t he t r ansit ion point
tau =
.783792490602e–6
because it is closest t o our pr evious est imat e.
A mor e gener ally applicable met hod for finding τ is based on t he fact t hat , at a
double r oot , bot h t he funct ion and it s der ivat ive must vanish. This r esult s in
t wo polynomial equat ions t o be solved for t wo unknowns. The st at ement
sol = solve(p,diff(p,x))
solves t he pair of algebr aic equat ions p = 0 and dp/dx = 0 and pr oduces
sol =
t: [4x1 sym]
x: [4x1 sym]
Find τ now by
tau = double(sol.t(2))
which r eveals t hat t he second element of sol.t is t he desir ed value of τ
format short
tau =
7.8379e–07
Ther efor e, t he second element of sol.x
sigma = double(sol.x(2))
is t he double eigenvalue
sigma =
1.5476
Linear Algebra
1-95
Let ’s ver ify t hat t his value of τ = 7.8379e – 07 does indeed pr oduce a double
eigenvalue at σ = 1.5476. To achieve t his, subst it ut e τ for t in t he per t ur bed
mat r ix A(t) = A + tE and find t he eigenvalues of A(t). That is,
e = eig(double(subs(A,t,tau)))
e =

1.5476
1.5476
2.9047
confir ms t hat σ = 1.5476 is a double eigenvalue of A(t) for t = 7.8379e – 07.
1 Tutorial
1-96
Solving Equations
Solving Algebraic Equations
If S is a symbolic expr ession,
solve(S)
at t empt s t o find values of t he symbolic var iable in S (as det er mined by
findsym) for which S is zer o. For example
syms a b c x
S = a*x^2 + b*x + c;
solve(S)
uses t he familiar quadr at ic for mula t o pr oduce
ans =
[1/2/a*(–b+(b^2–4*a*c)^(1/2))]
[1/2/a*(–b–(b^2–4*a*c)^(1/2))]
This is a symbolic vect or whose element s ar e t he t wo solut ions.
If you want t o solve for a specific var iable, you must specify t hat var iable as an
addit ional ar gument . For example, if you want t o solve S for b, use t he
command
b = solve(S,b)
which r et ur ns
b =
–(a*x^2+c)/x
Not e t hat t hese examples assume equat ions of t he for m f(x) = 0. If you need t o
solve equat ions of t he for m f(x) = q(x), you must use quot ed st r ings. In
par t icular , t he command
s = solve('cos(2*x)+sin(x)=1')
Solving Equations
1-97
r et ur ns a vect or wit h four solut ions.
s =
[ 0]
[ pi]
[ 1/6*pi]
[ 5/6*pi]
The equat ion x
3
– 2x
2
= x – 1 helps us under st and t he out put of solve. Type
s = solve('x^3–2*x^2 = x–1')
s =
[ 1/6*(28+84*i*3^(1/2))^(1/3)+14/3/(28+84*i*3^(1/2))^(1/3)+2/3]
[ –1/12*(28+84*i*3^(1/2))^(1/3)–7/3/(28+84*i*3^(1/2))^(1/3)
+2/3+1/2*i*3^(1/2)*(1/6*(28+84*i*3^(1/2))^(1/3)
–14/3/(28+84*i*3^(1/2))^(1/3))]
[ –1/12*(28+84*i*3^(1/2))^(1/3)–7/3/(28+84*i*3^(1/2))^(1/3)
+2/3–1/2*i*3^(1/2)*(1/6*(28+84*i*3^(1/2))^(1/3)
–14/3/(28+84*i*3^(1/2))^(1/3))]
To gain mor e insight int o t his solut ion, let ’s see t he numer ic r esult s
double(s)
ans =

2.24697960371747 + 0.00000000000000i
–0.80193773580484 + 0.00000000000000i
0.55495813208737 – 0.00000000000000i
It appear s t hat t he r oot s of x
3
– 2x
2
= x – 1 ar e all r eal. This is misleading.
Applying t he vpa command
vpa(s, 10)
yields
ans =

[ 2.246979604+.1e–9*i]
[ –.8019377357+.3e–9*i]
[ .5549581323–.5e–9*i]
1 Tutorial
1-98
This shows t hat t he imaginar y par t s of s ar e small, but st ill nonzer o.
As anot her example, consider t he commands
syms x
s = solve(tan(x)+sin(x)–2);
This r esult s in a lengt hy 4-by-1 symbolic vect or whose qualit at ive feat ur es ar e,
at best , cr ypt ic. As above, use t he double command
X = double(s)
which pr oduces
X =
0.8863
–1.8979
2.0766– 1.5151i
2.0766+ 1.5151i
Ar e t hese t he only t wo r eal solut ions of t an(x) + sin(x) – 2 for x ∈ [-2π, 2π]? To
answer t his quest ion, plot t he funct ion against t he r eal axis
ezplot(tan(x)+sin(x)–2)
hold on
w = –2*pi:pi/2:2*pi;
plot(w,0*w,'r-.');
Solving Equations
1-99
The r esult ing plot
−6 −4 −2 0 2 4 6
−10
−5
0
5
x
tan(x)+sin(x)−2
1 Tutorial
1-100
shows t hat t an(x) + sin(x) – 2 has four int er sect ions wit h t he r eal axis for x ∈ [–
2π, 2π]. Since t he fir st t wo element s of t he solut ion vect or X ar e r eal, we can plot
t hese on our cur r ent figur e.
RX = [X(1), X(2)]
plot(RX, 0*RX,'gO')
text(–1.8,–0.4,'X(2)')
text(1.0,–0.4,'X(1)')
−6 −4 −2 0 2 4 6
−10
−5
0
5
x
tan(x)+sin(x)−2
X(2) X(1)
Solving Equations
1-101
To display t he r emaining t wo r oot s in t he int er val [–2π, 2π], subt r act 2π fr om
X(1) = 0.8863, add 2π t o X(2) = –1.8970, and plot t he point s
PX = [X(1)–2*pi,X(2)+2*pi]
plot(PX, 0*PX,'kO')
hold off
−6 −4 −2 0 2 4 6
−10
−5
0
5
x
tan(x)+sin(x)−2
X(2) X(1) X(1)−2*pi X(2)+2*pi
1 Tutorial
1-102
Again for
f = cos(2*x) + sin(x) – 1;
s = solve(f);
plot t ing s and f, using
ezplot(f)
hold on;
plot(w,0*w,'r-.')
plot(double(s),0*double(s),'gO')
−6 −4 −2 0 2 4 6
−3
−2.5
−2
−1.5
−1
−0.5
0
x
cos(2*x)+sin(x)−1
Solving Equations
1-103
makes it clear t hat solve does not r et ur n all solut ions. Plot t ing t he point s
–2*pi, –11/6*pi, –(7/6)*pi, –p along wit h f shows that these points are
also solutions.
s2 = [–2*pi, –11/6*pi, –(7/6)*pi, –pi]
plot(s2, 0*s2, 'kX')
If we cannot find a symbolic solut ion, we can comput e a var iable-pr ecision one.
For example
digits(6)
syms x
X = solve(log(x)–sin(x)) % Equivalently, solve('log(x)=sin(x)')
r esult s in
X =
.996957e-1-1.19186*i
−6 −4 −2 0 2 4 6
−3
−2.5
−2
−1.5
−1
−0.5
0
x
( ) ( )
1 Tutorial
1-104
Several Algebraic Equations
Now let 's look at syst ems of equat ions. Suppose we have t he syst em
and we want t o solve for x and y. Fir st cr eat e t he necessar y symbolic object s
syms x y alpha
Ther e ar e sever al ways t o addr ess t he out put of solve. One is t o use a
t wo-out put call
[x,y] = solve(x^2*y^2; x–(y/2)–alpha)
which r et ur ns
x =
[ 0]
[ 0]
[ alpha]
[ alpha]
y =
[ –2*alpha]
[ –2*alpha]
[ 0]
[ 0]
Consequent ly, t he solut ion vect or
v = [x, y]
appear s t o have r edundant component s. This is due t o t he fir st equat ion
x
2
y
2
= 0, which has t wo solut ions in x and y: x = t0, y = t0. A per t ur bat ion t o
t he equat ions in t he for m of
eqs1 = 'x^2*y^2=1, x–1/2*y–alpha'
x
2
y
2
0 =
x
y
2
--- – α =
Solving Equations
1-105
pr oduces four dist inct solut ions.
x =
[ 1/2*alpha+1/2*(alpha^2+2)^(1/2)]
[ 1/2*alpha–1/2*(alpha^2+2)^(1/2)]
[ 1/2*alpha+1/2*(alpha^2–2)^(1/2)]
[ 1/2*alpha–1/2*(alpha^2–2)^(1/2)]


y =
[ –alpha+(alpha^2+2)^(1/2)]
[ –alpha–(alpha^2+2)^(1/2)]
[ –alpha+(alpha^2–2)^(1/2)]
[ –alpha–(alpha^2–2)^(1/2)]
Since we did not specify t he dependent var iables, solve uses findsym t o
det er mine t he var iables.
This way of assigning out put fr om solve is quit e successful for “small” syst ems.
Plainly, if we had, say, a 10-by-10 syst em of equat ions, t yping
[x1,x2,x3,x4,x5,x6,x7,x8,x9,x10] = solve(...)
is bot h awkwar d and t ime consuming. To cir cumvent t his difficult y, solve can
r et ur n a st r uct ur e whose fields ar e t he solut ions. In par t icular , consider t he
syst em u^2–v^2 = a^2, u + v = 1, a^2–2*a = 3. The command
S = solve('u^2–v^2 = a^2','u + v = 1','a^2–2*a = 3')
r et ur ns
S =
a: [2x1 sym]
u: [2x1 sym]
v: [2x1 sym]
The solut ions for a r eside in t he “a-field” of S. That is,
S.a
pr oduces
ans =
[ –1]
[ 3]
1 Tutorial
1-106
Similar comment s apply t o t he solut ions for u and v. The st r uct ur e S can now
be manipulat ed by field and index t o access a par t icular por t ion of t he solut ion.
For example, if we want t o examine t he second solut ion, we can use t he
following st at ement
s2 = [S.a(2), S.u(2), S.v(2)]
t o ext r act t he second component of each field
s2 =
[ 3, 5, –4]
The following st at ement
M = [S.a, S.u, S.v]
cr eat es t he solut ion mat r ix M
M =
[ –1, 1, 0]
[ 3, 5, –4]
whose r ows compr ise t he dist inct solut ions of t he syst em.
Linear syst ems of simult aneous equat ions can also be solved using mat r ix
division. For example,
clear u v x y
syms u v x y
S = solve(x+2*y–u, 4*x+5*y–v);
sol = [S.x;S.y]
and
A = [1 2; 4 5];
b = [u; v];
z = A\b
Solving Equations
1-107
r esult in
sol =

[ –5/3*u+2/3*v]
[ 4/3*u–1/3*v]
z =
[ –5/3*u+2/3*v]
[ 4/3*u–1/3*v]
Thus s and z pr oduce t he same solut ion, alt hough t he r esult s ar e assigned t o
differ ent var iables.
Single Differential Equation
The funct ion dsolve comput es symbolic solut ions t o or dinar y differ ent ial
equat ions. The equat ions ar e specified by symbolic expr essions cont aining t he
let t er D t o denot e differ ent iat ion. The symbols D2, D3, ... DN, cor r espond t o t he
second, t hir d, ..., Nt h der ivat ive, r espect ively. Thus, D2y is t he Symbolic Mat h
Toolbox equivalent of d
2
y/dt
2
. The dependent var iables ar e t hose pr eceded by D
and t he default independent var iable is t. Not e t hat names of symbolic
var iables should not cont ain D. The independent var iable can be changed fr om
t t o some ot her symbolic var iable by including t hat var iable as t he last input
ar gument .
Init ial condit ions can be specified by addit ional equat ions. If init ial condit ions
ar e not specified, t he solut ions cont ain const ant s of int egr at ion, C1, C2, et c.
The out put fr om dsolve par allels t he out put fr om solve. That is, you can call
dsolve wit h t he number of out put var iables equal t o t he number of dependent
var iables or place t he out put in a st r uct ur e whose fields cont ain t he solut ions
of t he differ ent ial equat ions. The t able below det ails t he out put synt ax.
Syntax Scope
y = dsolve('Dyt= y0*y') One equat ion, one out put
1 Tutorial
1-108
Example 1
The following call t o dsolve
dsolve('Dy=1+y^2')
uses y as t he dependent var iable and t as t he default independent var iable.
The out put of t his command is
ans =
tan(t–C1)
To specify an init ial condit ion, use
y = dsolve('Dy=1+y^2','y(0)=1')
This pr oduces
y =
tan(t+1/4*pi)
Not ice t hat y is in t he MATLAB wor kspace, but t he independent var iable t is
not . Thus, t he command diff(y,t) r et ur ns an er r or . To place t in t he
wor kspace, t ype syms t.
Example 2
Nonlinear equat ions may have mult iple solut ions, even when init ial condit ions
ar e given.
x = dsolve('(Dx)^2+x^2=1','x(0)=0')
r esult s in
x =
[–sin(t)]
[ sin(t)]
[u,v] = dsolve('Du = v', 'Dv = u') Two equat ions, t wo out put
S = dsolve('Df=g','Dg=h','Dh=–f')
S.f, S.g, S.h
Thr ee equat ions, out put
st r uct ur e
Solut ions
Syntax Scope
Solving Equations
1-109
Example 3
Her e is a second or der differ ent ial equat ion wit h t wo init ial condit ions. The
command
y = dsolve('D2y=cos(2*x)–y','y(0)=1','Dy(0)=0', 'x')
pr oduces
y =
–2/3*cos(x)^2+1/3+4/3*cos(x)
The key issues in t his example ar e t he or der of t he equat ion and t he init ial
condit ions. To solve t he or dinar y differ ent ial equat ion
u(0) = 1, u'(0) = –1, u''(0) = π
simply t ype
u = dsolve('D3u=u','u(0)=1','Du(0)=–1','D2u(0) = pi','x')
Use D3u t o r epr esent d
3
u/dx
3
and D2u(0) for u''(0).
Several Differential Equations
The funct ion dsolve can also handle sever al or dinar y differ ent ial equat ions in
sever al var iables, wit h or wit hout init ial condit ions. For example, her e is a pair
of linear , fir st or der equat ions.
S = dsolve('Df = 3*f+4*g', 'Dg = –4*f+3*g')
The comput ed solut ions ar e r et ur ned in t he st r uct ur e S. You can det er mine t he
values of f and g by t yping
f = S.f
f =
C2*exp(3*t)*sin(4*t)–C1*exp(3*t)*cos(4*t)
g = S.g
g =
C1*exp(3*t)*sin(4*t)+C2*exp(3*t)*cos(4*t)
x
3
3
d
d u
u =
1 Tutorial
1-110
If you pr efer t o r ecover f and g dir ect ly as well as include init ial condit ions,
t ype
[f,g] = dsolve('Df=3*f+4*g, Dg =–4*f+3*g', 'f(0) = 0, g(0) = 1')
f =
exp(3*t)*sin(4*t)
g =
exp(3*t)*cos(4*t)
This t able det ails some examples and Symbolic Mat h Toolbox synt ax. Not e t hat
t he final ent r y in t he t able is t he Air y differ ent ial equat ion whose solut ion is
r efer r ed t o as t he Air y funct ion.
The Air y funct ion plays an impor t ant r ole in t he mat hemat ical modeling of t he
disper sion of wat er waves. It is a nont r ivial exer cise t o show t hat t he Four ier
t r ansfor m of t he Air y funct ion is exp(iw
3
/3). Wit h t his in mind, we pr oceed t o
Differential Equation MATLAB Command
y = dsolve('Dy+4*y = exp(–t)',
'y(0) = 1')
y = dsolve('D2y+4*y = exp(–2*x)',
'y(0)=0', 'y(pi) = 0', 'x')
(The Air y Equat ion)
y = dsolve('D2y = x*y','y(0) = 0',
'y(3) = besselk(1/3, 2*sqrt(3))/pi',
'x')
t d
dy
4y t ( ) + e
t –
=
y 0 ( ) 1 =
x
2
2
d
d y
4y x ( ) + e
2x –
=
y 0 ( ) 0 y π ( ) 0 = , =
x
2
2
d
d y
xy x ( ) =
y 0 ( ) 0 y 3 ( )
1
π
---K
1
3
---
2 3 ( ) = , =
Solving Equations
1-111
t he sect ion “Int egr al Tr ansfor ms”—t he next st op on our t our of t he Symbolic
Mat h Toolbox.
1 Tutorial
1-112
Integral Transforms
Int egr al t r ansfor ms and t heir discr et e count er par t s ar e power ful and
impor t ant comput at ional t ools in engineer ing, applied mat hemat ics, and
science. The Laplace t r ansfor m act s on cont inuous syst ems (differ ent ial
equat ions); it s discr et e analog, t he z-t r ansfor m, oper at es on discr et e syst ems
(differ ence equat ions). Similar ly, t he Four ier t r ansfor m oper at es on cont inuous
funct ions; t he discr et e Four ier t r ansfor m (DFT), on finit e dat a samples. The
most famous and efficient DFT is t he fast Four ier t r ansfor m (FFT).
The Symbolic Mat h Toolbox pr ovides commands t hat enable you t o comput e
t he analyt ic Four ier , Laplace, and z-t r ansfor ms and t heir inver ses. If you want
t o t ake t he FFT of a dat a set , use t he MATLAB command fft. The following
sect ions descr ibe t he Symbolic Mat h Toolbox synt ax for t hese t hr ee
fundament al t r ansfor ms and t heir inver ses.
The Fourier and Inverse Fourier Transforms
The Four ier t r ansfor m of a funct ion f(x) is defined as
and t he inver se Four ier t r ansfor m (IFT) as
We r efer t o t his for mulat ion as t he Four ier t r ansfor m of f wit h r espect t o x as
a funct ion of w. Or , mor e concisely, t he Four ier t r ansfor m of f wit h r espect t o x
at w. Mat hemat icians oft en use t he not at ion F[f] t o denot e t he Four ier
t r ansfor m of f. In t his set t ing, t he t r ansfor m is t aken wit h r espect t o t he
independent var iable of f (if f = f(t), t hen t is t he independent var iable; f = f(x)
implies t hat x is t he independent var iable, et c.) at t he default var iable w. We
r efer t o F[f] as t he Four ier t r ansfor m of f at w and F
–1
[f] is t he IFT of f at x. See
fourier and ifourier in t he r efer ence pages for t ables t hat show t he Symbolic
Mat h Toolbox commands equivalent t o var ious mat hemat ical r epr esent at ions
of t he Four ier and inver se Four ier t r ansfor ms.
F f [ ] w ( ) f x ( )e
i wx –
x d
∞ –


=
F
1 –
f [ ] x ( )
1

------ f w ( )e
i wx
w d
∞ –


=
Integral Transforms
1-113
In t he sect ion on differ ent ial equat ions, we ment ioned t he Air y differ ent ial
equat ion
whose solut ion, A(x), has a Four ier t r ansfor m of
Let ’s ver ify t his claim wit h t he Symbolic Mat h Toolbox. Indeed,
if and only if
The st at ement s
syms w x
A = ifourier(exp(i*w^3/3),w,x);
A = simple(A);
pretty(A)
r et ur n
1/2 1/2 1/2 1/3 3/2
3 x besselk(1/3, 2/9 3 (x 3 ) )
1/3 ------------------------------------------------------
pi
x
2
2
d
d y
xy x ( ) =
e
i w
3
3 ⁄
F A [ ] e
i w
3
3 ⁄
=
A F
1 –
e
i w
3
3 ⁄
[ ] =
A x ( )
x
3
---
K
1 3 ⁄
2
3
---x
3 2 ⁄
. ,
| `
π
---------------------------------- =
1 Tutorial
1-114
wher e K
1/3
(z) is a Bessel funct ion of t he second kind of or der 1/3. Solving t he
Air y differ ent ial equat ion
Y = dsolve('D2y = x*y','x');
pretty(Y)
r et ur ns
1/2 3/2 1/2 3/2
C1 x besseli(1/3, 2/3 x ) + C2 x besselk(1/3, 2/3 x )
and set t ing
yields A(x).
An applicat ion of t he Four ier t r ansfor m is t he solut ion of or dinar y and par t ial
differ ent ial equat ions over t he r eal line. Consider t he defor mat ion of an
infinit ely long beam r est ing on an elast ic foundat ion wit h a shock applied t o it
at a point . A “r eal wor ld” analogy t o t his phenomenon is a set of r ailr oad t r acks
at op a r oad bed.
C1 0 C2
1

----------- = , =
δ(x)
shock
road
bed
k
x
bed rock
y(x)
stiffness
constant
.......
Integral Transforms
1-115
The shock could be induced by a pneumat ic hammer blow (or a swing fr om t he
might y J ohn Henr y!).
The differ ent ial equat ion idealizing t his physical set t ing is
Her e, E r epr esent s elast icit y of t he beam (r ail r oad t r ack), I is t he “beam
const ant ,” and k is t he spr ing (r oad bed) st iffness. The shock for ce on t he r ight
hand side of t he differ ent ial equat ion is modeled by t he Dir ac Delt a funct ion
δ(x). If you ar e unfamiliar wit h δ(x), you may be sur pr ised t o lear n t hat (despit e
it s name), it is not a funct ion at all. Rat her , δ(x) is an example of what
mat hemat icians call a distribution. The Dir ac Delt a funct ion (named aft er t he
physicist Paul Dir ac) has t he following impor t ant pr oper t y
A definit ion of t he Dir ac Delt a funct ion is
wher e
You can evaluat e t he Dir ac Delt a funct ion at a point (say) x = 3, using t he
commands
syms x
del = sym('Dirac(x)');
vpa(subs(del,x,3))
which r et ur n
ans =
0
x
4
4
d
d y k
EI
------- y +
1
EI
-------δ x ( ) = ∞ – x ∞ < < ,
f x y – ( )δ x ( ) x d
x –


f x ( ) =
δ x ( ) n χ
1 2n ⁄ – 1 2n ⁄ , ( )
n ∞ →
lim x ( ) =
χ
1 2n ⁄ – 1 2n ⁄ , ( )
x ( )
1 for
1
2n
------- – x <
1
2n
------- <
0 ot her wise
¹
¹
'
¹
¹
=
1 Tutorial
1-116
Ret ur ning t o t he differ ent ial equat ion, let Y(w) = F[y(x)](w) and
∆(w) = F[δ(x)](w). Indeed, t r y t he command fourier(del,x,w). The Four ier
t r ansfor m t ur ns differ ent iat ion int o exponent iat ion, and, in par t icular ,
To see a demonst r at ion of t his pr oper t y, t r y t his
syms w x
fourier(diff(sym('y(x)'),x,4),x,w)
which r et ur ns
ans =
w^4*fourier(y(x),x,w)
Not e t hat you can call t he fourier command wit h one, t wo, or t hr ee input s (see
t he r efer ence pages for fourier). Wit h a single input ar gument , fourier(f)
r et ur ns a funct ion of t he default var iable w. If t he input ar gument is a funct ion
of w, fourier(f) r et ur ns a funct ion of t. All input s t o fourier must be symbolic
object s.
We now see t hat applying t he Four ier t r ansfor m t o t he differ ent ial equat ion
above yields t he algebr aic equat ion
or
Y(w) = ∆(w) G(w)
wher e
for some funct ion g(x). That is, g is t he inver se Four ier t r ansfor m of G
g(x) = F
–1
[G(w)](x)
F
x
4
4
d
d y
w ( ) w
4
Y w ( ) =
w
4 k
EI
------- +
. ,
| `
Y w ( ) ∆ w ( ) =
G w ( )
1
w
4 k
EI
------- +
--------------------- F g x ( ) [ ] w ( ) = =
Integral Transforms
1-117
The Symbolic Mat h Toolbox count er par t t o t he IFT is ifourier. This behavior
of ifourier par allels fourier wit h one, t wo, or t hr ee input ar gument s (see t he
r efer ence pages for ifourier).
Cont inuing wit h t he solut ion of our differ ent ial equat ion, we obser ve t hat t he
r at io
is a r elat ively “lar ge” number since t he r oad bed has a high st iffness const ant
k and a r ail r oad t r ack has a low elast icit y E and beam const ant I. We make t he
simplifying assumpt ion t hat
This is done t o ease t he comput at ion of F
–1
[G(w)](x). Pr oceeding, we t ype
G = 1/(w^4 + 1024);
g = ifourier(G,w,x);
g = simple(expand(g));
pretty(g)
and see
(–1/1024 + 1/1024i) (exp((4 – 4i)x) Heaviside(x) – exp((4 – 4 i)x)
+ i exp((4 + 4i) x) Heaviside(x) – i Heaviside(x) exp((–4 – 4i)x)
– Heaviside(x) exp((–4 + 4 i) x) – i exp((4 + 4 i) x))
Not ice t hat g cont ains t he Heaviside dist r ibut ion
We can fact or out t he Heaviside dist r ibut ion.
H = sym('Heaviside(x)');
g = collect(g,H);
pretty(g)
K
EI
-------
K
EI
------- 1024 =
H x ( )
1 for x 0 >
0 for x 0 <
singular for x = 0
¹
¹
'
¹
¹
=
1 Tutorial
1-118
r et ur ns
(– 1/1024 + 1/1024 i) (exp((4 – 4 i) x) + i exp((4 + 4 i) x)
– i exp((–4 – 4 i) x) – exp((–4 + 4 i) x)) Heaviside(x)
+ (– 1/1024 + 1/1024 i) (–exp((4 – 4 i) x) – i exp((4 + 4 i) x))
Since Y is t he pr oduct of Four ier t r ansfor ms, t hen y is t he convolut ion of t he
t r ansfor med funct ions. That is, F[y] = Y(w) = ∆(w) G(w) = F[δ] F[g] implies
by t he special pr oper t y of t he Dir ac Delt a funct ion. To plot t his funct ion, we
must subst it ut e t he domain of x int o y(x), using t he subs command.
XX = –3:0.05:3;
YY = double(subs(g,x,XX));
plot(XX,YY)
title('Beam Deflection for a Point Shock')
xlabel('x'); ylabel('y(x)');
y x ( ) δ g ⋅ ( ) x ( ) g x y – ( )δ x ( ) x d
∞ –


g x ( ) = = =
Integral Transforms
1-119
The r esult ing gr aph
shows t hat t he impact of a blow on a beam is highly localized; t he gr eat est
deflect ion occur s at t he point of impact and falls off shar ply fr om t her e. This is
t he behavior we expect fr om exper ience.
−3 −2 −1 0 1 2 3
−5
0
5
10
15
20
x 10
−4
Beam Deflection for a Point Shock
x
y
(
x
)
1 Tutorial
1-120
The Laplace and Inverse Laplace Transforms
The Laplace t r ansfor m of a funct ion f(t) is defined as
while t he inver se Laplace t r ansfor m (ILT) of f(s) is
wher e c is a r eal number select ed so t hat all singular it ies of f(s) ar e t o t he left
of t he line s = c. The not at ion L[f] denot es t he Laplace t r ansfor m of f at s.
Similar ly, L
–1
[f] is t he ILT of f at t.
The Laplace t r ansfor m has many applicat ions including t he solut ion of
or dinar y differ ent ial equat ions/init ial value pr oblems. Consider t he
r esist ance-induct or -capacit or (RLC) cir cuit below..
L f [ ] s ( ) f t ( )e
t s –
t d
0


=
L
1 –
f [ ] t ( )
1
2πi
--------- f s ( )e
s t
s d
c i ∞ –
c i ∞ +

=
+
R
1
R
2
R
3
E(t)
L
C
N
1
N
2
I
1
I
3
I
2
Integral Transforms
1-121
Let Rj and Ij, j = 1, 2, 3 be r esist ances (measur ed in ohms) and cur r ent s (amps),
r espect ively; L be induct ance (henr ys), and C be capacit ance (far ads); E(t) be
t he elect r omot ive for ce, and Q(t) be t he char ge
By applying Kir chhoff’s volt age and cur r ent laws, Ohm’s Law, Far aday’s Law,
and Henr y’s Law, you can ar r ive at t he following syst em of simult aneous
or dinar y differ ent ial equat ions.
Let ’s solve t his syst em of differ ent ial equat ions using laplace. We will fir st
t r eat t he R
j
, L, and C as (unknown) r eal const ant s and t hen supply values lat er
on in t he comput at ion.
syms R1 R2 R3 L C real
dI1 = sym('diff(I1(t),t)'); dQ = sym('diff(Q(t),t)');
I1 = sym('I1(t)'); Q = sym('Q(t)');
syms t s
E = sin(t); % Voltage
eq1 = dI1 + R2*dQ/L – (R2 – R1)*I1/L;
eq2 = dQ – (E – Q/C)/(R2 + R3) – R2*I1/(R2 + R3);
At t his point , we have const r uct ed t he equat ions in t he MATLAB wor kspace.
An appr oach t o solving t he differ ent ial equat ions is t o apply t he Laplace
t r ansfor m, which we will apply t o eq1 and eq2. Tr ansfor ming eq1 and eq2
L1 = laplace(eq1,t,s)
L2 = laplace(eq2,t,s)
r et ur ns
L1 =
[s*laplace(I1(t),t,s) – I1(0) + R2/L*(s*laplace(Q(t),t,s) – Q(0))
– (R2 – R1)/L*laplace(I1(t),t,s)]
L2 =
[s*laplace(Q(t),t,s) – Q(0) – 1/(R2 + R3)/C*(C/(s^2 + 1) –
laplace(Q(t),t,s)) – R2/(R2 + R3)*laplace(I1(t),t,s)]
t d
dI
1
R
2
L
-------
t d
dQ
+
R
1
R
2

L
--------------------I
1
I
1
0 ( ) I
10
= , =
t d
dQ 1
R
3
R
2
+
--------------------- E t ( )
1
C
----Q t ( ) –
. ,
| `
R
2
R
3
R
2
+
---------------------I
1
Q 0 ( ) Q
0
= , + =
1 Tutorial
1-122
Now we need t o solve t he syst em of equat ions L1 = 0, L2 = 0 for
laplace(I1(t),t,s) and laplace(Q(t),t,s), t he Laplace t r ansfor ms of I
1
and Q, r espect ively. To do t his, we need t o make a ser ies of subst it ut ions. For
t he pur poses of t his example, use t he quant it ies R
1
= 4 Ω (ohms), R
2
= 2 Ω,
R
3
= 3 Ω, C = 1/4 far ads, L = 1.6 H (henr ys), I
1
(0) = 15 amps, and Q(0) = 2
amps/sec. Subst it ut ing t hese values in L1
syms LI1 LQ
NI1 = subs(L1,{R1,R2,R3,L,C,'I1(0)','Q(0)'}, ...
{4,2,3,1.6,1/4,15,2})
r et ur ns
NI1 =
s*laplace(I1(t),t,s) – 35/2 + 5/4*s*laplace(Q(t),t,s)
+ 5/4*laplace(I1(t),t,s)
The subst it ut ion
NQ = subs(L2,{R1,R2,R3,L,C,'I1(0)','Q(0)'},{4,2,3,1.6,1/4,15,2})
r et ur ns
NQ =
s*laplace(Q(t),t,s) – 2 – 1/5/(s^2+1) + 4/5*laplace(Q(t),t,s)
– 2/5*laplace(I1(t),t,s)
To solve for laplace(I1(t),t,s) and laplace(Q(t),t,s), we make a final
pair of subst it ut ions. Fir st , r eplace t he st r ings 'laplace(I1(t),t,s)' and
'laplace(Q(t),t,s)' by t he syms LI1 and LQ, using
NI1 =
subs(NI1,{'laplace(I1(t),t,s)','laplace(Q(t),t,s)'},{LI1,LQ})
t o obt ain
NI1 =
s*LI1 – 35/2 + 5/4*s*LQ + 5/4*LI1
Collect ing t er ms
NI1 = collect(NI1,LI1)
Integral Transforms
1-123
gives
NI1 =
(s + 5/4)*LI1 – 35/2 + 5/4*s*LQ
A similar st r ing subst it ut ion
NQ =
subs(NQ,{'laplace(I1(t),t,s)','laplace(Q(t),t,s)'},{LI1,LQ})
yields
NQ =
s*LQ – 2 – 1/5/(s^2+1) + 4/5*LQ – 2/5*LI1
which, aft er collect ing t er ms,
NQ = collect(NQ,LQ)
gives
NQ =
(4/5 + s)*LQ – 2/5*LI1 – 2 – 1/5/(s^2+1)
Now, solving for LI1 and LQ
[LI1,LQ] = solve(NI1,NQ,LI1,LQ)
we obt ain
LI1 =
[5*(59*s + 56 + 56*s^2 + 60*s^3)/(51*s^3 + 40*s^2 + 51*s + 20
+ 20*s^4)]

LQ =
[(44*s + 195 + 190*s^2 + 40*s^3)/(51*s^3 + 40*s^2 + 51*s + 20
+ 20*s^4)]
To r ecover I1 and Q we need t o comput e t he inver se Laplace t r ansfor m of LI1
and LQ. Inver t ing LI1
I1 = ilaplace(LI1,s,t)
1 Tutorial
1-124
pr oduces
I1 =
–5/51*sin(t)+15*exp(–51/40*t)*cosh(1/40*1001^(1/2)*t)
– 1465/7293*exp(–51/40*t)*1001^(1/2)*sinh(1/40*1001^(1/2)*t)
– 5/51*sin(t)
Inver t ing LQ
Q = ilaplace(LQ,s,t)
yields
Q =
–5/51*cos(t) + 4/51*sin(t)
+ 107/51*exp(–51/40*t)*cosh(1/40*1001^(1/2)*t)
+ 2039/7293*exp(–51/40*t)*1001^(1/2)*sinh(1/40*1001^(1/2)*t)
Now let ’s plot t he cur r ent I1(t) and char ge Q(t) in t wo differ ent t ime domains,
0 ≤ t ≤ 10 and 5 ≤ t ≤ 25. The st at ement s
subplot(2,2,1); ezplot(I1,[0,10]);
title('Current'); ylabel('I1(t)'); grid
subplot(2,2,2); ezplot(Q,[0,10]);
title('Charge'); ylabel('Q(t)'); grid
subplot(2,2,3); ezplot(I1,[5,25]);
title('Current'); ylabel('I1(t)'); grid
text(7,0.25,'Transient'); text(16,0.125,'Steady State');
subplot(2,2,4); ezplot(Q,[5,25]);
title('Charge'); ylabel('Q(t)'); grid
text(7,0.25,'Transient'); text(15,0.16,'Steady State');
Integral Transforms
1-125
gener at e t he desir ed plot s
Not e t hat t he cir cuit ’s behavior , which appear s t o be exponent ial decay in t he
shor t t er m, t ur ns out t o be oscillat or y in t he long t er m. The appar ent
discr epancy ar ises because t he cir cuit ’s behavior act ually has t wo component s:
an exponent ial par t t hat decays r apidly (t he “t r ansient ” component ) and an
oscillat or y par t t hat per sist s (t he “st eady-st at e” component ).
0 2 4 6 8 10
0
1
2
3
4
5
t
Current
I
1
(
t
)
0 2 4 6 8 10
0
0.5
1
1.5
2
2.5
3
t
Charge
Q
(
t
)
5 10 15 20 25
−0.1
0
0.1
0.2
0.3
t
Current
I
1
(
t
)
Transient
Steady State
5 10 15 20 25
−0.1
0
0.1
0.2
0.3
0.4
t
Charge
Q
(
t
)
Transient
Steady State
1 Tutorial
1-126
The Z– and Inverse Z–transforms
The (one-sided) z-t r ansfor m of a funct ion f(n) is defined as
The not at ion Z[f] r efer s t o t he z-t r ansfor m of f at z. Let R be a posit ive number
so t hat t he funct ion g(z) is analyt ic on and out side t he cir cle | z| = R. Then t he
inver se z-t r ansfor m (IZT) of g at n is defined as
The not at ion Z
–1
[f] means t he IZT of f at n. The Symbolic Mat h Toolbox
commands ztrans and iztrans apply t he z-t r ansfor m and IZT t o symbolic
expr essions, r espect ively. See ztrans and iztrans for t ables showing var ious
mat hemat ical r epr esent at ions of t he z-t r ansfor m and inver se z-t r ansfor m and
t heir Symbolic Mat h Toolbox count er par t s.
The z-t r ansfor m is oft en used t o solve differ ence equat ions. In par t icular ,
consider t he famous “Rabbit Pr oblem.” That is, suppose t hat r abbit s r epr oduce
only on odd bir t hdays (1, 3, 5, 7, …). If p(n) is t he r abbit populat ion at year n,
t hen p obeys t he differ ence equat ion
p(n+2) = p(n+1) + p(n), p(0) = 1, p(1) = 2.
We can use ztrans t o find t he populat ion each year p(n). Fir st , we apply ztrans
t o t he equat ions
pn = sym('p(n)');
pn1 = sym('p(n+1)');
pn2 = sym('p(n+2)');
syms n z
eq = pn2 – pn1 – pn;
Zeq = ztrans(eq, n, z)
t o obt ain
Zeq =
z^2*ztrans(p(n),n,z)–p(0)*z^2–p(1)*z–z*ztrans(p(n),n,z)+p(0)*z
–ztrans(p(n),n,z)
Z f [ ] z ( ) f n ( )z
n –
n 0 =


=
Z
1 –
g [ ] n ( )
1
2πi
--------- g z ( )z
n 1 –
z n 1 2 … , , = , d
z R =

°
=
Integral Transforms
1-127
Next , r eplace 'ztrans(p(n),n,z)' wit h Pz and inser t t he init ial condit ions for
p(0) and p(1).
syms Pz
Zeq = subs(Zeq,{'ztrans(p(n),n,z)','p(0)','p(1)'},{Pz,1,2})
t o obt ain
Zeq =
z^2*Pz–1*z^2–2*z–z*Pz+1*z–Pz
Collect ing t er ms
eq = collect(Zeq,Pz)
yields
eq =
(z^2–z–1)*Pz–z^2–z
Now solve for Pz
P = solve(eq,Pz)
t o obt ain
P =
z*(z + 1)/(z^2 – z – 1)
To r ecover p(n), we t ake t he inver se z-t r ansfor m of P.
p = iztrans(P,z,n);
p = simple(p);
pretty(p)
n 1/2 n n 1/2 n
2 5 2 (–2) 5 (–2)
3/10 --------- + 1/2 -------- – 3/10 ---------- + 1/2 ----------
1/2 n 1/2 n 1/2 n 1/2 n
(5 – 1) (5 – 1) (5 + 1) (5 + 1)
1 Tutorial
1-128
Finally, let ’s plot p
m = 1:10;
y = double(subs(f,n,m));
plot(m,y,'rO')
title('Rabbit Population');
xlabel('years'); ylabel('f(n)'); grid on
t o show t he gr owt h in r abbit populat ion over t ime.
References
Andr ews, L.C., B.K. Shivamoggi, Integral Transforms for Engineers and
Applied Mathematicians, Macmillan Publishing Company, New Yor k, 1986
Cr andall, R.E., Projects in S cientific Computation, Spr inger -Ver lag Publisher s,
New Yor k, 1994
1 2 3 4 5 6 7 8 9 10
0
50
100
150
Rabbit Population
years
p
Integral Transforms
1-129
St r ang, G., Introduction to Applied Mathematics, Wellesley-Cambr idge Pr ess,
Wellesley, MA, 1986
1 Tutorial
1-130
Special Mathematical Functions
Over fift y of t he special funct ions of classical applied mat hemat ics ar e
available in t he t oolbox. These funct ions ar e accessed wit h t he mfun funct ion,
which numer ically evaluat es a special funct ion for t he specified par amet er s.
This allows you t o evaluat e funct ions t hat ar e not available in st andar d
MATLAB, such as t he Fr esnel cosine int egr al. In addit ion, you can evaluat e
sever al MATLAB special funct ions in t he complex plane, such as t he er r or
funct ion.
For example, suppose you want t o evaluat e t he hyper bolic cosine int egr al at
t he point s 2+i, 0, and 4.5. Fir st t ype
help mfunlist
t o see t he list of funct ions available for mfun. This list pr ovides a br ief
mat hemat ical descr ipt ion of each funct ion, it s Maple name, and t he
par amet er s it needs. Fr om t he list , you can see t hat t he hyper bolic cosine
int egr al is called Chi, and it t akes one complex ar gument . For addit ional
infor mat ion, you can access Maple help on t he hyper bolic cosine int egr al using
mhelp Chi
Now t ype
z = [2+i 0 4.5];
w = mfun('Chi',z)
which r et ur ns
w =
2.0303 + 1.7227i NaN 13.9658
mfun r et ur ns NaNs wher e t he funct ion has a singular it y. The hyper bolic cosine
int egr al has a singular it y at z = 0.
These special funct ions can be used wit h t he mfun funct ion:
•Air y Funct ions
•Binomial Coefficient s
•Riemann Zet a Funct ions
•Ber noulli Number s and Polynomials
•Euler Number s and Polynomials
Special Mathematical Functions
1-131
•Har monic Funct ion
•Exponent ial Int egr als
•Logar it hmic Int egr al
•Sine and Cosine Int egr als
•Hyper bolic Sine and Cosine Int egr als
•Shift ed Sine Int egr al
•Fr esnel Sine and Cosine Int egr al
•Dawson’s Int egr al
•Er r or Funct ion
•Complement ar y Er r or Funct ion and it s It er at ed Int egr als
•Gamma Funct ion
•Logar it hm of t he Gamma Funct ion
•Incomplet e Gamma Funct ion
•Digamma Funct ion
•Polygamma Funct ion
•Gener alized Hyper geomet r ic Funct ion
•Bessel Funct ions
•Incomplet e Ellipt ic Int egr als
•Complet e Ellipt ic Int egr als
•Complet e Ellipt ic Int egr als wit h Complement ar y Modulus
•Bet a Funct ion
•Dilogar it hm Int egr al
•Lamber t ’s W Funct ion
•Dir ac Delt a Funct ion (dist r ibut ion)
•Heaviside Funct ion (dist r ibut ion)
The or t hogonal polynomials list ed below ar e available wit h t he Ext ended
Symbolic Mat h Toolbox:
•Gegenbauer
•Her mit e
1 Tutorial
1-132
•Laguer r e
•Gener alized Laguer r e
•Legendr e
•J acobi
•Chebyshev of t he Fir st and Second Kind
Diffraction
This example is fr om diffr act ion t heor y in classical elect r odynamics. (J .D.
J ackson, Classical Electrodynamics, J ohn Wiley & Sons, 1962.)
Suppose we have a plane wave of int ensit y I
0
and wave number k. We assume
t hat t he plane wave is par allel t o t he xy-plane and t r avels along t he z-axis as
shown below. This plane wave is called t he incident wave. A per fect ly
conduct ing flat diffr act ion scr een occupies half of t he xy-plane, t hat is x <0. The
plane wave st r ikes t he diffr act ion scr een, and we obser ve t he diffr act ed wave
fr om t he line whose coor dinat es ar e
(x, 0, z
0
), wher e z
0
> 0.
The int ensit y of t he diffr act ed wave is given by
diffraction screen
x
z
y
line of observation
(x
0
,0,z
0
)
incident plane wave
I
I
0
2
----- C ζ ( )
1
2
--- +
. ,
| `
2
S ζ ( )
1
2
--- +
. ,
| `
2
+ =
Special Mathematical Functions
1-133
wher e
and C(ξ) and S (ξ) ar e t he Fr esnel cosine and sine int egr als:
How does t he int ensit y of t he diffr act ed wave behave along t he line of
obser vat ion? Since k and z
0
ar e const ant s independent of x, we set
and assume an init ial int ensit y of I
0
= 1 for simplicit y.
ζ
k
2z
0
--------- x ⋅ =
C ζ ( )
π
2
--- t
2

. ,
| `
t d cos
0
ζ

=
S ζ ( )
π
2
--- t
2

. ,
| `
sin t d
0
ζ

=
k
2z
0
--------- 1 =
1 Tutorial
1-134
The following code gener at es a plot of int ensit y as a funct ion of x.
x = –50:50;
C = mfun('FresnelC',x);
S = mfun('FresnelS',x);
I0 = 1;
T = (C+1/2).^2 + (S+1/2).^2;
I = (I0/2)*T;
plot(x,I);
xlabel('x');
ylabel('I(x)');
title('Intensity of Diffracted Wave');;
We see fr om t he gr aph t hat t he diffr act ion effect is most pr ominent near t he
edge of t he diffr act ion scr een (x = 0), as we expect .
Not e t hat values of x t hat ar e lar ge and posit ive cor r espond t o obser vat ion
point s far away fr om t he scr een. Her e, we would expect t he scr een t o have no
effect on t he incident wave. That is, t he int ensit y of t he diffr act ed wave should
be t he same as t hat of t he incident wave. Similar ly, x values t hat ar e lar ge and
negat ive cor r espond t o obser vat ion point s under t he scr een t hat ar e far away
fr om t he scr een edge. Her e, we would expect t he diffr act ed wave t o have zer o
int ensit y. These r esult s can be ver ified by set t ing
x = [Inf –Inf]
-50 -40 -30 -20 -10 0 10 20 30 40 50
0
0.2
0.4
0.6
0.8
1
1.2
1.4
x
I
(
x
)
Intensity of Diffracted Wave
Special Mathematical Functions
1-135
in t he code t o calculat e I.
1 Tutorial
1-136
Using Maple Functions
The maple funct ion let s you access Maple funct ions dir ect ly. This funct ion
t akes sym object s, st r ings, and doubles as input s. It r et ur ns a symbolic object ,
char act er st r ing, or double cor r esponding t o t he class of t he input . You can also
use t he maple funct ion t o debug symbolic mat h pr ogr ams t hat you develop.
Simple Example
Suppose we want t o wr it e an M-file t hat t akes t wo polynomials or t wo int eger s
and r et ur ns t heir gr eat est common divisor . For example, t he gr eat est common
divisor of 14 and 21 is 7. The gr eat est common divisor of x^ 2–y^ 2 and x^ 3–y^ 3
is x – y.
The fir st t hing we need t o know is how t o call t he gr eat est common divisor
funct ion in Maple. We use t he mhelp funct ion t o br ing up t he Maple online help
for t he gr eat est common divisor (gcd):
Let ’s t r y t he gcd funct ion:
mhelp gcd
which r et ur ns
Function: gcd - greatest common divisor of polynomials

Function: lcm - least common multiple of polynomials

Calling Sequence:
gcd(a,b,'cofa','cofb')
lcm(a,b,...)

Parameters:
a, b - multivariate polynomials over the rationals
cofa,cofb - (optional) unevaluated names
Using Maple Functions
1-137

Description:

- The gcd function computes the greatest common divisor of two
polynomials a and b with rational coefficients.

- The lcm function computes the least common multiple of an
arbitrary number of polynomials with rational coefficients.

- The optional third argument cofa is assigned the cofactor
a/gcd(a,b).

- The optional fourth argument cofb is assigned the cofactor
b/gcd(a,b).

Examples:
> gcd(x^2–y^2,x^3–y^3);
–x + y

> lcm(x^2–y^2,x^3–y^3);
3 4 4 3
–y x + y – x + x y

> gcd(6,8,a,b);
2

> a;
3

> b;
4

See Also: gcdex, igcd, ilcm, Gcd, numtheory[GIgcd]
1 Tutorial
1-138
Since we now know t he Maple calling synt ax for gcd, we can wr it e a simple
M-file t o calculat e t he gr eat est common divisor . Fir st , cr eat e t he M-file gcd in
t he @sym dir ect or y and include t he commands below.
function g = gcd(a, b)
g = maple('gcd',a, b);
If we r un t his file
syms x y
z = gcd(x^2–y^2,x^3–y^3)
w = gcd(6, 24)
we get
z =
–y+x
w =
6
Now let ’s ext end our funct ion so t hat we can t ake t he gcd of t wo mat r ices in a
point wise fashion.
function g = gcd(a,b)
if any(size(a) ~= size(b))
error('Inputs must have the same size.')
end
for k = 1: prod(size(a))
g(k) = maple('gcd',a(k), b(k));
end
g = reshape(g,size(a));
Running t his on some t est dat a
A = sym([2 4 6; 3 5 6; 3 6 4]);
B = sym([40 30 8; 17 60 20; 6 3 20]);
gcd(A,B)
Using Maple Functions
1-139
we get t he r esult
ans =
[ 2, 2, 2 ]
[ 1, 5, 2 ]
[ 3, 3, 4 ]
Vectorized Example
Suppose we want t o calculat e t he sine of a symbolic mat r ix. One way t o do t his
is:
function y = sin1(x)
for k = 1: prod(size(x))
y(k) = maple('sin',x(k));
end
y = reshape(y,size(x));
So t he st at ement s
syms x y
A = [0 x; y pi/4]
sin1(A)
r et ur n
A =
[ 0, x ]
[ y, pi/4 ]

ans =
[ 0, sin(x) ]
[ sin(y), 1/2*2^(1/2) ]
1 Tutorial
1-140
A mor e efficient way t o do t his is t o call Maple just once, using t he Maple map
funct ion. The map funct ion applies a Maple funct ion t o each element of an
ar r ay. In our sine calculat ion example, t his looks like:
function y = sin2(x)
if prod(size(x)) == 1
% scalar case
y = maple('sin',x);
else
% array case
y = maple('map','sin',x);
end
Not e t hat our sin2 funct ion t r eat s scalar and ar r ay cases differ ent ly. It applies
t he map funct ion t o ar r ays but not t o scalar s. This is because map applies a
funct ion t o each oper and of a scalar .
Because our sin2 funct ion calls Maple only once, it is consider ably fast er t han
our sin1 funct ion, which calls Maple prod(size(A)) number of t imes. For
example, using A = x*ones(10,10) on a Sun-4, sin1(A) t akes mor e t han six
t imes longer t o comput e t han sin2(A). On a Macint osh 7500/100 Power PC, t he
r at io is four -t o-one.
The map funct ion can also be used for Maple funct ions t hat r equir e mult iple
input ar gument s. In t his case, t he synt ax is
maple('map', Maple function, sym array, arg2, arg3, ..., argn)
For example, one way t o call t he collect M-file is collect(S,x). In t his case,
t he collect funct ion collect s all t he coefficient s wit h t he same power of x for
each element in S. The cor e sect ion of t he implement at ion is shown below:
r = maple('map','collect',sym(s),sym(x));
For addit ional infor mat ion on t he Maple map funct ion, t ype
mhelp map
Using Maple Functions
1-141
Debugging
The maple command pr ovides t wo debugging facilit ies: t r ace mode and a st at us
out put ar gument .
Trace Mode
The command maple traceon causes all subsequent Maple st at ement s and
r esult s t o be pr int ed t o t he scr een. For example
maple traceon
a = sym('a');
exp(2*a)
pr int s all calls made t o t he Maple ker nel for calculat ing exp(2*a).
statement =
(2)*(a);
result =
2*a
statement =
exp(2*a);
result =
exp(2*a)

ans =
exp(2*a)
To r ever t back t o suppr essed pr int ing, use maple traceoff.
Status Output Argument
The maple funct ion opt ionally r et ur ns t wo out put ar gument s, result and
status. If t he maple call succeeds, Maple r et ur ns t he r esult in t he result
ar gument and zer o in t he status ar gument . If t he call fails, Maple r et ur ns an
er r or code (a posit ive int eger ) in t he status ar gument and a cor r esponding
war ning/er r or message in t he result ar gument .
For example, t he Maple discrim funct ion calculat es t he discr iminant of a
polynomial and has t he synt ax discrim(p,x), wher e p is a polynomial in x.
1 Tutorial
1-142
Suppose we for get t o supply t he second ar gument when calling t he discrim
funct ion
syms a b c x
[result, status] = maple('discrim', a*x^2+b*x+c)
Maple r et ur ns
result =
Error, (in discrim) invalid arguments
status =
2
If we t hen include x
[result, status] = maple('discrim', a*x^2+b*x+c, x)
we get t he following
result =
–4*a*c+b^2
status =
0
Extended Symbolic Math Toolbox
1-143
Extended Symbolic Math Toolbox
The Ext ended Symbolic Mat h Toolbox allows you t o access all nongr aphics
Maple packages, Maple pr ogr amming feat ur es, and Maple pr ocedur es. The
Ext ended Toolbox t hus pr ovides access t o a lar ge body of mat hemat ical
soft war e wr it t en in t he Maple language.
Maple pr ogr amming feat ur es include looping (for ... do ... od, while ...
do ... od) and condit ionals (if ... elif ... else ... fi). Please see The
Maple Handbook for infor mat ion on how t o use t hese and ot her feat ur es.
This sect ion explains how t o load Maple packages and how t o use Maple
pr ocedur es. For addit ional infor mat ion, please consult t hese r efer ences.
Char , B.W., K.O. Geddes, G.H. Gonnet , B.L. Leong, M.B. Monagan, and S.M.
Wat t , First Leaves: A Tutorial Introduction to Maple V, Spr inger -Ver lag, NY,
1991.
Char , B.W., K.O. Geddes, G.H. Gonnet , B.L. Leong, M.B. Monagan, and S.M.
Wat t , Maple V Language Reference Manual, Spr inger -Ver lag, NY, 1991.
Char , B.W., K.O. Geddes, G.H. Gonnet , B.L. Leong, M.B. Monagan, and S.M.
Wat t , Maple V Library Reference Manual, Spr inger -Ver lag, NY, 1991.
Heck, A., Introduction to Maple, Spr inger -Ver lag, NY, 1996.
Nicolaides, R. and N. Walkingt on, Maple: A Comprehensive Introduction,
Cambr idge Univer sit y Pr ess, Cambr idge, 1996.
Packages of Library Functions
Specialized libr ar ies, or “packages,” can be used t hr ough t he Ext ended Toolbox.
These packages include:
•Combinat or ial Funct ions
•Differ ent ial Equat ion Tools
•Differ ent ial For ms
•Domains of Comput at ion
•Euclidean Geomet r y
•Gaussian Int eger s
•Gr öbner Bases
1 Tutorial
1-144
•Per mut at ion and Finit ely Pr esent ed Gr oups
•Lie Symmet r ies
•Boolean Logic
•Gr aph Net wor ks
•Newman-Penr ose For malism
•Number Theor y
•Numer ical Appr oximat ion
•Or t hogonal Polynomials
•p-adic Number s
•For mal Power Ser ies
•Pr oject ive Geomet r y
•Simplex Linear Opt imizat ion
•St at ist ics
•Tot al Or der s on Names
•Galois Fields
•Linear Recur r ence Relat ion Tools
•Financial Mat hemat ics
•Rat ional Gener at ing Funct ions
•Tensor Comput at ions
You can use t he Maple with command t o load t hese packages. Say, for example,
t hat you want t o use t he or t hogonal polynomials package. Fir st get t he Maple
name of t his package, using t he st at ement
mhelp index[packages]
which r et ur ns
HELP FOR: Index of descriptions for packages of library functions
SYNOPSIS:
- The following packages are available:
...
orthopoly: orthogonal polynomials
...
Extended Symbolic Math Toolbox
1-145
You can t hen can access infor mat ion about t he package
mhelp orthopoly
To load t he package, t ype
maple('with(orthopoly);')
This r et ur ns
ans =
[G, H, L, P, T, U]
which is a list ing of funct ion names in t he orthopoly package. These funct ions
ar e now loaded in t he Maple wor kspace, and you can use t hem as you would
any r egular Maple funct ion.
Procedure Example
The following example shows how you can access a Maple pr ocedur e t hr ough
t he Ext ended Symbolic Mat h Toolbox. The example comput es eit her symbolic
or var iable-pr ecision numer ic appr oximat ions t o π, using a met hod der ived by
1 Tutorial
1-146
Richar d Br ent based fr om t he ar it hmet ic-geomet r ic mean algor it hm of Gauss.
Her e is t he Maple sour ce code.
pie := proc(n)
# pie(n) takes n steps of an arithmetic–geometric mean
# algorithm for computing pi. The result is a symbolic
# expression whose length roughly doubles with each step.
# The number of correct digits in the evaluated string also
# roughly doubles with each step.
# Example: pie(5) is a symbolic expression with 1167
# characters which, when evaluated, agrees with pi to 84
# decimal digits.
local a,b,c,d,k,t;
a := 1:
b := sqrt(1/2):
c := 1/4:
t := 1:
for k from 1 to n do
d := (b–a)/2:
b := sqrt(a*b):
a := a+d:
c := c–t*d^2:
t := 2*t:
od;
(a+b)^2/(4*c):
end;
Assume t he sour ce code for t his Maple pr ocedur e is st or ed in t he file pie.src.
Using t he Ext ended Symbolic Mat h Toolbox, t he MATLAB st at ement
procread('pie.src')
r eads t he specified file, delet es comment s and newline char act er s, and sends
t he r esult ing st r ing t o Maple. (The MATLAB ans var iable t hen cont ains a
st r ing r epr esent at ion of t he pie.src file.)
Extended Symbolic Math Toolbox
1-147
You can use t he pie funct ion, using t he maple funct ion. The st at ement
p = maple('pie',5)
r et ur ns a symbolic object p t hat begins and ends wit h
p =
1/4*(1/32+1/64*2^(1/2)+1/32*2^(3/4)+ ...
... *2^(1/2))*2^(3/4))^(1/2))^(1/2))^2)
It is int er est ing t o change t he comput at ion fr om symbolic t o numer ic. The
assignment t o t he var iable b in t he second execut able line is key. If t he
assignment st at ement is simply
b := sqrt(1/2)
t he ent ir e comput at ion is done symbolically. But if t he assignment st at ement
is modified t o include decimal point s
b := sqrt(1./2.)
t he ent ir e comput at ion uses var iable-pr ecision ar it hmet ic at t he cur r ent
set t ing of digits. If t his change is made, t hen
digits(100)
procread('pie.src')
p = maple('pie',5)
pr oduces a 100-digit r esult
p =
3.14159265358979323 ... 5628703211672038
The last 16 digit s differ fr om t hose of π because, wit h five it er at ions, t he
algor it hm gives only 84 digit s.
Not e t hat you can define your own MATLAB M-file t hat accesses a Maple
pr ocedur e
function p = pie1(n)
p = maple('pie',n)
1 Tutorial
1-148
Precompiled Maple Procedures
When Maple loads a sour ce (ASCII t ext ) pr ocedur e int o it s wor kspace, it
compiles (t r anslat es) t he pr ocedur e int o an int er nal for mat . You can
subsequent ly use t he maple funct ion t o save t he pr ocedur es in t he int er nal
for mat . The advant age is you avoid r ecompiling t he pr ocedur e t he next t ime
you load it , t her eby speeding up t he pr ocess.
For example, you can conver t t he pie.src pr ocedur e developed in t he
pr eceding example t o a pr ecompiled Maple pr ocedur e, using t he commands
clear maplemex
procread('pie.src')
maple('save(`pi.m`)');
The clear maplemex command r eset s t he Maple wor kspace t o it s init ial st at e.
Since t he Maple save command saves all var iables in t he cur r ent session, we
want t o r emove ext r aneous var iables. Not e t hat you must use back quot es
ar ound t he funct ion name.
To r ead t he pr ecompiled pr ocedur e int o a subsequent MATLAB session, t ype
maple('read','`pie.m`');
Again, as wit h t he ASCII t ext for m, you can access t he funct ion using maple
p = maple('pie',5)
Not e t hat pr ecompiled Maple pr ocedur es have .m ext ensions. Hence, you must
t ake car e t o avoid confusing t hem wit h MATLAB M-files, which also have .m
ext ensions.
2
Refer ence
2 Reference
2-2
This chapt er pr ovides det ailed descr ipt ions of all Symbolic Mat h Toolbox
funct ions. It begins wit h t ables of t hese funct ions and cont inues wit h t he
r efer ence ent r ies in alphabet ical or der .
Calculus
diff Differ ent iat e.
int Int egr at e.
jacobian J acobian mat r ix.
limit Limit of an expr ession.
symsum Summat ion of ser ies.
taylor Taylor ser ies expansion.
Linear Algebra
colspace Basis for column space.
det Det er minant .
diag Cr eat e or ext r act diagonals.
eig Eigenvalues and eigenvect or s.
expm Mat r ix exponent ial.
inv Mat r ix inver se.
jordan J or dan canonical for m.
null Basis for null space.
poly Char act er ist ic polynomial.
rank Mat r ix r ank.
rref Reduced r ow echelon for m.
2-3
svd Singular value decomposit ion.
tril Lower t r iangle.
triu Upper t r iangle.
Simplification
collect Collect common t er ms.
expand Expand polynomials and element ar y funct ions.
factor Fact or.
horner Nest ed polynomial r epr esent at ion.
numden Numer at or and denominat or.
simple Sear ch for shor t est for m.
simplify Simplificat ion.
subexpr Rewr it e in t er ms of subexpr essions.
Solution of Equations
compose Funct ional composit ion.
dsolve Solut ion of differ ent ial equat ions.
finverse Funct ional inver se.
solve Solut ion of algebr aic equat ions.
Linear Algebra
2 Reference
2-4
Variable Precision Arithmetic
digits Set var iable pr ecision accur acy.
vpa Var iable pr ecision ar it hmet ic.
Arithmetic Operations
+ Addit ion.
– Subt r act ion.
* Mult iplicat ion.
.* Ar r ay mult iplicat ion.
/ Right division.
./ Ar r ay r ight division.
\ Left division.
.\ Ar r ay left division.
^ Mat r ix or scalar r aised t o a power.
.^ Ar r ay r aised t o a power.
' Complex conjugat e t r anspose.
.' Real t r anspose.
2-5
Special Functions
cosint Cosine int egr al, Ci(x).
hypergeom Gener alized hyper geomet r ic funct ion.
lambertw Solut ion of .
sinint Sine int egr al, Si(x).
zeta Riemann zeta funct ion.
Access To Maple
maple Access Maple ker nel.
mapleinit Init ialize Maple.
mfun Numer ic evaluat ion of Maple funct ions.
mhelp Maple help.
mfunlist List of funct ions for mfun.
procread Inst all a Maple pr ocedur e.
Pedagogical and Graphical Applications
ezcontour Cont our plot t er.
ezcontourf Filled cont our plot t er.
ezmesh Mesh plot t er.
ezmeshc Combined mesh and cont our plot t er.
λ x ( )e
λ x ( )
x =
2 Reference
2-6
ezplot Funct ion plot t er.
ezplot3 3-D cur ve plot t er.
ezpolar Polar coor dinat e plot t er.
ezsurf Sur face plot t er.
ezsurfc Combined sur face and cont our plot t er.
funtool Funct ion calculat or.
rsums Riemann sums.
taylortool Taylor ser ies calculat or.
Conversions
char Conver t sym object t o st r ing.
double Conver t symbolic mat r ix t o double.
poly2sym Funct ion calculat or.
sym2poly Symbolic polynomial t o coefficient vect or.
Basic Operations
ccode C code r epr esent at ion of a symbolic expr ession.
conj Complex conjugat e.
findsym Det er mine symbolic var iables.
fortran For t r an r epr esent at ion of a symbolic expr ession.
imag Imaginar y par t of a complex number.
Pedagogical and Graphical Applications
2-7
latex LaTeX r epr esent at ion of a symbolic expr ession.
pretty Pr et t y pr int a symbolic expr ession.
real Real par t of an imaginar y number.
sym Cr eat e symbolic object .
syms Shor t cut for cr eat ing mult iple symbolic object s.
Integral Transforms
fourier Four ier t r ansfor m.
ifourier Inver se Four ier t r ansfor m.
ilaplace Inver se Laplace t r ansfor m.
iztrans Inver se z-t r ansfor m.
laplace Laplace t r ansfor m.
ztrans z-t r ansfor m.
Basic Operations
Arithmetic Operations
2-8
2
Arit hmet ic Operat ions
Purpose Per for m ar it hmet ic oper at ions on symbols.
Syntax A+B
A–B
A*B A.*B
A\B A.\B
A/B A./B
A^B A.^B
A' A.'
Description + Mat r ix addit ion. A + B adds A and B. A and B must have t he same
dimensions, unless one is scalar .
– Subt r act ion. A – B subt r act s B fr om A. A and B must have t he same
dimensions, unless one is scalar .
* Mat r ix mult iplicat ion. A*B is t he linear algebr aic pr oduct of A and B. The
number of columns of A must equal t he number of r ows of B, unless one
is a scalar .
.* Ar r ay mult iplicat ion. A.*B is t he ent r y-by-ent r y pr oduct of A and B. A
and B must have t he same dimensions, unless one is scalar .
\ Mat r ix left division. X = A\B solves t he symbolic linear equat ions A*X=B.
Not e t hat A\B is r oughly equivalent t o inv(A)*B. War ning messages ar e
pr oduced if X does not exist or is not unique. Rect angular mat r ices A ar e
allowed, but t he equat ions must be consist ent ; a least squar es solut ion
is not comput ed.
.\ Ar r ay left division. A.\B is t he mat r ix wit h ent r ies B(i,j)/A(i,j). A
and B must have t he same dimensions, unless one is scalar .
/ Mat r ix r ight division. X=B/A solves t he symbolic linear equat ion X*A=B.
Not e t hat B/A is t he same as (A.'\B.'). War ning messages ar e
pr oduced if X does not exist or is not unique. Rect angular mat r ices A ar e
allowed, but t he equat ions must be consist ent ; a least squar es solut ion
is not comput ed.
./ Ar r ay r ight division. A./B is t he mat r ix wit h ent r ies A(i,j)/B(i,j). A
and B must have t he same dimensions, unless one is scalar .
Arithmetic Operations
2-9
^ Mat r ix power . X^P r aises t he squar e mat r ix X t o t he int eger power P. If
X is a scalar and P is a squar e mat r ix, X^P r aises X t o t he mat r ix power
P, using eigenvalues and eigenvect or s. X^P, wher e X and P ar e bot h
mat r ices, is an er r or .
.^ Ar r ay power . A.^B is t he mat r ix wit h ent r ies A(i,j)^B(i,j). A and B
must have t he same dimensions, unless one is scalar .
' Mat r ix Her mit ion t r anspose. If A is complex, A' is t he complex
conjugat e t r anspose.
.' Ar r ay t r anspose. A.' is t he r eal t r anspose of A. A.' does not conjugat e
complex ent r ies.
Examples The following st at ement s
syms a b c d;
A = [a b; c d];
A*A/A
A*A–A^2
r et ur n
[ a, b]
[ c, d]
[ 0, 0]
[ 0, 0]
The following st at ement s
syms a11 a12 a21 a22 b1 b2;
A = [a11 a12; a21 a22];
B = [b1 b2];
X = B/A;
x1 = X(1)
x2 = X(2)
Arithmetic Operations
2-10
r et ur n
x1 =
(a21*b2–b1*a22)/(–a11*a22+a12*a21)
x2 =
(–a11*b2+a12*b1)/(–a11*a22+a12*a21)
See Also null, solve
ccode
2-11
ccode
Purpose C code r epr esent at ion of a symbolic expr ession.
Syntax ccode(s)
Description ccode(s) r et ur ns a fr agment of C t hat evaluat es t he symbolic expr ession s.
Examples The st at ement s
syms x
f = taylor(log(1+x));
ccode(f)
r et ur n
t0 = x–x*x/2+x*x*x/3–pow(x,4.0)/4+pow(x,5.0)/5;
The st at ement s
H = sym(hilb(3));
ccode(H)
r et ur n
H[0][0] = 1.0; H[0][1] = 1.0/2.0; H[0][2] = 1.0/3.0;
H[1][0] = 1.0/2.0; H[1][1] = 1.0/3.0; H[1][2] = 1.0/4.0;
H[2][0] = 1.0/3.0; H[2][1] = 1.0/4.0; H[2][2] = 1.0/5.0;
See Also fortran, latex, pretty
collect
2-12
collect
Purpose Collect coefficient s.
Syntax R = collect(S)
R = collect(S,v)
Description For each polynomial in t he ar r ay S of polynomials, collect(S) collect s t er ms
cont aining t he var iable v (or x, if v is not specified). The r esult is an ar r ay
cont aining t he collect ed polynomials.
Examples The following st at ement s
syms x y;
R1 = collect((exp(x)+x)*(x+2))
R2 = collect((x+y)*(x^2+y^2+1), y)
R3 = collect([(x+1)*(y+1),x+y])
r et ur n
R1 =
x^2+(exp(x)+2)*x+2*exp(x)
R2 =
y^3+x*y^2+(x^2+1)*y+x*(x^2+1)
R3 =
[(y+1)*x+y+1, x+y]
See Also expand, factor, simple, simplify, syms
colspace
2-13
colspace
Purpose Basis for column space.
Syntax B = colspace(A)
Description colspace(A) r et ur ns a mat r ix whose columns for m a basis for t he column
space of A. A is a symbolic or numer ic mat r ix. Not e t hat size(colspace(A),2)
r et ur ns t he r ank of A.
Examples The st at ement s
A = sym([2,0;3,4;0,5])
B = colspace(A)
r et ur n
A =
[2,0]
[3,4]
[0,5]
B =
[ 1, 0]
[ 0, 1]
[–15/8, 5/4]
See Also null
orth in t he online MATLAB Funct ion Refer ence
compose
2-14
compose
Purpose Funct ional composit ion.
Syntax compose(f,g)
compose(f,g,z)
compose(f,g,x,z)
compose(f,g,x,y,z)
Description compose(f,g) r et ur ns f(g(y)) wher e f = f(x) and g = g(y). Her e x is t he
symbolic var iable of f as defined by findsym and y is t he symbolic var iable of g
as defined by findsym.
compose(f,g,z) r et ur ns f(g(z)) wher e f = f(x), g = g(y), and x and y ar e
t he symbolic var iables of f and g as defined by findsym.
compose(f,g,x,z) r et ur ns f(g(z)) and makes x t he independent var iable for
f. That is, if f = cos(x/t), t hen compose(f,g,x,z) r et ur ns cos(g(z)/t)
wher eas compose(f,g,t,z) r et ur ns cos(x/g(z)).
compose(f,g,x,y,z) r et ur ns f(g(z)) and makes x t he independent var iable
for f and y t he independent var iable for g. For f = cos(x/t) and
g = sin(y/u), compose(f,g,x,y,z) r et ur ns cos(sin(z/u)/t) wher eas
compose(f,g,x,u,z) r et ur ns cos(sin(y/z)/t).
Examples Suppose
syms x y z t u;
f = 1/(1 + x^2); g = sin(y); h = x^t; p = exp(–y/u);
Then
compose(f,g) -> 1/(1+sin(x)^2)
compose(f,g,t) -> 1/(1+sin(t)^2)
compose(h,g,x,z) -> sin(z)^t
compose(h,g,t,z) -> x^sin(z)
compose(h,p,x,y,z) -> exp(–z/u)^t
compose(h,p,t,u,z) -> x^exp(–y/z)
See Also finverse, subs, syms
conj
2-15
conj
Purpose Symbolic conjugat e.
Syntax conj(X)
Description conj(X) is t he complex conjugat e of X.
For a complex X, conj(X) = real(X) - i*imag(X).
See Also real, imag
cosint
2-16
cosint
Purpose Cosine int egr al funct ion.
Syntax Y = cosint(X)
Description cosint(X) evaluat es t he cosine int egr al funct ion at t he element s of X, a
numer ic mat r ix, or a symbolic mat r ix. The cosine int egr al funct ion is defined
by:
wher e γ is Euler ’s const ant 0.577215664...
Examples cosint(7.2) r et ur ns 0.0960.
cosint([0:0.1:1]) r et ur ns
Columns 1 through 7
Inf –1.7279 –1.0422 –0.6492 –0.3788 –0.1778 –0.0223

Columns 8 through 11

0.1005 0.1983 0.2761 0.3374
The st at ement s
syms x;
f = cosint(x);
diff(x)
r et ur n
cos(x)/x
See Also sinint
Ci x ( ) γ x ( ) ln
t cos 1 –
t
-------------------- t d
0
x

+ + =
det
2-17
det
Purpose Mat r ix det er minant .
Syntax r = det(A)
Description det(A) comput es t he det er minant of A, wher e A is a symbolic or numer ic
mat r ix. det(A) r et ur ns a symbolic expr ession, if A is symbolic; a numer ic value,
if A is numer ic.
Examples The st at ement s
syms a b c d;
det([a, b; c, d])
r et ur n
a*d – b*c
The st at ement s
A = sym([2/3 1/3;1 1])
r = det(A)
r et ur n
A =
[ 2/3, 1/3]
[ 1, 1]
r = 1/3
diag
2-18
diag
Purpose Cr eat e or ext r act symbolic diagonals.
Syntax diag(A,k)
diag(A)
Description diag(A,k), wher e A is a r ow or column vect or wit h n component s, r et ur ns a
squar e symbolic mat r ix of or der n+abs(k), wit h t he element s of A on t he k-t h
diagonal. k = 0 signifies t he main diagonal; k > 0, t he k-t h diagonal above t he
main diagonal; k < 0, t he k-t h diagonal below t he main diagonal.
diag(A,k), wher e A is a squar e symbolic mat r ix, r et ur ns a column vect or
for med fr om t he element s of t he k-t h diagonal of A.
diag(A), wher e A is a vect or wit h n component s, r et ur ns an n-by-n diagonal
mat r ix having A as it s main diagonal.
diag(A), wher e A is a squar e symbolic mat r ix, r et ur ns t he main diagonal of A.
Examples Suppose
v = [a b c]
Then bot h diag(v) and diag(v,0) r et ur n
[ a, 0, 0 ]
[ 0, b, 0 ]
[ 0, 0, c ]
diag(v,–2) r et ur ns
[ 0, 0, 0, 0, 0]
[ 0, 0, 0, 0, 0]
[ a, 0, 0, 0, 0]
[ 0, b, 0, 0, 0]
[ 0, 0, c, 0, 0]
Suppose
A =
[ a, b, c ]
[ 1, 2, 3 ]
[ x, y, z ]
diag
2-19
diag(A) r et ur ns
[ a ]
[ 2 ]
[ z ]
diag(A,1) r et ur ns
[ b ]
[ 3 ]
See Also tril, triu
diff
2-20
diff
Purpose Differ ent iat e.
Syntax diff(S,'v')
diff(S,n)
diff(S,'v',n)
Description diff(S) differ ent iat es a symbolic expr ession S wit h r espect t o it s fr ee var iable
as det er mined by findsym.
diff(S,'v') or diff(S,sym('v')) differ ent iat es S wit h r espect t o v.
diff(S,n), for a posit ive int eger n, differ ent iat es S n t imes.
diff(S,'v',n) and diff(S,n,'v') ar e also accept able.
Examples Assume
syms x t
Then
diff(sin(x^2))
r et ur ns
2*cos(x^2)*x
and
diff(t^6,6)
r et ur ns
720
See also int, jacobian, findsym
digits
2-21
digit s
Purpose Set var iable pr ecision accur acy.
Syntax digits(d)
d = digits
digits
Description digits specifies t he number of significant decimal digit s t hat Maple uses t o do
var iable pr ecision ar it hmet ic (VPA). The default value is 32 digit s.
digits(d) set s t he cur r ent VPA accur acy t o d digit s.
digits r et ur ns t he cur r ent VPA accur acy.
Examples If
z = 1.0e–16
x = 1.0e+2
digits(14)
t hen
y = vpa(x*z+1)
uses 14-digit decimal ar it hmet ic and r et ur ns
y =
1.0000000000000
Wher eas
digits(15)
y = vpa(x*z+1)
used 15-digit decimal ar it hmet ic and r et ur ns
y =
1.00000000000001
See Also double, vpa
double
2-22
double
Purpose Conver t symbolic mat r ix t o MATLAB numer ic for m.
Syntax R = double(S)
Description double(S) conver t s t he symbolic object S t o a numer ic object . If S is a symbolic
const ant or const ant expr ession, double r et ur ns a double-pr ecision
float ing-point number r epr esent ing t he value of S. If S is a symbolic mat r ix
whose ent r ies ar e const ant s or const ant expr essions, double r et ur ns a mat r ix
of double pr ecision float ing-point number s r epr esent ing t he values of S’s
ent r ies.
Examples double(sym('(1+sqrt(5))/2')) r et ur ns 1.6180.
The following st at ement s
a = sym(2*sqrt(2));
b = sym((1–sqrt(3))^2);
T = [a, b]
double(T)
r et ur n
ans =
2.8284 0.5359
See Also sym, vpa
dsolve
2-23
dsolve
Purpose Symbolic solut ion of or dinar y differ ent ial equat ions.
Syntax r = dsolve('eq1,eq2,...', 'cond1,cond2,...', 'v')
r = dsolve('eq1','eq2',...,'cond1','cond2',...,'v')
Description dsolve('eq1,eq2,...', 'cond1,cond2,...', 'v') symbolically solves t he
or dinar y differ ent ial equat ion(s) specified by eq1, eq2,... using v as t he
independent var iable and t he boundar y and/or init ial condit ion(s) specified by
cond1,cond2,....
The default independent var iable is t.
The let t er D denot es differ ent iat ion wit h r espect t o t he independent var iable;
wit h t he pr imar y default , t his is d/dx. A D followed by a digit denot es r epeat ed
differ ent iat ion. For example, D2 is d2/dx2. Any char act er immediat ely
following a differ ent iat ion oper at or is a dependent var iable. For example, D3y
denot es t he t hir d der ivat ive of y(x) or y(t).
Init ial/boundar y condit ions ar e specified wit h equat ions like y(a) = b or
Dy(a) = b, wher e y is a dependent var iable and a and b ar e const ant s. If t he
number of init ial condit ions specified is less t han t he number of dependent
var iables, t he r esult ing solut ions will cont ain t he ar bit r ar y const ant s C1,
C2,....
You can also input each equat ion and/or init ial condit ion as a separ at e
symbolic equat ion. dsolve accept s up t o 12 input ar gument s.
Wit h no out put ar gument s, dsolve r et ur ns a list of solut ions.
dsolve r et ur ns a war ning message, if it cannot find an analyt ic solut ion for an
equat ion. In such a case, you can find a numer ic solut ion, using MATLAB’s
ode23 or ode45 funct ion.
Examples dsolve('Dy = a*y') r et ur ns
exp(a*t)*C1
dsolve('Df = f + sin(t)') r et ur ns
–1/2*cos(t)–1/2*sin(t)+exp(t)*C1
dsolve
2-24
dsolve('(Dy)^2 + y^2 = 1','s') r et ur ns
–sin(–s+C1)
dsolve('Dy = a*y', 'y(0) = b') r et ur ns
exp(a*t)*b
dsolve('D2y = –a^2*y', 'y(0) = 1', 'Dy(pi/a) = 0') r et ur ns
cos(a*t)
dsolve('Dx = y', 'Dy = –x') r et ur ns
x=
cos(t)*C1+sin(t)*C2
y =
–sin(t)*C1+cos(t)*C2
Diagnostics If dsolve cannot find an analyt ic solut ion for an equat ion, it pr int s t he war ning
Warning: explicit solution could not be found
and r et ur n an empt y sym object .
See Also syms
eig
2-25
eig
Purpose Symbolic mat r ix eigenvalues and eigenvect or s.
Syntax lambda = eig(A)
[V,D] = eig(A)
[V,D,P] = eig(A)
lambda = eig(vpa(A))
[V,D] = eig(vpa(A))
Description lambda=eig(A) r et ur ns a symbolic vect or cont aining t he eigenvalues of t he
squar e symbolic mat r ix A.
[V,D] = eig(A) r et ur ns a mat r ix V whose columns ar e eigenvect or s and a
diagonal mat r ix D cont aining eigenvalues. If t he r esult ing V is t he same size as
A, t hen A has a full set of linear ly independent eigenvect or s t hat sat isfy
A*V = V*D.
[V,D,P]=eig(A) also r et ur ns P, a vect or of indices whose lengt h is t he t ot al
number of linear ly independent eigenvect or s, so t hat A*V = V*D(P,P).
lambda = eig(VPA(A)) and [V,D] = eig(VPA(A)) comput e numer ic
eigenvalues and eigenvect or s, r espect ively, using var iable pr ecision
ar it hmet ic. If A does not have a full set of eigenvect or s, t he columns of V will not
be linear ly independent .
Examples The st at ement s
R = sym(gallery('rosser'));
eig(R)
r et ur n
ans =
[ 0]
[ 1020]
[ 510+100*26^(1/2)]
[ 510–100*26^(1/2)]
[ 10*10405^(1/2)]
[ –10*10405^(1/2)]
[ 1000]
[ 1000]
eig
2-26
eig(vpa(R)) r et ur ns
ans =
[ –1020.0490184299968238463137913055]
[ .56512999999999999999999999999800e–28]
[ .98048640721516997177589097485157e–1]
[ 1000.0000000000000000000000000002]
[ 1000.0000000000000000000000000003]
[ 1019.9019513592784830028224109024]
[ 1020.0000000000000000000000000003]
[ 1020.0490184299968238463137913055]
The st at ement s
A = sym(gallery(5));
[v,lambda] = eig(A)
r et ur n
v =
[ 0]
[ 21/256]
[ –71/128]
[ 973/256]
[ 1]
lambda =

[ 0, 0, 0, 0, 0]
[ 0, 0, 0, 0, 0]
[ 0, 0, 0, 0, 0]
[ 0, 0, 0, 0, 0]
[ 0, 0, 0, 0, 0]
See Also jordan, poly, svd, vpa
expm
2-27
expm
Purpose Symbolic mat r ix exponent ial.
Syntax expm(A)
Description expm(A) is t he mat r ix exponent ial of t he symbolic mat r ix A.
Examples The st at ement s
syms t;
A = [0 1; –1 0];
expm(t*A)
r et ur n
[ cos(t), sin(t)]
[ –sin(t), cos(t)]
expand
2-28
expand
Purpose Symbolic expansion.
Syntax R = expand(S)
Description expand(S) wr it es each element of a symbolic expr ession S as a pr oduct of it s
fact or s. expand is most oft en used only wit h polynomials, but also expands
t r igonomet r ic, exponent ial, and logar it hmic funct ions.
Examples expand((x–2)*(x–4)) r et ur ns
x^2–6*x+8
expand(cos(x+y)) r et ur ns
cos(x)*cos(y)–sin(x)*sin(y)
expand(exp((a+b)^2)) r et ur ns
exp(a^2)*exp(a*b)^2*exp(b^2)
expand(log(a*b/sqrt(c))) r et ur ns
log(a)+log(b)–1/2*log(c)
expand([sin(2*t), cos(2*t)]) r et ur ns
[2*sin(t)*cos(t), 2*cos(t)^2–1]
See Also collect, factor, horner, simple, simplify, syms
ezcontour
2-29
ezcont our
Purpose Cont our plot t er .
Syntax ezcontour(f)
ezcontour(f,domain)
ezcontour(...,n)
Description ezcontour(f) plot s t he cont our lines of f(x,y), wher e f is a symbolic expr ession
t hat r epr esent s a mat hemat ical funct ion of t wo var iables, such as x and y.
The funct ion f is plot t ed over t he default domain -2π < x < 2π, -2π < y < 2π.
MATLAB chooses t he comput at ional gr id accor ding t o t he amount of var iat ion
t hat occur s; if t he funct ion f is not defined (singular ) for point s on t he gr id, t hen
t hese point s ar e not plot t ed.
ezcontour(f,domain) plot s f(x,y) over t he specified domain. domain can be
eit her a 4-by-1 vect or [xmin, xmax, ymin, ymax] or a 2-by-1 vect or [min, max]
(wher e, min < x < max, min < y < max).
If f is a funct ion of t he var iables u and v (r at her t han x and y), t hen t he domain
endpoint s umin, umax, vmin, and vmax ar e sor t ed alphabet ically. Thus,
ezcontour(u^2 − v^3,[0,1],[3,6]) plot s t he cont our lines for u
2
− v
3
over
0 < u < 1, 3 < v < 6.
ezcontour(...,n) plot s f over t he default domain using an n-by-n gr id. The
default value for n is 60.
ezcontour aut omat ically adds a t it le and axis labels.
Examples The following mat hemat ical expr ession defines a funct ion of t wo var iables, x
and y:
ezcontour r equir es a sym ar gument t hat expr esses t his funct ion using
MATLAB synt ax t o r epr esent exponent s, nat ur al logs, et c. This funct ion is
r epr esent ed by t he symbolic expr ession:
syms x y
f = 3*(1−x)^2*exp(−(x^2)−(y+1)^2) ...
− 10*(x/5 − x^3 − y^5)*exp(−x^2−y^2) ...
− 1/3*exp(−(x+1)^2 − y^2);
f x y , ( ) 3 1 x – ( )
2
e
x
2
– y 1 + ( )
2

10
x
5
--- x
3
– y
5

. ,
| `
e
x
2
– y
2


1
3
---e
x 1 + ( )
2
– y
2

– =
ezcontour
2-30
For convenience, t his expr ession is wr it t en on t hr ee lines.
Pass t he sym f t o ezcontour along wit h a domain r anging fr om -3 t o 3 and
specify a comput at ional gr id of 49-by-49:
ezcontour(f,[-3,3],49)
In t his par t icular case, t he t it le is t oo long t o fit at t he t op of t he gr aph so
MATLAB abbr eviat es t he st r ing.
See Also contour, ezcontourf, ezmesh, ezmeshc, ezplot, ezplot3, ezpolar, ezsurf,
ezsurfc
−3 −2 −1 0 1 2 3
−3
−2
−1
0
1
2
3
x
y
3 (1−x)
2
exp(−(x
2
) − (y+1)
2
)− ~~~ x
2
−y
2
)− 1/3 exp(−(x+1)
2
− y
2
)
ezcontourf
2-31
ezcont our f
Purpose Filled cont our plot t er .
Syntax ezcontourf(f)
ezcontourf(f,domain)
ezcontourf(...,n)
Description ezcontour(f) plot s t he cont our lines of f(x,y), wher e f is a sym t hat r epr esent s
a mat hemat ical funct ion of t wo var iables, such as x and y.
The funct ion f is plot t ed over t he default domain -2π < x < 2π, -2π < y < 2π.
MATLAB chooses t he comput at ional gr id accor ding t o t he amount of var iat ion
t hat occur s; if t he funct ion f is not defined (singular ) for point s on t he gr id, t hen
t hese point s ar e not plot t ed.
ezcontour(f,domain) plot s f(x,y) over t he specified domain. domain can be
eit her a 4-by-1 vect or [xmin, xmax, ymin, ymax] or a 2-by-1 vect or [min, max]
(wher e, min < x < max, min < y < max).
If f is a funct ion of t he var iables u and v (r at her t han x and y), t hen t he domain
endpoint s umin, umax, vmin, and vmax ar e sor t ed alphabet ically. Thus,
ezcontourf(u^2 − v^3,[0,1],[3,6]) plot s t he cont our lines for u
2
− v
3
over
0 < u < 1, 3 < v < 6.
ezcontourf(...,n) plot s f over t he default domain using an n-by-n gr id. The
default value for n is 60.
ezcontourf aut omat ically adds a t it le and axis labels.
Examples The following mat hemat ical expr ession defines a funct ion of t wo var iables, x
and y:
ezcontourf r equir es a sym ar gument t hat expr esses t his funct ion using
MATLAB synt ax t o r epr esent exponent s, nat ur al logs, et c. This funct ion is
r epr esent ed by t he symbolic expr ession:
syms x y
f = 3*(1−x)^2*exp(−(x^2)−(y+1)^2) ...
− 10*(x/5 − x^3 − y^5)*exp(−x^2−y^2) ...
− 1/3*exp(−(x+1)^2 − y^2);
f x y , ( ) 3 1 x – ( )
2
e
x
2
– y 1 + ( )
2

10
x
5
--- x
3
– y
5

. ,
| `
e
x
2
– y
2


1
3
---e
x 1 + ( )
2
– y
2

– =
ezcontourf
2-32
For convenience, t his expr ession is wr it t en on t hr ee lines.
Pass t he sym f t o ezcontourf along wit h a domain r anging fr om −3 t o 3 and
specify a gr id of 49-by-49:
ezcontourf(f,[−3,3],49)
In t his par t icular case, t he t it le is t oo long t o fit at t he t op of t he gr aph so
MATLAB abbr eviat es t he st r ing.
See Also contourf, ezcontour, ezmesh, ezmeshc, ezplot, ezplot3, ezpolar, ezsurf,
ezsurfc
−3 −2 −1 0 1 2 3
−3
−2
−1
0
1
2
3
x
y
3 (1−x)
2
exp(−(x
2
) − (y+1)
2
)− ~~~ x
2
−y
2
)− 1/3 exp(−(x+1)
2
− y
2
)
ezmesh
2-33
2ezmesh
Purpose 3-D mesh plot t er .
Syntax ezmesh(f)
ezmesh(f,domain)
ezmesh(x,y,z)
ezmesh(x,y,z,[smin,smax,tmin,tmax]) or ezmesh(x,y,z,[min,max])
ezmesh(...,n)
ezmesh(...,'circ')
Description ezmesh(f) cr eat es a gr aph of f(x,y), wher e f is a symbolic expr ession t hat
r epr esent s a mat hemat ical funct ion of t wo var iables, such as x and y.
The funct ion f is plot t ed over t he default domain −2π < x < 2π, −2π < y < 2π.
MATLAB chooses t he comput at ional gr id accor ding t o t he amount of var iat ion
t hat occur s; if t he funct ion f is not defined (singular ) for point s on t he gr id, t hen
t hese point s ar e not plot t ed.
ezmesh(f,domain) plot s f over t he specified domain. domain can be eit her a
4-by-1 vect or [xmin, xmax, ymin, ymax] or a 2-by-1 vect or [min, max] (wher e,
min < x < max, min < y < max).
If f is a funct ion of t he var iables u and v (r at her t han x and y), t hen t he domain
endpoint s umin, umax, vmin, and vmax ar e sor t ed alphabet ically. Thus,
ezmesh(u^2 − v^3,[0,1],[3,6]) plot s u
2
− v
3
over 0 < u < 1, 3 < v < 6.
ezmesh(x,y,z) plot s t he par amet r ic sur face x = x(s,t), y = y(s,t), and z = z(s,t)
over t he squar e: −2π < s < 2π, −2π < t < 2π.
ezmesh(x,y,z,[smin,smax,tmin,tmax]) or ezmesh(x,y,z,[min,max]) plot s
t he par amet r ic sur face using t he specified domain.
ezmesh(...,n) plot s f over t he default domain using an n-by-n gr id. The
default value for n is 60.
ezmesh(...,'circ') plot s f over a disk cent er ed on t he domain
Remarks rotate3d is always on. To r ot at e t he gr aph, click and dr ag wit h t he mouse.
Examples This example visualizes t he funct ion,
f x y , ( ) xe
x –
2
y
2

=
ezmesh
2-34
wit h a mesh plot dr awn on a 40-by-40 gr id. The mesh lines ar e set t o a unifor m
blue color by set t ing t he color map t o a single color :
syms x y
ezmesh(x*exp(−x^2−y^2),40)
colormap [0 0 1]
See Also ezcontour, ezcontourf, ezmeshc, ezplot, ezplot3, ezpolar, ezsurf, ezsurfc,
mesh
−2
0
2
−2
−1
0
1
2
−0.5
0
0.5
x
x exp(−x
2
− y
2
)
y
ezmeshc
2-35
2ezmeshc
Purpose Combined mesh/cont our plot t er .
Syntax ezmeshc(f)
ezmeshc(f,domain)
ezmeshc(x,y,z)
ezmeshc(x,y,z,[smin,smax,tmin,tmax]) or ezmeshc(x,y,z,[min,max])
ezmeshc(...,n)
ezmeshc(...,'circ')
Description ezmeshc(f) cr eat es a gr aph of f(x,y), wher e f is a symbolic expr ession t hat
r epr esent s a mat hemat ical funct ion of t wo var iables, such as x and y.
The funct ion f is plot t ed over t he default domain −2π < x < 2π, −2π < y < 2π.
MATLAB chooses t he comput at ional gr id accor ding t o t he amount of var iat ion
t hat occur s; if t he funct ion f is not defined (singular ) for point s on t he gr id, t hen
t hese point s ar e not plot t ed.
ezmeshc(f,domain) plot s f over t he specified domain. domain can be eit her a
4-by-1 vect or [xmin, xmax, ymin, ymax] or a 2-by-1 vect or [min, max] (wher e,
min < x < max, min < y < max).
If f is a funct ion of t he var iables u and v (r at her t han x and y), t hen t he domain
endpoint s umin, umax, vmin, and vmax ar e sor t ed alphabet ically. Thus,
ezmeshc(u^2 − v^3,[0,1],[3,6]) plot s u
2
− v
3
over 0 < u < 1, 3 < v < 6.
ezmeshc(x,y,z) plot s t he par amet r ic sur face x =x(s,t), y =y(s,t), and z = z(s,t)
over t he squar e: −2π < s < 2π, −2π < t < 2π.
ezmeshc(x,y,z,[smin,smax,tmin,tmax]) or ezmeshc(x,y,z,[min,max])
plot s t he par amet r ic sur face using t he specified domain.
ezmeshc(...,n) plot s f over t he default domain using an n-by-n gr id. The
default value for n is 60.
ezmeshc(...,'circ') plot s f over a disk cent er ed on t he domain
Remarks rotate3d is always on. To r ot at e t he gr aph, click and dr ag wit h t he mouse.
Examples Cr eat e a mesh/cont our gr aph of t he expr ession,
ezmeshc
2-36
over t he domain −5 < x < 5, −2*pi < y < 2*pi:
syms x y
ezmeshc(y/(1 + x^2 + y^2),[−5,5,−2*pi,2*pi])
Use t he mouse t o r ot at e t he axes t o bet t er obser ve t he cont our lines (t his
pict ur e uses a view of azimut h = −65.5 and elevat ion = 26).
See Also ezcontour, ezcontourf, ezmesh, ezplot, ezplot3, ezpolar, ezsurf, ezsurfc,
meshc
f x y , ( )
y
1 x
2
y
2
+ +
--------------------------- =
−5
0
5
−5
0
5
−0.5
0
0.5
x
y/(1 + x
2
+ y
2
)
y
ezplot
2-37
2ezplot
Purpose Funct ion plot t er .
Syntax ezplot(f)
ezplot(f,[min,max])
ezplot(f,[xmin,xmax,ymin,ymax])
ezplot(x,y)
ezplot(x,y,[tmin,tmax])
ezplot(...,figure)
Description ezplot(f) plot s t he expr ession f = f(x) over t he default domain −2π < x < 2π.
ezplot(f,[xmin xmax]) plot s f = f(x) over t he specified domain. It opens and
displays t he r esult in a window labeled Fi gure No. 1. If any plot windows ar e
alr eady open, ezplot displays t he r esult in t he highest number ed window.
ezplot(f,[xmin xmax],fign) opens (if necessar y) and displays t he plot in t he
window labeled fign.
For implicit ly defined funct ions, f = f(x,y):
ezplot(f) plot s f(x,y) = 0 over t he default domain −2π < x < 2π, −2π < y < 2π.
ezplot(f,[xmin,xmax,ymin,ymax]) plot s f(x,y) = 0 over xmin < x < xmax and
ymin < y < ymax.
ezplot(f,[min,max])plot s f(x,y) = 0 over min < x < max and min < y < max.
If f is a funct ion of t he var iables u and v (r at her t han x and y), t hen t he domain
endpoint s umin, umax, vmin, and vmax ar e sor t ed alphabet ically. Thus,
ezplot(u^2 − v^2 − 1,[−3,2,−2,3]) plot s u
2
− v
2
− 1 = 0 over −3 < u < 2,
−2 < v < 3.
ezplot(x,y) plot s t he par amet r ically defined planar cur ve x =x(t) and y =y(t)
over t he default domain 0 < t < 2π.
ezplot(x,y,[tmin,tmax]) plot s x = x(t) and y = y(t) over tmin < t < tmax.
ezplot(...,figure) plot s t he given funct ion over t he specified domain in t he
Figur e window ident ified by t he handle figure.
Algorithm If you do not specify a plot r ange, ezplot samples t he funct ion bet ween –2*pi
and 2*pi and select s a subint er val wher e t he var iat ion is significant as t he plot
ezplot
2-38
domain. For t he r ange, ezplot omit s ext r eme values associat ed wit h
singular it ies.
Examples This example plot s t he implicit ly defined funct ion,
x
2
− y
4
= 0
over t he domain [−2π, 2π]:
syms x y
ezplot(x^2−y^4)
−6 −4 −2 0 2 4 6
−6
−4
−2
0
2
4
6
x
y
x
2
−y
4
= 0
ezplot
2-39
The following st at ement s
syms x
ezplot(erf(x))
grid
plot a gr aph of t he er r or funct ion:
See Also ezcontour, ezcontourf, ezmesh, ezmeshc, ezplot3, ezpolar, ezsurf, ezsurfc,
plot
-2 -1.5 -1 -0.5 0 0.5 1 1.5 2
-1
0.5
0
0.5
1
x
erf(x)
ezplot3
2-40
2ezplot 3
Purpose 3-D par amet r ic cur ve plot t er .
Syntax ezplot3(x,y,z)
ezplot3(x,y,z,[tmin,tmax])
ezplot3(...,'animate')
Description ezplot3(x,y,z) plot s t he spat ial cur ve x = x(t), y = y(t), and z = z(t) over t he
default domain 0 < t < 2π.
ezplot3(x,y,z,[tmin,tmax]) plot s t he cur ve x =x(t), y =y(t), and z =z(t) over
t he domain tmin < t < tmax.
ezplot3(...,'animate') pr oduces an animat ed t r ace of t he spat ial cur ve.
Examples This example plot s t he par amet r ic cur ve,
over t he domain [0,6π]:
syms t; ezplot3(sin(t), cos(t), t,[0,6*pi])
−1
−0.5
0
0.5
1
−1
−0.5
0
0.5
1
0
5
10
15
20
x
x = sin(t), y = cos(t), z = t
y
z
ezplot3
2-41
See Also ezcontour, ezcontourf, ezmesh, ezmeshc, ezplot, ezpolar, ezsurf, ezsurfc,
plot3
ezpolar
2-42
2ezpolar
Purpose Polar coor dinat e plot t er .
Syntax ezpolar(f)
ezpolar(f,[a,b])
Description ezpolar(f) plot s t he polar cur ve rho = f(theta) over t he default domain
0 < t het a < 2π.
ezpolar(f,[a,b]) plot s f for a < theta < b.
Example This example cr eat es a polar plot of t he funct ion,
1 + cos(t)
over t he domain [0, 2π]:
syms t
ezpolar(1+cos(t))
0.5
1
1.5
2
30
210
60
240
90
270
120
300
150
330
180 0
r = 1+cos(t)
ezsurf
2-43
2ezsur f
Purpose 3-D color ed sur face plot t er .
Syntax ezsurf(f)
ezsurf(f,domain)
ezsurf(x,y,z)
ezsurf(x,y,z,[smin,smax,tmin,tmax]) or ezsurf(x,y,z,[min,max])
ezsurf(...,n)
ezsurf(...,'circ')
Purpose ezsurf(f) cr eat es a gr aph of f(x,y), wher e f is a symbolic expr ession t hat
r epr esent s a mat hemat ical funct ion of t wo var iables, such as x and y.
The funct ion f is plot t ed over t he default domain −2π < x < 2π, −2π < y < 2π.
MATLAB chooses t he comput at ional gr id accor ding t o t he amount of var iat ion
t hat occur s; if t he funct ion f is not defined (singular ) for point s on t he gr id, t hen
t hese point s ar e not plot t ed.
ezsurf(f,domain) plot s f over t he specified domain. domain can be eit her a
4-by-1 vect or [xmin, xmax, ymin, ymax] or a 2-by-1 vect or [min, max] (wher e,
min < x < max, min < y < max).
If f is a funct ion of t he var iables u and v (r at her t han x and y), t hen t he domain
endpoint s umin, umax, vmin, and vmax ar e sor t ed alphabet ically. Thus,
ezsurf(u^2 − v^3,[0,1],[3,6]) plot s u
2
− v
3
over 0 < u < 1, 3 < v < 6.
ezsurf(x,y,z) plot s t he par amet r ic sur face x = x(s,t), y = y(s,t), and z = z(s,t)
over t he squar e: −2π < s < 2π, −2π < t < 2π.
ezsurf(x,y,z,[smin,smax,tmin,tmax]) or ezsurf(x,y,z,[min,max]) plot s
t he par amet r ic sur face using t he specified domain.
ezsurf(...,n) plot s f over t he default domain using an n-by-n gr id. The
default value for n is 60.
ezsurf(...,'circ') plot s f over a disk cent er ed on t he domain
Remarks rotate3d is always on. To r ot at e t he gr aph, click and dr ag wit h t he mouse.
Examples ezsurf does not gr aph point s wher e t he mat hemat ical funct ion is not defined
(t hese dat a point s ar e set t o NaNs, which MATLAB does not plot ). This example
ezsurf
2-44
illust r at es t his filt er ing of singular it ies/discont inuous point s by gr aphing t he
funct ion,
over t he default domain −2π < x < 2π, −2π < y < 2π:
syms x y
ezsurf(real(atan(x+i*y)))
Not e also t hat ezsurf cr eat es gr aphs t hat have axis labels, a t it le, and ext end
t o t he axis limit s.
See Also ezcontour, ezcontourf, ezmesh, ezmeshc, ezplot, ezpolar, ezsurfc, surf
f x y , ( ) x i y + ( ) atan ( ) real =
−5
0
5
−5
0
5
−2
−1
0
1
2
x
real(atan(x+i y))
y
ezsurfc
2-45
2ezsur fc
Purpose Combined sur face/cont our plot t er .
Syntax ezsurfc(f)
ezsurfc(f,domain)
ezsurfc(x,y,z)
ezsurfc(x,y,z,[smin,smax,tmin,tmax]) or ezsurfc(x,y,z,[min,max])
ezsurfc(...,n)
ezsurfc(...,'circ')
Description ezsurfc(f) cr eat es a gr aph of f(x,y), wher e f is a symbolic expr ession t hat
r epr esent s a mat hemat ical funct ion of t wo var iables, such as x and y.
The funct ion f is plot t ed over t he default domain −2π < x < 2π, −2π < y < 2π.
MATLAB chooses t he comput at ional gr id accor ding t o t he amount of var iat ion
t hat occur s; if t he funct ion f is not defined (singular ) for point s on t he gr id, t hen
t hese point s ar e not plot t ed.
ezsurfc(f,domain) plot s f over t he specified domain. domain can be eit her a
4-by-1 vect or [xmin, xmax, ymin, ymax] or a 2-by-1 vect or [min, max] (wher e,
min < x < max, min < y < max).
If f is a funct ion of t he var iables u and v (r at her t han x and y), t hen t he domain
endpoint s umin, umax, vmin, and vmax ar e sor t ed alphabet ically. Thus,
ezsurfc(u^2 − v^3,[0,1],[3,6]) plot s u
2
− v
3
over 0 < u < 1, 3 < v < 6.
ezsurfc(x,y,z) plot s t he par amet r ic sur face x =x(s,t), y =y(s,t), and z = z(s,t)
over t he squar e: −2π < s < 2π, −2π < t < 2π.
ezsurfc(x,y,z,[smin,smax,tmin,tmax]) or ezsurfc(x,y,z,[min,max])
plot s t he par amet r ic sur face using t he specified domain.
ezsurfc(...,n) plot s f over t he default domain using an n-by-n gr id. The
default value for n is 60.
ezsurfc(...,'circ') plot s f over a disk cent er ed on t he domain.
Remarks rotate3d is always on. To r ot at e t he gr aph, click and dr ag wit h t he mouse.
ezsurfc
2-46
Examples Cr eat e a sur face/cont our plot of t he expr ession,
over t he domain −5 < x < 5, −2*pi < y < 2*pi, wit h a comput at ional gr id of size
35-by-35:
syms x y
ezsurfc(y/(1 + x^2 + y^2),[−5,5,−2*pi,2*pi],35)
Use t he mouse t o r ot at e t he axes t o bet t er obser ve t he cont our lines (t his
pict ur e uses a view of azimut h = −65.5 and elevat ion = 26)
See Also ezcontour, ezcontourf, ezmesh, ezmeshc, ezplot, ezpolar, ezsurf, surfc
f x y , ( )
y
1 x
2
y
2
+ +
--------------------------- =
−5
0
5
−5
0
5
−0.5
0
0.5
x
y/(1 + x
2
+ y
2
)
y
factor
2-47
fact or
Purpose Fact or izat ion.
Syntax factor(X)
Description factor can t ake a posit ive int eger , an ar r ay of symbolic expr essions, or an
ar r ay of symbolic int eger s as an ar gument . If N is a posit ive int eger , factor(N)
r et ur ns t he pr ime fact or izat ion of N.
If S is a mat r ix of polynomials or int eger s, factor(S) fact or s each element . If
any element of an int eger ar r ay has mor e t han 16 digit s, you must use sym t o
cr eat e t hat element , for example, sym('N').
Examples factor(x^3–y^3) r et ur ns
(x–y)*(x^2+x*y+y^2)
factor([a^2–b^2, a^3+b^3]) r et ur ns
[(a–b)*(a+b), (a+b)*(a^2–a*b+b^2)]
factor(sym('12345678901234567890')) r et ur ns
(2)*(3)^2*(5)*(101)*(3803)*(3607)*(27961)*(3541)
See Also collect, expand, horner, simplify, simple
findsym
2-48
findsym
Purpose Finds t he var iables in a symbolic expr ession or mat r ix.
Syntax r = findsym(S)
r = findsym(S,n)
Description findsym(S) r et ur ns all symbolic var iables in S in alphabet ical or der , separ at ed
by commas. If S does not cont ain any var iables, findsym r et ur ns an empt y
st r ing.
findsym(S,n) r et ur ns t he n var iables alphabet ically closest t o x.
Note A symbolic var iable is an alphanumer ic name, ot her t han i or j, t hat
begins wit h an alphabet ic char act er .
Examples syms a x y z t
findsym(sin(pi*t)) returns pi, t.
findsym(x+i*y–j*z) returns x, y, z.
findsym(a+y,1) r et ur ns y.
See Also compose, diff, int, limit, taylor
finverse
2-49
finver se
Purpose Funct ional inver se.
Syntax g = finverse(f)
g = finverse(f,u)
Description g = finverse(f) r et ur ns t he funct ional inver se of f. f is a scalar sym
r epr esent ing a funct ion of one symbolic var iable, say x. Then g is a scalar sym
t hat sat isfies g(f(x)) = x. That is, finverse(f) r et ur ns f
–1
, pr ovided f
–1
exist s.
g = finverse(f,v) uses t he symbolic var iable v, wher e v is a sym, as t he
independent var iable. Then g is a scalar sym t hat sat isfies g(f(v)) = v. Use
t his for m when f cont ains mor e t han one symbolic var iable.
Examples finverse(1/tan(x)) r et ur ns
atan(1/x)
finverse(exp(u–2*v),u) r et ur ns
2*v+log(u)
See Also compose, syms
fortran
2-50
for t ran
Purpose For t r an r epr esent at ion of a symbolic expr ession.
Syntax fortran(S)
Description fortran(S)r et ur ns t he For t r an code equivalent t o t he expr ession S.
Examples The st at ement s
syms x
f = taylor(log(1+x));
fortran(f)
r et ur n
t0 = x–x**2/2+x**3/3–x**4/4+x**5/5
The st at ement s
H = sym(hilb(3));
fortran(H)
r et ur n
H(1,1) = 1 H(1,2) = 1.E0/2.E0 H(1,3) = 1.E0/3.E0
H(2,1) = 1.E0/2.E0 H(2,2) = 1.E0/3.E0 H(2,3) = 1.E0/4.E0
H(3,1) = 1.E0/3.E0 H(3,2) = 1.E0/4.E0 H(3,3) = 1.E0/5.E0
See Also ccode, latex, pretty
fourier
2-51
four ier
Purpose Four ier int egr al t r ansfor m.
Syntax F = fourier(f)
F = fourier(f,v)
F = fourier(f,u,v)
Description F = fourier(f) is t he Four ier t r ansfor m of t he symbolic scalar f wit h default
independent var iable x. The default r et ur n is a funct ion of w. The Four ier
t r ansfor m is applied t o a funct ion of x and r et ur ns a funct ion of w.
If f = f(w), fourier r et ur ns a funct ion of t.
By definit ion
wher e x is t he symbolic var iable in f as det er mined by findsym.
F = fourier(f,v) makes F a funct ion of t he symbol v inst ead of t he default w.
F = fourier(f,u,v) makes f a funct ion of u and F a funct ion of v inst ead of
t he default var iables x and w, r espect ively.
f f x ( ) = F F w ( ) = ⇒
F F t ( ) =
F w ( ) f x ( )e
i wx –
x d
∞ –


=
F v ( ) f x ( )e
i v x –
x d
∞ –


=
F v ( ) f u ( )e
i v u –
u d
∞ –


=
fourier
2-52
Examples
Fourier Transform MATLAB Command
f = exp(–x^2)
fourier(f)
r et ur ns
pi^(1/2)*exp(–1/4*w^2)
g = exp(–abs(w))
fourier(g)
r et ur ns
2/(1+t^2)
f = x*exp(–abs(x))
fourier(f,u)
r et ur ns
–4*i/(1+u^2)^2*u
f x ( ) e
x
2

=
F f [ ] w ( ) f x ( )e
i xw –
x
π e
w
2
4 ⁄ –
=
d
∞ –


=
g w ( ) e
w –
=
F g [ ] t ( ) g w ( )e
i t w –
w
2
1 t
2
+
-------------- =
d
∞ –


=
f x ( ) xe
x –
=
F f [ ] u ( ) f x ( )e
i xu –
x d
∞ –


4i
1 u
2
+ ( )
2u
--------------------------- –
=
=
fourier
2-53
See Also ifourier, laplace, ztrans
syms x real
f = exp(–x^2*abs(v))*sin(v)/v
fourier(f,v,u)
r et ur ns
–atan((u–1)/x^2)+atan((u+1)/x^2)
Fourier Transform MATLAB Command
f x v , ( ) e
x
2
v – v sin
v
------------ x r eal , =
F f v ( ) [ ] u ( ) f x v , ( )e
i v u –
v d
∞ –


u 1 –
x
2
------------ - at an –
u 1 +
x
2
------------- at an +
=
=
funtool
2-54
funt ool
Purpose Funct ion calculat or .
Syntax funtool
Description funtool is a visual funct ion calculat or t hat manipulat es and displays funct ions
of one var iable. At t he click of a but t on, for example, funtool dr aws a gr aph
r epr esent ing t he sum, pr oduct , differ ence, or r at io of t wo funct ions t hat you
specify. funtool includes a funct ion memor y t hat allows you t o st or e funct ions
for lat er r et r ieval.
At st ar t up, funtool displays gr aphs of a pair of funct ions, f(x) = x and
g(x) = 1. The gr aphs plot t he funct ions over t he domain [–2*pi, 2*pi].
funtool also displays a cont r ol panel t hat let s you save, r et r ieve, r edefine,
combine, and t r ansfor m f and g.
Text Fields. The t op of t he cont r ol panel cont ains a gr oup of edit able t ext fields.
f= Displays a symbolic expr ession r epr esent ing f. Edit t his field t o
r edefine f.
g= Displays a symbolic expr ession r epr esent ing g. Edit t his field t o
r edefine g.
x= Displays t he domain used t o plot f and g. Edit t his field t o
specify a differ ent domain.
funtool
2-55
a= Displays a const ant fact or used t o modify f (see but t on
descr ipt ions in t he next sect ion). Edit t his field t o change t he
value of t he const ant fact or .
funtool r edr aws f and g t o r eflect any changes you make t o t he cont ent s of t he
cont r ol panel’s t ext fields.
Control Buttons. The bot t om par t of t he cont r ol panel cont ains an ar r ay of
but t ons t hat t r ansfor m f and per for m ot her oper at ions.
The fir st r ow of cont r ol but t ons r eplaces f wit h var ious t r ansfor mat ions of f.
df/dx Der ivat ive of f
i nt f Int egr al of f
s imple f Simplified for m of f, if possible
num f Numer at or of f
den f Denominat or of f
1/f Recipr ocal of f
fi nv Inver se of f
The oper at or s i nt f and fi nv may fail if t he cor r esponding symbolic expr essions
do not exist in closed for m.
The second r ow of but t ons t r anslat es and scales f and t he domain of f by a
const ant fact or . To specify t he fact or , ent er it s value in t he field labeled a= on
t he calculat or cont r ol panel. The oper at ions ar e
f+a Replaces f(x) by f(x) + a.
f–a Replaces f(x) by f(x) – a.
f*a Replaces f(x) by f(x) * a.
f/a Replaces f(x) by f(x) / a.
f^a Replaces f(x) by f(x) ^ a.
f(x+a) Replaces f(x) by f(x + a ).
f(x*a) Replaces f(x) by f(x * a).
funtool
2-56
The fir st four but t ons of t he t hir d r ow r eplace f wit h a combinat ion of f and g.
f+g Replaces f(x) by f(x) + g(x).
f–g Replaces f(x) by f(x)–g(x).
f*g Replaces f(x) by f(x) * g(x).
f/g Replaces f(x) by f(x) / g(x).
The r emaining but t ons on t he t hir d r ow int er change f and g.
g=f Replaces g wit h f.
swap Replaces f wit h g and g wit h f.
The fir st t hr ee but t ons in t he four t h r ow allow you t o st or e and r et r ieve
funct ions fr om t he calculat or ’s funct ion memor y.
Insert Adds f t o t he end of t he list of st or ed funct ions.
Cycle Replaces f wit h t he next it em on t he funct ion list .
Delet e Delet es f fr om t he list of st or ed funct ions.
The ot her four but t ons on t he four t h r ow per for m miscellaneous funct ions:
Re set Reset s t he calculat or t o it s init ial st at e.
Hel p Displays t he online help for t he calculat or .
Demo Runs a shor t demo of t he calculat or .
Close Closes t he calculat or ’s windows.
See Also ezplot, syms
horner
2-57
hor ner
Purpose Hor ner polynomial r epr esent at ion.
Syntax R = horner(P)
Description Suppose P is a mat r ix of symbolic polynomials. horner(P) t r ansfor ms each
element of P int o it s Hor ner , or nest ed, r epr esent at ion.
Examples horner(x^3–6*x^2+11*x–6) r et ur ns
–6+(11+(–6+x)*x)*x
horner([x^2+x;y^3–2*y]) r et ur ns
[ (1+x)∗x]
[(–2+y^2)*y]
See Also expand, factor, simple, simplify, syms
hypergeom
2-58
hyper geom
Purpose Gener alized hyper geomet r ic funct ion.
Syntax hypergeom(n, d, z)
Description hypergeom(n, d, z) is t he gener alized hyper geomet r ic funct ion F(n, d, z), also
known as t he Bar nes ext ended hyper geomet r ic funct ion and denot ed by
j
F
k
wher e j = length(n) and k = length(d). For scalar a, b, and c,
hypergeom([a,b],c,z) is t he Gauss hyper geomet r ic funct ion
2
F
1
(a,b;c;z).
The definit ion by a for mal power ser ies is
wher e
Eit her of t he fir st t wo ar gument s may be a vect or pr oviding t he coefficient
par amet er s for a single funct ion evaluat ion. If t he t hir d ar gument is a vect or ,
t he funct ion is evaluat ed point wise. The r esult is numer ic if all t he ar gument s
ar e numer ic and symbolic if any of t he ar gument s is symbolic.
See Abr amowit z and St egun, Handbook of Mathematical Functions, chapt er
15.
Examples syms a z
hypergeom([],[],z) r et ur ns exp(z)
hypergeom(1,[],z) r et ur ns −1/(−1+z)
hypergeom(1,2,'z') r et ur ns (exp(z)−1)/z
hypergeom([1,2],[2,3],'z') r et ur ns −2*(−exp(z)+1+z)/z^2
hypergeom(a,[],z) r et ur ns (1−z)^(−a)
hypergeom([],1,−z^2/4) r et ur ns besselj(0,z)
F n d z , , ( )
C
n k ,
C
d k ,
------------
z
k
k!
----- ⋅
k 0 =


=
C
v k ,
Γ v
j
k + ( )
Γ v
j
( )
-----------------------
j 1 =
v

=
hypergeom
2-59
hypergeom([−n, n],1/2,(1−z)/2) r et ur ns
expand(cos(n*acos(z)))
which is T(n, z), t he n-t h Chebyshev polynomial.
ifourier
2-60
ifour ier
Purpose Inver se Four ier int egr al t r ansfor m.
Syntax f = ifourier(F)
f = ifourier(F,u)
f = ifourier(F,v,u)
Description f = ifourier(F) is t he inver se Four ier t r ansfor m of t he scalar symbolic object
F wit h default independent var iable w. The default r et ur n is a funct ion of x. The
inver se Four ier t r ansfor m is applied t o a funct ion of w and r et ur ns a funct ion
of x.
If F = F(x), ifourier r et ur ns a funct ion of t.
By definit ion
f = ifourier(F,u) makes f a funct ion of u inst ead of t he default x.
Her e u is a scalar symbolic object .
f = ifourier(F,v,u) t akes F t o be a funct ion of v and f t o be a funct ion of u
inst ead of t he default w and x, r espect ively.
F F w ( ) = f f x ( ) = ⇒
f f t ( ) =
f x ( ) 1 2π ( ) ⁄ F w ( )e
i wx
w d
∞ –


=
f u ( ) 1 2π ( ) ⁄ F w ( )e
i wu
w d
∞ –


=
f u ( ) 1 2π ( ) ⁄ F v ( )e
i v u
v d
∞ –


=
ifourier
2-61
Examples
Inverse Fourier Transform MATLAB Command
syms a real
f = exp(–w^2/(4*a^2))
F = ifourier(f)
F = simple(F)
r et ur ns
a*exp(–x^2*a^2)/pi^(1/2)
g = exp(–abs(x))
ifourier(g)
r et ur ns
1/(1+t^2)/pi
f = 2*exp(–abs(w)) – 1
simple(ifourier(f,t))
r et ur ns
(2–pi*Dirac(t)–pi*Dirac(t)*t^2)/
(pi+pi*t^2)
f w ( ) e
w
2
4a
2
( ) ⁄
=
F
1 –
f [ ] x ( ) f w ( )e
i xw
w d
∞ –


a
π
-------e
a x ( )
2

=
=
g x ( ) e
x –
=
F
1 –
g [ ] t ( ) g x ( )e
i t x
x d
∞ –


π
1 t
2
+
--------------
=
=
f w ( ) 2e
w –
1 – =
F
1 –
f [ ] t ( ) f w ( )e
i t w
w d
∞ –


2 πδ t ( ) 1 t
2
– ( ) –
π 1 t
2
+ ( )
------------------------------------------
=
=
ifourier
2-62
See Also fourier, ilaplace, iztrans
syms w real
f = exp(–w^2*abs(v))*sin(v)/v
ifourier(f,v,t)
r et ur ns
1/2*(atan((t+1)/w^2)–
atan((–1+t)/w^2))/pi
Inverse Fourier Transform MATLAB Command
f w v , ( ) e
w
2
v – v sin
v
------------ w r eal , =
F
1 –
f v ( ) [ ] t ( ) f w v , ( )e
i v t
v d
∞ –


1

------
t 1 +
w
2
----------- at an
t 1 –
w
2
----------- at an –
. ,
| `
=
=
ilaplace
2-63
ilaplace
Purpose Inver se Laplace t r ansfor m.
Syntax F = ilaplace(L)
F = ilaplace(L,y)
F = ilaplace(L,y,x)
Description F = ilaplace(L) is t he inver se Laplace t r ansfor m of t he scalar symbolic object
L wit h default independent var iable s. The default r et ur n is a funct ion of t. The
inver se Laplace t r ansfor m is applied t o a funct ion of s and r et ur ns a funct ion
of t.
If L = L(t), ilaplace r et ur ns a funct ion of x.
By definit ion
wher e c is a r eal number select ed so t hat all singular it ies of L(s) ar e t o t he left
of t he line s = c, i.
F = ilaplace(L,y) makes F a funct ion of y inst ead of t he default t.
Her e y is a scalar symbolic object .
F = ilaplace(L,y,x) t akes F t o be a funct ion of x and L a funct ion of y inst ead
of t he default var iables t and s, r espect ively.
L L s ( ) = F F t ( ) = ⇒
F F x ( ) =
F t ( ) L s ( )e
s t
s d
c i ∞ –
c i ∞ +

=
F y ( ) L y ( )e
s y
s d
c i ∞ –
c i ∞ +

=
F x ( ) L y ( )e
x y
y d
c i ∞ –
c i ∞ +

=
ilaplace
2-64
Examples
Inverse Laplace Transform MATLAB Command
f = 1/s^2
ilaplace(f)
r et ur ns
t
g = 1/(t–a)^2
ilaplace(g)
r et ur ns
x*exp(a*x)
f = 1/(u^2–a^2)
ilaplace(f,x)
r et ur ns
1/2/a*exp(a*x)–1/2/a*exp(–a*x)
f s ( )
1
s
2
----- =
L
1 –
f [ ]
1
2πi
--------- f s ( )e
s t
s d
c i ∞ –
c i ∞ +

t
=
=
g t ( )
1
t a – ( )
2
------------------- =
L
1 –
g [ ]
1
2πi
--------- g t ( )e
x t
t d
c i ∞ –
c i ∞ +

xe
a x
=
=
f u ( )
1
u
2
a
2

------------------ =
L
1 –
f [ ]
1
2πi
--------- g u ( )e
xu
u d
c i ∞ –
c i ∞ +

1
2ae
a x
---------------
1
2ae
a x –
------------------ –
=
=
ilaplace
2-65
See Also ifourier, iztrans, laplace
f = s^3*v/(s^2+v^2)
laplace(f,v,x)
r et ur ns
s^3*cos(s*x)
Inverse Laplace Transform MATLAB Command
f s v , ( )
s
3
v
s
2
v
2
+
----------------- =
L
1 –
f [ ]
1
2πi
--------- f s v , ( )e
xv
v d
c i ∞ –
c i ∞ +

s
3
sx cos
=
=
imag
2-66
imag
Purpose Symbolic imaginar y par t .
Syntax imag(Z)
Description imag(Z) is t he imaginar y par t of a symbolic Z.
See Also conj, r eal
int
2-67
int
Purpose Int egr at e.
Syntax R = int(S)
R = int(S,v)
R = int(S,a,b)
R = int(S,v,a,b)
Description int(S) r et ur ns t he indefinit e int egr al of S wit h r espect t o it s symbolic var iable
as defined by findsym.
int(S,v) r et ur ns t he indefinit e int egr al of S wit h r espect t o t he symbolic scalar
var iable v.
int(S,a,b) r et ur ns t he definit e int egr al fr om a t o b of each element of S wit h
r espect t o each element ’s default symbolic var iable. a and b ar e symbolic or
double scalar s.
int(S,v,a,b) r et ur ns t he definit e int egr al of S wit h r espect t o v fr om a t o b.
Examples int(–2*x/(1+x^2)^2) r et ur ns
1/(1+x^2)
int(x/(1+z^2),z) r et ur ns
atan(z)*x
int(x*log(1+x),0,1) r et ur ns
1/4
int(2*x, sin(t), 1) r et ur ns
1–sin(t)^2
int([exp(t),exp(alpha*t)]) r et ur ns
[exp(t), 1/alpha*exp(alpha*t)]
See Also diff, symsum
inv
2-68
inv
Purpose Mat r ix inver se.
Syntax R = inv(A)
Description inv(A) r et ur ns inver se of t he symbolic mat r ix A.
Examples The st at ement s
A = sym([2,–1,0;–1,2,–1;0,–1,2]);
inv(A)
r et ur n
[ 3/4, 1/2, 1/4]
[ 1/2, 1, 1/2]
[ 1/4, 1/2, 3/4]
The st at ement s
syms a b c d
A = [a b; c d]
inv(A)
r et ur n
[ d/(a*d–b*c), –b/(a*d–b*c)]
[ –c/(a*d–b*c), a/(a*d–b*c)]
Suppose you have cr eat ed t he following M-file:
%% Generate a symbolic N-by-N Hilbert matrix.
function A = genhilb(N)
syms t;
for i = 1:N
for j = 1:N
A(i,j) = 1/(i + j – t);
end
end
Then, t he following st at ement
inv(genhilb(2))
inv
2-69
r et ur ns
[ –(–3+t)^2*(–2+t), (–3+t)*(–2+t)*(–4+t)]
[(–3+t)*(–2+t)*(–4+t), –(–3+t)^2*(–4+t)]
t he symbolic inver se of t he 2-by-2 Hilber t mat r ix.
See Also vpa
Ar it hmet ic Oper at ions page
iztrans
2-70
izt rans
Purpose Inver se z-t r ansfor m.
Syntax f = iztrans(F)
f = iztrans(F,k)
f = iztrans(F,w,k)
Description f = iztrans(F) is t he inver se z-t r ansfor m of t he scalar symbolic object F wit h
default independent var iable z. The default r et ur n is a funct ion of n:
wher e R is a posit ive number chosen so t hat t he funct ion F(z) is analyt ic on and
out side t he cir cle | z| = R
If F = F(n), iztrans r et ur ns a funct ion of k:
f = iztrans(F,k) makes f a funct ion of k inst ead of t he default n. Her e k is a
scalar symbolic object .
f = iztrans(F,w,k) t akes F t o be a funct ion of w inst ead of t he default
findsym(F) and r et ur ns a funct ion of k:
Examples
f n ( )
1
2πi
--------- F z ( )z
n 1 –
z n 1 2 … , , = , d
z R =

°
=
f f k ( ) =
F F w ( ) = f f k ( ) = ⇒
Inverse Z-Transform MATLAB Operation
f = 2*z/(z–2)^2
iztrans(f)
r et ur ns
2^n*n
f z ( )
2z
z 2 – ( )
2
------------------- =
Z
1 –
f [ ]
1
2πi
--------- f s ( )z
n 1 –
d z
n 2
n
=
z R =

°
=
iztrans
2-71
See Also ifourier, ilaplace, ztrans
g = n*(n+1)/(n^2+2*n+1)
iztrans(g)
r et ur ns
(–1)^k
f = z/(z–a)
iztrans(f,k)
r et ur ns
a^k
f = x*(x–exp(z))/
(x^2–2*x*exp(z)+exp(2*z))
iztrans(f,x,k)
r et ur ns
exp(z)^k
Inverse Z-Transform MATLAB Operation
g n ( )
n n 1 + ( )
n
2
2n 1 + +
----------------------------- - =
Z
1 –
g [ ]
1
2πi
--------- g n ( )n
k 1 –
d n
1
k
– =
n R =

°
=
f z ( )
z
z a –
------------ =
Z
1 –
f [ ]
1
2πi
--------- f z ( )z
k 1 –
d z
a
k
=
z R =

°
=
f x z , ( )
x x e
z
– ( )
x
2
2xe
z
– e
2z
+
-------------------------------------- =
Z
1 –
f [ ]
1
2πi
--------- f x z , ( )x
k 1 –
d x
e
k z
=
x R =

°
=
jacobian
2-72
jacobian
Purpose J acobian mat r ix.
Syntax R = jacobian(w,v)
Description jacobian(w,v) comput es t he J acobian of w wit h r espect t o v. w is a symbolic
scalar expr ession or a symbolic column vect or . v is a symbolic r ow vect or . The
(i,j)-t h ent r y of t he r esult is ∂w(i)/∂v(j).
Examples The st at ement s
w = [x*y*z; y; x+z];
v = [x,y,z];
R = jacobian(w,v)
b = jacobian(x+z, v)
r et ur n
R =
[y*z, x*z, x*y]
[ 0, 1, 0]
[ 1, 0, 1]
b =
[1, 0, 1]
See Also diff
jordan
2-73
jordan
Purpose J or dan canonical for m.
Syntax J = jordan(A)
[V,J] = jordan(A)
Description jordan(A) comput es t he J or dan canonical (nor mal) for m of A, wher e A is a
symbolic or numer ic mat r ix. The mat r ix must be known exact ly. Thus, it s
element s must be int eger s or r at ios of small int eger s. Any er r or s in t he input
mat r ix may complet ely change t he J or dan canonical for m.
[V,J] = jordan(A) comput es bot h J, t he J or dan canonical for m, and t he
similar it y t r ansfor m, V, whose columns ar e t he gener alized eigenvect or s.
Mor eover , V\A*V=J.
Examples The st at ement s
A = [1 –3 –2; –1 1 –1; 2 4 5]
[V,J] = jordan(A)
r et ur n
A =
1 –3 –2
–1 1 –1
2 4 5
V =
[–1, –2, 2]
[ 0, –2, 0]
[ 0, 4, 0]
J =
[3, 0, 0]
[0, 2, 1]
[0, 0, 2]
Then t he st at ement s
V = double(V)
V\A*V
jordan
2-74
r et ur n
V =
–1 –2 2
0 –2 0
1 4 0
ans =
3 0 0
0 2 1
0 0 2
See Also eig, poly
lambertw
2-75
lamber t w
Purpose Lamber t ’s W funct ion.
Syntax Y = lambertw(X)
Description lambertw(X) evaluat es Lamber t ’s W funct ion at t he element s of X, a numer ic
mat r ix or a symbolic mat r ix. Lamber t ’s W solves t he equat ion
for w as a funct ion of x.
Examples lambertw([0 –exp(–1); pi 1]) r et ur ns
0 –1.0000
1.0737 0.5671
The st at ement s
syms x y
lambertw([0 x;1 y])
r et ur n
[ 0, lambertw(x)]
[ lambertw(1), lambertw(y)]
References [1] Cor less, R.M, Gonnet , G.H., Har e, D.E.G., and J effr ey, D.J ., Lambert' s W
Function in Maple, Technical Repor t , Dept . of Applied Mat h., Univ. of West er n
Ont ar io, London, Ont ar io, Canada.
[2] Cor less, R.M, Gonnet , G.H., Har e, D.E.G., and J effr ey, D.J ., On Lambert' s
W Function, Technical Repor t , Dept . of Applied Mat h., Univ. of West er n
Ont ar io, London, Ont ar io, Canada.
Bot h paper s ar e available by anonymous FTP fr om
cs–archive.uwaterloo.ca
we
w
x =
laplace
2-76
laplace
Purpose Laplace t r ansfor m.
Syntax laplace(F)
laplace(F,t)
fourier(F,w,z)
Description L = laplace(F) is t he Laplace t r ansfor m of t he scalar symbol F wit h default
independent var iable t. The default r et ur n is a funct ion of s. The Laplace
t r ansfor m is applied t o a funct ion of t and r et ur ns a funct ion of s.
If F = F(s), laplace r et ur ns a funct ion of t.
By definit ion
wher e t is t he symbolic var iable in F as det er mined by findsym.
L = laplace(F,t) makes L a funct ion of t inst ead of t he default s.
Her e L is r et ur ned as a scalar symbol.
L = laplace(F,w,z) makes L a funct ion of z and F a funct ion of w inst ead of
t he default var iables s and t, r espect ively.
F F t ( ) = L L s ( ) = ⇒
L L t ( ) =
L s ( ) F t ( )e
s t –
t d
0


=
L t ( ) F x ( )e
t x –
x d
0


=
L z ( ) F w ( )e
z w –
w d
0


=
laplace
2-77
Examples
Laplace Transform MATLAB Command
f = t^4
laplace(f)
r et ur ns
24/s^5
g = 1/sqrt(s)
laplace(g)
r et ur ns
1/s^(1/2)*pi^(1/2)
f = exp(–a*t)
laplace(f,x)
r et ur ns
1/(x + a)
f t ( ) t
4
=
L f [ ] f t ( )e
t s –
t d
0


24
s
5
------
=
=
g s ( )
1
s
------ =
L g [ ] t ( ) g s ( )e
s t –
s d
0


π
s
---
=
=
f t ( ) e
a t –
=
L f [ ] x ( ) f t ( )e
t x –
t d
0


1
x a +
------------
=
=
laplace
2-78
See Also fourier, ilaplace, ztrans
f = 1 – cos(t*v)
laplace(f,v,x)
r et ur ns
1/x–x/(x^2+t^2)
Laplace Transform MATLAB Command
f t v , ( ) 1 t v cos – =
L f [ ] x ( ) f t v , ( )e
v x –
v d
0


1
x
---
x
x
2
t
2
+
-----------------
t
2
x
3
xt
2
+
-------------------- = –
=
=
latex
2-79
lat ex
Purpose LaTeX r epr esent at ion of a symbolic expr ession.
Syntax latex(S)
Description latex(S) r et ur ns t he LaTeX r epr esent at ion of t he symbolic expr ession S.
Examples The st at ement s
syms x
f = taylor(log(1+x));
latex(f)
r et ur n
x–1/2\,{x}^{2}+1/3\,{x}^{3}–1/4\,{x}^{4}+1/5\,{x}^{5}
The st at ement s
H = sym(hilb(3));
latex(H)
r et ur n
\left [\begin {array}{ccc} 1&1/2&1/3\\\noalign{\medskip}1/2&1/
3&1/4
\\\noalign{\medskip}1/3&1/4&1/5\end {array}\right ]
The st at ement s
syms alpha t
A = [alpha t alpha*t];
latex(A)
r et ur n
\left [\begin {array}{ccc} \alpha&t&\alpha\,t\end {array}\right ]
See Also pretty, ccode, fortran
limit
2-80
limit
Purpose Limit of a symbolic expr ession.
Syntax limit(F,x,a)
limit(F,a)
limit(F)
limit(F,x,a,'right')
limit(F,x,a,'left')
Description limit(F,x,a) t akes t he limit of t he symbolic expr ession F as x -> a.
limit(F,a) uses findsym(F) as t he independent var iable.
limit(F) uses a = 0 as t he limit point .
limit(F,x,a,'right') or limit(F,x,a,'left') specify t he dir ect ion of a
one-sided limit .
Examples Assume
syms x a t h;
Then
limit(sin(x)/x) => 1
limit(1/x,x,0,'right') => inf
limit(1/x,x,0,'left') => –inf
limit((sin(x+h)–sin(x))/h,h,0) => cos(x)
v = [(1 + a/x)^x, exp(–x)];
limit(v,x,inf,'left') => [exp(a), 0]
See Also pretty, ccode, fortran
maple
2-81
maple
Purpose Access Maple ker nel.
Syntax r = maple('statement')
r = maple('function',arg1,arg2,...)
[r, status] = maple(...)
maple('traceon') or maple trace on
maple('traceoff') or maple trace off
Description maple('statement') sends statement t o t he Maple ker nel and r et ur ns t he
r esult . A semicolon for t he Maple synt ax is appended t o statement if necessar y.
maple('function',arg1,arg2,...) accept s t he quot ed name of any Maple
funct ion and associat ed input ar gument s. The ar gument s ar e conver t ed t o
symbolic expr essions if necessar y, and function is t hen called wit h t he given
ar gument s. If t he input ar gument s ar e syms, t hen maple r et ur ns a sym.
Ot her wise, it r et ur ns a r esult of class char.
[r,status] = maple(...) is an opt ion t hat r et ur ns t he war ning/er r or st at us.
When t he st at ement execut ion is successful, r is t he r esult and status is 0. If
t he execut ion fails, r is t he cor r esponding war ning/er r or message, and status
is a posit ive int eger .
maple('traceon') (or maple trace on) causes all subsequent Maple
st at ement s and r esult s t o be pr int ed. maple('traceoff') (or maple trace
off) t ur ns t his feat ur e off.
Examples Each of t he following st at ement s evaluat e π t o 100 digit s:
maple('evalf(Pi,100)')
maple evalf Pi 100
maple('evalf','Pi',100)
The st at ement
[result,status] = maple('BesselK',4.3)
maple
2-82
r et ur ns t he following out put because Maple’s BesselK funct ion needs t wo input
ar gument s:
result =
Error, (in BesselK) invalid arguments
status =
2
The traceon command shows how Symbolic Mat h Toolbox commands int er act
wit h Maple. For example, t he st at ement s
syms x
v = [x^2–1;x^2–4]
maple traceon % or maple trace on
w = factor(v)
r et ur n
v =
[x^2–1]
[x^2–4]
statement =
map(ifactor,array([[x^2–1],[x^2–4]]));
result =
Error, (in ifactor) invalid arguments
statement =
map(factor,array([[x^2–1],[x^2–4]]));
result =
MATRIX([[(x–1)*(x+1)], [(x–2)*(x+2)]])
w =
[(x–1)*(x+1)]
[(x–2)*(x+2)]
This example r eveals t hat t he factor st at ement fir st invokes Maple’s int eger
fact or (ifactor) st at ement t o det er mine whet her t he ar gument is a fact or able
int eger . If Maple’s int eger fact or st at ement r et ur ns an er r or , t he Symbolic
maple
2-83
Mat h Toolbox factor st at ement t hen invokes Maple’s expr ession fact or ing
st at ement .
See Also mhelp, procread
mapleinit
2-84
mapleinit
Purpose Init ialize t he Maple ker nel.
Syntax mapleinit
Description mapleinit det er mines t he pat h t o t he dir ect or y cont aining t he Maple Libr ar y,
loads t he Maple linear algebr a and int egr al t r ansfor m packages, init ializes
digits, and est ablishes sever al aliases. mapleinit is called by t he MEX-file
int er face t o Maple.
You can edit t he mapleinit M-file t o change t he pat hname t o t he Maple
libr ar y. You do t his by changing t he initstring var iable in mapleinit.m t o t he
full pat hname of t he Maple libr ar y, as descr ibed below.
UNIX. Suppose you alr eady have a copy of t he Libr ar y for Maple V, Release 4
in t he UNIX dir ect or y /usr/local/Maple/lib. You can edit mapleinit.m t o
cont ain
maplelib = '/usr/local/Maple/lib'
and t hen delet e t he copy of t he Maple Libr ar y t hat is dist r ibut ed wit h
MATLAB.
MS-Windows. Suppose you alr eady have a copy of t he Libr ar y for Maple V,
Release 4 in t he dir ect or y C:\MAPLE\LIB. You can edit mapleinit.m t o cont ain
maplelib = 'C:\MAPLE\LIB'
and t hen delet e t he copy of t he Maple Libr ar y t hat is dist r ibut ed wit h
MATLAB.
Macintosh. Suppose you alr eady have a copy of t he Libr ar y for Maple V,
Release 4 in t he dir ect or y MyDisk:Maple:Lib. You can edit mapleinit.m t o
cont ain
maplelib = 'MyDisk:Maple:Lib'
and t hen delet e t he copy of t he Maple Libr ar y t hat is dist r ibut ed wit h
MATLAB.
mfun
2-85
mfun
Purpose Numer ic evaluat ion of Maple mat hemat ical funct ion.
Syntax Y = mfun('function',par1,par2,par3,par4)
Description mfun('function',par1,par2,par3,par4) numer ically evaluat es one of t he
special mat hemat ical funct ions known t o Maple. Each par ar gument is a
numer ic quant it y cor r esponding t o a Maple par amet er for function. You can
use up t o four par amet er s. The last par amet er specified can be a mat r ix,
usually cor r esponding t o X. The dimensions of all ot her par amet er s depend on
t he Maple specificat ions for function. You can access par amet er infor mat ion
for Maple funct ions using one of t he following commands:
help mfunlist
mhelp function
Maple evaluat es function using 16 digit accur acy. Each element of t he r esult
is a MATLAB numer ic quant it y. Any singular it y in function is r et ur ned as
NaN.
Examples mfun('FresnelC',0:5) r et ur ns
0 0.7799 0.4883 0.6057 0.4984 0.5636
mfun('Chi',[3*i 0]) r et ur ns
0.1196 + 1.5708i NaN
See Also mfunlist, mhelp
mfunlist
2-86
mfunlist
Purpose List special funct ions for use wit h mfun.
Syntax mfunlist % help mfunlist on the Macintosh
Description mfunlist list s t he special mat hemat ical funct ions for use wit h t he mfun
funct ion. The following t ables descr ibe t hese special funct ions.
You can access mor e det ailed descr ipt ions by t yping
mhelp function
Limitations In gener al, t he accur acy of a funct ion will be lower near it s r oot s and when it s
ar gument s ar e r elat ively lar ge.
Runt ime depends on t he specific funct ion and it s par amet er s. In gener al,
calculat ions ar e slower t han st andar d MATLAB calculat ions.
See Also mfun, mhelp
References [1] Abr amowit z, M. and St egun, I.A., Handbook of Mathematical Functions ,
Dover Publicat ions, 1965.
Table
Conventions
The following convent ions ar e used in Table 2-1: MFUN Special Funct ions,
unless ot her wise indicat ed in t he Arguments column:
x, y r eal ar gument
z , z1, z2 complex ar gument
m , n int eger ar gument
mfunlist
2-87
Table 2-1: MFUN Special Functions
Function Name Definition mfun Name Arguments
Ber noulli Number s
and Polynomials
Gener at ing funct ions: bernoulli(n)
bernoulli(n,t)
n ≥ 0
Bessel Funct ions BesselI, BesselJ – Bessel funct ions
of t he fir st kind.
BesselK, BesselY – Bessel funct ions
of t he second kind.
BesselJ(v,x)
BesselY(v,x)
BesselI(v,x)
BesselK(v,x)
v is r eal.
Bet a Funct ion Beta(x,y)
Binomial Coefficient s binomial(m,n)
Complet e Ellipt ic
Int egr als
Legendr e ’s complet e ellipt ic int egr als
of t he fir st , second, and t hir d kind.
LegendreKc(k)
LegendreEc(k)
LegendrePic(a,k)
a is r eal
–Inf < a < Inf
k is r eal
0 < k < 1
e
xt
e
t
1 –
------------- B
n
x ( )
t
n 1 –
n!
------------ ⋅
n 0 =


=
0 t 2π < <
B x y , ( )
Γ x ( ) Γ y ( ) ⋅
Γ x y + ( )
---------------------------- =
m
n . ,
| `
m!
n! m n – ( )!
--------------------------- =
Γ m 1 + ( )
Γ n 1 + ( )Γ m n 1 + – ( )
-------------------------------------------------------- =
mfunlist
2-88
Complet e Ellipt ic
Int egr als wit h
Complement ar y
Modulus
Associat ed complet e ellipt ic int egr als
of t he fir st , second, and t hir d kind
using complement ar y modulus.
LegendreKc1(k)
LegendreEc1(k)
LegendrePic1(a,k)
a is r eal
–Inf < a < Inf
k is r eal
0 < k < 1
Complement ar y Er r or
Funct ion and It s
It er at ed Int egr als
erfc(z)
erfc(n,z)
n > 0
Dawson’s Int egr al dawson(x)
Digamma Funct ion Psi(x)
Table 2-1: MFUN Special Functions (Continued)
Function Name Definition mfun Name Arguments
er f c z ( )
2
π
------- e
t –
2
t 1 er f z ( ) – = d
z


⋅ =
er f c 1 z , – ( )
2
π
------- e
z –
2
⋅ =
er f c n z , ( ) erf c n 1 – z , ( ) t d
z


=
F x ( ) e
x
2

e
t
2

t d
0
x

⋅ =
ψ x ( )
x d
d
Γ x ( ) ( ) ln
Γ′ x ( )
Γ x ( )
------------- = =
mfunlist
2-89
Dilogar it hm Int egr al dilog(x) x > 1
Er r or Funct ion erf(z)
Euler Number s and
Polynomials
Gener at ing funct ion for Euler
number s:
euler(n)
euler(n,z)
Exponent ial Int egr als Ei(n,z)
Ei(x)
n ≥ 0
Real(z) > 0
Table 2-1: MFUN Special Functions (Continued)
Function Name Definition mfun Name Arguments
f x ( )
t ( ) ln
1 t –
------------- t d
1
x

=
er f z ( )
2
π
------- e
t –
2
t d
0
z

=
1
ch t ( )
------------- - E
n
t
n
n!
-----
n 0 =


=
n 0 ≥
t
π
2
--- <
Ei n z , ( )
e
z t –
t
n
--------- t d
1


=
Ei x ( ) PV
e
t
t
----
∞ –
x

– =
mfunlist
2-90
Fr esnel Sine and
Cosine Int egr als
FresnelC(x)
FresnelS(x)
Gamma Funct ion GAMMA(z)
Har monic Funct ion harmonic(n) n > 0
Hyper bolic Sine and
Cosine Int egr als
Shi(z)
Chi(z)
Table 2-1: MFUN Special Functions (Continued)
Function Name Definition mfun Name Arguments
C x ( )
π
2
--- t
2

. ,
| `
cos t d
0
x

=
S x ( )
π
2
--- t
2

. ,
| `
sin t d
0
x

=
Γ z ( ) t
z 1 –
e
t –
t d
0


=
h n ( )
1
k
---
k 1 =
n

ψ n 1 + ( ) γ + = =
S h i z ( )
t ( ) sinh
t
------------------- t d
0
z

=
Ch i z ( ) γ z ( ) ln
t ( ) cosh 1 –
t
----------------------------- t d
0
z

+ + =
mfunlist
2-91
(Gener alized)
Hyper geomet r ic
Funct ion
wher e j and m ar e t he number of
t er ms in n and d, r espect ively.
hypergeom(n,d,x)
wher e
n = [n1,n2,...]
d = [d1,d2,...]
n1,n2,... ar e
r eal.
d1,d2,... ar e
r eal and
non-negat ive.
Incomplet e Ellipt ic
Int egr als
Legendr e's incomplet e ellipt ic
int egr als of t he fir st , second, and
t hir d kind.
LegendreF(x,k)
LegendreE(x,k)
LegendrePi(x,a,k)
0 < x ≤ Inf
a is r eal
–Inf < a < Inf
k is r eal
0 < k < 1
Incomplet e Gamma
Funct ion
GAMMA(z1,z2)
Logar it hm of t he
Gamma Funct ion
lnGAMMA(z)
Table 2-1: MFUN Special Functions (Continued)
Function Name Definition mfun Name Arguments
F n d z , , ( )
Γ n
i
k + ( )
Γ n
i
( )
----------------------- - z
k

i 1 =
j

Γ d
i
k + ( )
Γ d
i
( )
------------------------ k! ⋅
i 1 =
m

---------------------------------------------
k 0 =


=
Γ a z , ( ) e
t –
t
a 1 –
⋅ t d
z


=
Γ z ( ) ln Γ z ( ) ( ) ln =
mfunlist
2-92
Logar it hmic Int egr al Li(x) x > 1
Polygamma Funct ion
wher e is t he Digamma funct ion.
Psi(n,z) n ≥ 0
Shift ed Sine Int egr al Ssi(z)
Table 2-1: MFUN Special Functions (Continued)
Function Name Definition mfun Name Arguments
L i x ( ) PV
t d
t ln
--------
0
x

¹ ¹
¹ ¹
' '
¹ ¹
¹ ¹
Ei x ln ( ) = =
ψ
n ( )
z ( )
z
n
d
d
ψ z ( ) =
ψ z ( )
S s i z ( ) S i z ( )
π
2
--- – =
mfunlist
2-93
Orthogonal
Polynomials
The following funct ions r equir e t he Maple Or t hogonal Polynomial Package.
They ar e available only wit h t he Ext ended Symbolic Mat h Toolbox. Befor e
using t hese funct ions, you must fir st init ialize t he Or t hogonal Polynomial
Package by t yping
maple('with','orthopoly')
Not e t hat in all cases, n is a non-negat ive int eger and x is r eal.
Table 2-2: Orthogonal Polynomials
Polynomial Maple Name Arguments
Gegenbauer G(n,a,x) a is a nonr at ional algebr aic
expr ession or a r at ional number
gr eat er t han –1/2.
Her mit e H(n,x)
Laguer r e L(n,x)
Gener alized
Laguer r e
L(n,a,x) a is a nonr at ional algebr aic
expr ession or a r at ional number
gr eat er t han –1.
Legendr e P(n,x)
J acobi P(n,a,b,x) a, b ar e nonr at ional algebr aic
expr essions or r at ional number s
gr eat er t han –1.
Chebyshev of
t he Fir st and
Second Kind
T(n,x)
U(n,x)
mhelp
2-94
mhelp
Purpose Maple help.
Syntax mhelp topic
mhelp('topic')
Description mhelp topic and mhelp('topic') bot h r et ur n Maple’s online document at ion
for t he specified Maple topic.
Examples mhelp BesselI and mhelp('BesselI') bot h r et ur n Maple’s online
document at ion for t he Maple BesselI funct ion.
See Also maple
null
2-95
null
Purpose Basis for null space.
Syntax Z = null(A)
Description The columns of Z = null(A) for m a basis for t he null space of A.
size(Z,2) is t he nullit y of A.
A*Z is zer o.
If A has full r ank, Z is empt y.
Examples The st at ement s
A = sym(magic(4));
Z = null(A)
A*Z
r et ur n
[ –1]
[ –3]
[ 3]
[ 1]
[ 0]
[ 0]
[ 0]
[ 0]
See Also ar it hmet ic oper at or s, colspace, rank, rref, svd
null in t he online MATLAB Funct ion Refer ence.
numden
2-96
numden
Purpose Numer at or and denominat or .
Syntax [N,D] = numden(A)
Description [N,D] = numden(A) conver t s each element of A t o a r at ional for m wher e t he
numer at or and denominat or ar e r elat ively pr ime polynomials wit h int eger
coefficient s. A is a symbolic or a numer ic mat r ix. N is t he symbolic mat r ix of
numer at or s, and D is t he symbolic mat r ix of denominat or s.
Examples [n,d] = numden(4/5) r et ur ns n = 4 and d = 5.
[n,d] = numden(x/y + y/x) r et ur ns
n =
x^2+y^2
d =
y*x
The st at ement s
A = [a, 1/b]
[n,d] = numden(A)
r et ur n
A =
[a, 1/b]

n =
[a, 1]
d =
[1, b]
poly
2-97
poly
Purpose Char act er ist ic polynomial of a mat r ix.
Syntax p = poly(A)
p = poly(A, v)
Description If A is a numer ic ar r ay, poly(A) r et ur ns t he coefficient s of t he char act er ist ic
polynomial of A. If A is symbolic, poly(A) r et ur ns t he char act er ist ic polynomial
of A in t er ms of t he default var iable x. The var iable v can be specified in t he
second input ar gument .
Not e t hat if A is numer ic, poly(sym(A)) appr oximat ely equals
poly2sym(poly(A)). The appr oximat ion is due t o r oundoff er r or .
Examples The st at ement s
A = gallery(3)
p = poly(A)
q = poly(sym(A))
s = poly(sym(A),z)
r et ur n
A =
–149 –50 –154
537 180 546
–27 –9 –25
p =
1.0000 –6.0000 11.0000 –6.0000
q=
x^3–6*x^2+11*x–6
s =

z^3–6*z^2+11*z–6
See Also poly2sym, jordan, eig, solve
poly2sym
2-98
poly2sym
Purpose Polynomial coefficient vect or t o symbolic polynomial.
Syntax r = poly2sym(c)
r = poly2sym(c, v)
Description r = poly2sym(c) r et ur ns a symbolic r epr esent at ion of t he polynomial whose
coefficient s ar e in t he numer ic vect or c. The default symbolic var iable is x. The
var iable v can be specified as a second input ar gument . If c = [c1 c2 ... cn],
r=poly2sym(c) has t he for m:
poly2sym uses sym’s default (r at ional) conver sion mode t o conver t t he numer ic
coefficient s t o symbolic const ant s. This mode expr esses t he symbolic coefficient
appr oximat ely as a r at io of int eger s, if sym can find a simple r at io t hat
appr oximat es t he numer ic value, ot her wise as an int eger mult iplied by a power
of 2.
If x has a numer ic value and sym expr esses t he element s of c exact ly,
eval(poly2sym(c)) r et ur ns t he same value as polyval(c,x).
Examples poly2sym([1 3 2]) r et ur ns
x^2 + 3*x + 2
poly2sym([.694228, .333, 6.2832]) r et ur ns
6253049924220329/9007199254740992*x^2+333/1000*x+3927/625
poly2sym([1 0 1 –1 2], y) r et ur ns
y^4+y^2–y+2
See Also sym, sym2poly
polyval in t he online MATLAB Funct ion Refer ence
c
1
x
n 1 –
c
2
x
n 2 –
… c
n
+ + +
pretty
2-99
pr et t y
Purpose Pr et t ypr int symbolic expr essions.
Syntax pretty(S)
pretty(S,n)
Description The pretty funct ion pr int s symbolic out put in a for mat t hat r esembles t ypeset
mat hemat ics.
pretty(S) pr et t ypr int s t he symbolic mat r ix S using t he default line widt h of
79.
pretty(S,n) pr et t ypr int s S using line widt h n inst ead of 79.
Examples The following st at ement s:
A = sym(pascal(2))
B = eig(A)
pretty(B)
r et ur n
A =
[1, 1]
[1, 2]
B =
[3/2+1/2*5^(1/2)]
[3/2–1/2*5^(1/2)]
[ 1/2 ]
[ 3/2 + 1/2 5 ]
[ ]
[ 1/2 ]
[ 3/2 – 1/2 5 ]
procread
2-100
pr ocread
Purpose Inst all a Maple pr ocedur e.
Syntax procread('filename')
Description procread('filename') r eads t he specified file, which should cont ain t he sour ce
t ext for a Maple pr ocedur e. It delet es any comment s and newline char act er s,
t hen sends t he r esult ing st r ing t o Maple.
The Ext ended Symbolic Mat h Toolbox is r equir ed.
Examples Suppose t he file ident.src cont ains t he following sour ce t ext for a Maple
pr ocedur e.
ident := proc(A)
# ident(A) computes A*inverse(A)
local X;
X := inverse(A);
evalm(A &* X);
end;
Then t he st at ement
procread('ident.src')
inst alls t he pr ocedur e. It can be accessed wit h
maple('ident',magic(3))
or
maple('ident',vpa(magic(3)))
See Also maple
rank
2-101
r ank
Purpose Symbolic mat r ix r ank.
Syntax rank(A)
Description rank(A) is t he r ank of t he symbolic mat r ix A.
Examples rank([a b;c d]) is 2.
rank(sym(magic(4))) is 3.
real
2-102
r eal
Purpose Symbolic r eal par t .
Syntax real(Z)
Description real(Z) is t he r eal par t of a symbolic Z.
See Also conj, imag
rref
2-103
r r ef
Purpose Reduced r ow echelon for m.
Syntax rref(A)
Description rref(A) is t he r educed r ow echelon for m of t he symbolic mat r ix A.
Examples rref(sym(magic(4))) r et ur ns
[ 1, 0, 0, 1]
[ 0, 1, 0, 3]
[ 0, 0, 1, –3]
[ 0, 0, 0, 0]
rsums
2-104
r sums
Purpose Int er act ive evaluat ion of Riemann sums.
Syntax rsums(f)
Description rsums(f) int er act ively appr oximat es t he int egr al of f (x) by Riemann sums.
rsums(f) displays a gr aph of f(x). You can t hen adjust t he number of t er ms
t aken in t he Riemann sum by using t he slider below t he gr aph. The number of
t er ms available r anges fr om 2 t o 256.
Examples rsums exp(–5*x^2) cr eat es t he following plot
simple
2-105
simple
Purpose Sear ch for a symbolic expr ession’s simplest for m.
Syntax r = simple(S)
[r,how] = simple(S)
Description simple(S) t r ies sever al differ ent algebr aic simplificat ions of t he symbolic
expr ession S, displays any t hat shor t en t he lengt h of S’s r epr esent at ion, and
r et ur ns t he shor t est . S is a sym. If S is a mat r ix, t he r esult r epr esent s t he
shor t est r epr esent at ion of t he ent ir e mat r ix, which is not necessar ily t he
shor t est r epr esent at ion of each individual element . If no r et ur n out put is given,
simple(S) displays all possible r epr esent at ions and r et ur ns t he shor t est .
[r,how] = simple(S) does not display int er mediat e simplificat ions, but
r et ur ns t he shor t est found, as well as a st r ing descr ibing t he par t icular
simplificat ion. r is a sym. how is a st r ing.
Examples
See Also collect, expand, factor, horner, simplify
Expression Simplification Simplification Method
cos(x)^2+sin(x)^2 1 simplify
2*cos(x)^2–sin(x)^2 3*cos(x)^2–1 simplify
cos(x)^2–sin(x)^2 cos(2*x) combine(trig)
cos(x)+
(–sin(x)^2)^(1/2)
cos(x)+i*sin(x) radsimp
cos(x)+i*sin(x) exp(i*x) convert(exp)
(x+1)*x*(x–1) x^3–x collect(x)
x^3+3*x^2+3*x+1 (x+1)^3 factor
cos(3*acos(x)) 4*x^3–3*x expand
simplify
2-106
simplify
Purpose Symbolic simplificat ion.
Syntax R = simplify(S)
Description simplify(S) simplifies each element of t he symbolic mat r ix S using Maple
simplificat ion r ules.
Examples simplify(sin(x)^2 + cos(x)^2) r et ur ns
1
simplify(exp(c*log(sqrt(a+b)))) r et ur ns
(a+b)^(1/2*c)
The st at ement s
S = [(x^2+5*x+6)/(x+2),sqrt(16)];
R = simplify(S)
r et ur n
R = [x+3,4]
See Also collect, expand, factor, horner, simple
sinint
2-107
sinint
Purpose Sine int egr al funct ion.
Syntax Y = sinint(X)
Description sinint(X) evaluat es t he sine int egr al funct ion at t he element s of X, a numer ic
mat r ix, or a symbolic mat r ix. The r esult is a numer ic mat r ix. The sine int egr al
funct ion is defined by
Examples sinint([pi 0;–2.2 exp(3)]) r et ur ns
1.8519 0
–1.6876 1.5522
sinint(1.2) r et ur ns 1.1080.
diff(sinint(x)) r et ur ns sin(x)/x.
See Also cosint
S i x ( )
t sin
t
----------- t d
0
x

=
size
2-108
size
Purpose Symbolic mat r ix dimensions.
Syntax d = size(A)
[m,n] = size(A)
d= size(A, n)
Description Suppose A is an m-by-n symbolic or numer ic mat r ix. The st at ement
d = size(A) r et ur ns a numer ic vect or wit h t wo int eger component s, d = [m,n].
The mult iple assignment st at ement [m,n] = size(A) r et ur ns t he t wo int eger s
in t wo separ at e var iables.
The st at ement d = size(A,n) r et ur ns t he lengt h of t he dimension specified by
t he scalar n. For example, size(A,1) is t he number of r ows of A and size(A,2)
is t he number of columns of A.
Examples The st at ement s
syms a b c d
A = [a b c ; a b d; d c b; c b a];
d = size(A)
r = size(A, 2)
r et ur n
d =
4 3
r =
3
See Also length, ndims in t he online MATLAB Funct ion Refer ence
solve
2-109
solve
Purpose Symbolic solut ion of algebr aic equat ions.
Syntax g = solve(eq)
g = solve(eq,var)
g = solve(eq1,eq2,...,eqn)
g = solve(eq1,eq2,...,eqn,var1,var2,...,varn)
Description Single Equation/Expression. The input t o solve can be eit her symbolic
expr essions or st r ings. If eq is a symbolic expr ession (x^2–2*x+1) or a st r ing
t hat does not cont ain an equal sign ('x^2–2*x+1'), t hen solve(eq) solves t he
equat ion eq=0 for it s default var iable (as det er mined by findsym).
solve(eq,var) solves t he equat ion eq (or eq=0 in t he t wo cases cit ed above) for
t he var iable var.
System of Equations. The input s ar e eit her symbolic expr essions or st r ings
specifying equat ions. solve(eq1,eq2,...,eqn) solves t he syst em of equat ions
implied by eq1,eq2,...,eqn in t he n var iables det er mined by applying
findsym t o t he syst em.
Thr ee differ ent t ypes of out put ar e possible. For one equat ion and one out put ,
t he r esult ing solut ion is r et ur ned wit h mult iple solut ions for a nonlinear
equat ion. For a syst em of equat ions and an equal number of out put s, t he
r esult s ar e sor t ed alphabet ically and assigned t o t he out put s. For a syst em of
equat ions and a single out put , a st r uct ur e cont aining t he solut ions is r et ur ned.
For bot h a single equat ion and a syst em of equat ions, numer ic solut ions ar e
r et ur ned if symbolic solut ions cannot be det er mined.
Examples solve('a*x^2 + b*x + c') r et ur ns
[ 1/2/a*(–b+(b^2–4*a*c)^(1/2)),
1/2/a*(–b–(b^2–4*a*c)^(1/2))]
solve('a*x^2 + b*x + c','b') r et ur ns
–(a*x^2+c)/x
solve('x + y = 1','x – 11*y = 5') r et ur ns
y = –1/3, x = 4/3
solve
2-110
A = solve('a*u^2 + v^2', 'u – v = 1', 'a^2 – 5*a + 6')
r et ur ns
A =
a: [1x4 sym]
u: [1x4 sym]
v: [1x4 sym]
wher e
A.a =
[ 2, 2, 3, 3]
A.u =
[ 1/3+1/3*i*2^(1/2), 1/3–1/3*i*2^(1/2),
1/4+1/4*i*3^(1/2), 1/4–1/4*i*3^(1/2)]
A.v =
[ –2/3+1/3*i*2^(1/2), –2/3–1/3*i*2^(1/2),
–3/4+1/4*i*3^(1/2), –3/4–1/4*i*3^(1/2)]
See Also arithmetic operators, dsolve, findsym
subexpr
2-111
subexpr
Purpose Rewr it e a symbolic expr ession in t er ms of common subexpr essions.
Syntax [Y,SIGMA] = subexpr(X,SIGMA)
[Y,SIGMA] = subexpr(X,'SIGMA')
Description [Y,SIGMA] = subexpr(X,SIGMA) or [Y,SIGMA] = subexpr(X,'SIGMA')
r ewr it es t he symbolic expr ession X in t er ms of it s common subexpr essions.
These ar e t he subexpr essions t hat ar e wr it t en as %1, %2, et c. by pretty(S).
Examples The st at ement s
t = solve('a*x^3+b*x^2+c*x+d = 0');
[r,s] = subexpr(t,'s');
r et ur n t he r ewr it t en expr ession for t in r in t er ms of a common subexpr ession,
which is r et ur ned in s.
See Also pretty, simple, subs
subs
2-112
subs
Purpose Symbolic subst it ut ion in a symbolic expr ession or mat r ix.
Syntax R = subs(S)
R = subs(S,old,new)
Description subs(S) r eplaces all occur r ences of var iables in t he symbolic expr ession S wit h
values obt ained fr om t he calling funct ion, or t he MATLAB wor kspace.
subs(S,old,new) r eplaces old wit h new in t he symbolic expr ession S. old is a
symbolic var iable or a st r ing r epr esent ing a var iable name. new is a symbolic
or numer ic var iable or expr ession.
If old and new ar e cell ar r ays of t he same size, each element of old is r eplaced
by t he cor r esponding element of new. If S and old ar e scalar s and new is an
ar r ay or cell ar r ay, t he scalar s ar e expanded t o pr oduce an ar r ay r esult . If new
is a cell ar r ay of numer ic mat r ices, t he subst it ut ions ar e per for med
element wise (i.e., subs(x*y,{x,y},{A,B}) r et ur ns A.*B when A and B ar e
numer ic).
If subs(s,old,new) does not change s, subs(s,new,old)is t r ied. This pr ovides
backwar ds compat ibilit y wit h pr evious ver sions and eliminat es t he need t o
r emember t he or der of t he ar gument s. subs(s,old,new) does not swit ch t he
ar gument s if s does not change.
Examples Single input:
Suppose a = 980 and C1 = 3 exist in t he wor kspace.
The st at ement
y = dsolve('Dy = -a*y')
pr oduces
y = exp(-a*t)*C1
Then t he st at ement
subs(y)
pr oduces
ans = 3*exp(-980*t)
subs
2-113
Single Substitution:
subs(a+b,a,4) r et ur ns 4+b.
Multiple Substitutions:
subs(cos(a)+sin(b),{a,b},{sym('alpha'),2}) r et ur ns
cos(alpha)+sin(2)
Scalar Expansion Case:
subs(exp(a*t),'a',-magic(2)) r et ur ns
[ exp(-t), exp(-3*t)]
[ exp(-4*t), exp(-2*t)]
Multiple Scalar Expansion:
subs(x*y,{x,y},{[0 1;-1 0],[1 -1;-2 1]}) r et ur ns
[ 0, -1]
[ 2, 0]
See Also simplify, subexpr
svd
2-114
svd
Purpose Symbolic singular value decomposit ion.
Syntax sigma = svd(A)
sigma = svd(vpa(A))
[U,S,V] = svd(A)
[U,S,V] = svd(vpa(A))
Description sigma = svd(A) is a symbolic vect or cont aining t he singular values of a
symbolic mat r ix A.
sigma = svd(vpa(A)) comput es numer ic singular values, using var iable
pr ecision ar it hmet ic.
[U,S,V] = svd(A) and [U,S,V] = svd(vpa(A)) r et ur n numer ic unit ar y
mat r ices U and V whose columns ar e t he singular vect or s and a diagonal mat r ix
S cont aining t he singular values. Toget her , t hey sat isfy A = U*S*V'.
Symbolic singular vect or s ar e not available.
Examples The st at ement s
digits(3)
A = sym(magic(4));
svd(A)
svd(vpa(A))
[U,S,V] = svd(A)
r et ur n
[ 0]
[ 34]
[ 2*5^(1/2)]
[ 8*5^(1/2)]
[ .311e–6*i]
[ 4.47]
[ 17.9]
[ 34.1]
svd
2-115
U =

[ –.500, .671, .500, –.224]
[ –.500, –.224, –.500, –.671]
[ –.500, .224, –.500, .671]
[ –.500, –.671, .500, .224]


S =

[ 34.0, 0, 0, 0]
[ 0, 17.9, 0, 0]
[ 0, 0, 4.47, 0]
[ 0, 0, 0, .835e–15]


V =

[ –.500, .500, .671, –.224]
[ –.500, –.500, –.224, –.671]
[ –.500, –.500, .224, .671]
[ –.500, .500, –.671, .224]
See Also digits, eig, vpa
sym
2-116
sym
Purpose Const r uct symbolic number s, var iables and object s.
Syntax S = sym(A)
x = sym('x')
x = sym('x','real')
x = sym('x','unreal')
S = sym(A,flag) wher e flag is one of 'r', 'd', 'e', or 'f'.
Description S = sym(A) const r uct s an object S, of class 'sym', fr om A. If t he input ar gument
is a st r ing, t he r esult is a symbolic number or var iable. If t he input ar gument
is a numer ic scalar or mat r ix, t he r esult is a symbolic r epr esent at ion of t he
given numer ic values.
x = sym('x') cr eat es t he symbolic var iable wit h name 'x' and st or es t he
r esult in x. x = sym('x','real') also assumes t hat x is r eal, so t hat conj(x)
is equal t o x. alpha = sym('alpha') and r = sym('Rho','real') ar e ot her
examples. x = sym('x','unreal') makes x a pur ely for mal var iable wit h no
addit ional pr oper t ies (i.e., ensur es t hat x is not r eal). See also t he r efer ence
pages on syms.
St at ement s like pi = sym('pi') and delta = sym('1/10') cr eat e symbolic
number s t hat avoid t he float ing-point appr oximat ions inher ent in t he values of
pi and 1/10. The pi cr eat ed in t his way t empor ar ily r eplaces t he built -in
numer ic funct ion wit h t he same name.
S = sym(A,flag) conver t s a numer ic scalar or mat r ix t o symbolic for m. The
t echnique for conver t ing float ing-point number s is specified by t he opt ional
second ar gument , which can be 'f', 'r', 'e' or 'd'. The default is 'r'.
'f' st ands for “float ing-point .” All values ar e r epr esent ed in t he for m
'1.F'*2^(e) or '–1.F'*2^(e) wher e F is a st r ing of 13 hexadecimal digit s and
e is an int eger . This capt ur es t he float ing-point values exact ly, but may not be
convenient for subsequent manipulat ion. For example, sym(1/10,'f') is
'1.999999999999a'*2^(–4) because 1/10 cannot be r epr esent ed exact ly in
float ing-point .
'r' st ands for “r at ional.” Float ing-point number s obt ained by evaluat ing
expr essions of t he for m p/q, p*pi/q, sqrt(p), 2^q, and 10^q for modest sized
int eger s p and q ar e conver t ed t o t he cor r esponding symbolic for m. This
effect ively compensat es for t he r oundoff er r or involved in t he or iginal
sym
2-117
evaluat ion, but may not r epr esent t he float ing-point value pr ecisely. If no
simple r at ional appr oximat ion can be found, an expr ession of t he for m p*2^q
wit h lar ge int eger s p and q r epr oduces t he float ing-point value exact ly. For
example, sym(4/3,'r') is '4/3', but sym(1+sqrt(5),'r') is
7286977268806824*2^(–51)
'e' st ands for “est imat e er r or .” The 'r' for m is supplement ed by a t er m
involving t he var iable 'eps', which est imat es t he differ ence bet ween t he
t heor et ical r at ional expr ession and it s act ual float ing-point value. For
example, sym(3*pi/4) is 3*pi/4–103*eps/249.
'd' st ands for “decimal.” The number of digit s is t aken fr om t he cur r ent set t ing
of digits used by vpa. Fewer t han 16 digit s loses some accur acy, while mor e
t han 16 digit s may not be war r ant ed. For example, wit h digits(10),
sym(4/3,'d') is 1.333333333, while wit h digit s digits(20), sym(4/3,'d') is
1.3333333333333332593, which does not end in a st r ing of 3's, but is an
accur at e decimal r epr esent at ion of t he float ing-point number near est t o 4/3.
See Also digits, double, syms
eps in t he online MATLAB Funct ion Refer ence
syms
2-118
syms
Purpose Shor t -cut for const r uct ing symbolic object s.
Syntax syms arg1 arg2 ...
syms arg1 arg2 ... real
syms arg1 arg2 ... unreal
Description syms arg1 arg2 ... is shor t -hand not at ion for
arg1 = sym('arg1');
arg2 = sym('arg2'); ...
syms arg1 arg2 ... real is shor t -hand not at ion for
arg1 = sym('arg1','real');
arg2 = sym('arg2','real'); ...
syms arg1 arg2 ... unreal is shor t -hand not at ion for
arg1 = sym('arg1','unreal');
arg2 = sym('arg2','unreal'); ...
Each input ar gument must begin wit h a let t er and can cont ain only
alphanumer ic char act er s.
Examples syms x beta real is equivalent t o:
x = sym('x','real');
beta = sym('beta','real');
To clear t he symbolic object s x and beta of 'real' st at us, t ype
syms x beta unreal
Note clear x will not clear t he symbolic object x of it s st at us 'real'. You can
achieve t his, using t he commands syms x unreal or clear mex or clear all.
In t he lat t er t wo cases, t he Maple ker nel will have t o be r eloaded in t he
MATLAB wor kspace. (This is inefficient and t ime consuming).
See Also sym
sym2poly
2-119
sym2poly
Purpose Symbolic-t o-numer ic polynomial conver sion.
Syntax c = sym2poly(s)
Description sym2poly r et ur ns a r ow vect or cont aining t he numer ic coefficient s of a symbolic
polynomial. The coefficient s ar e or der ed in descending power s of t he
polynomial’s independent var iable. In ot her wor ds, t he vect or ’s fir st ent r y
cont ains t he coefficient of t he polynomial’s highest t er m; t he second ent r y, t he
coefficient of t he second highest t er m; and so on.
Examples The commands
syms x u v;
sym2poly(x^3 – 2*x – 5)
r et ur n
1 0 –2 –5
while sym2poly(u^4 – 3 + 5*u^2) r et ur ns
1 0 5 0 –3
and sym2poly(sin(pi/6)*v + exp(1)*v^2) r et ur ns
2.7183 0.5000 0
See Also poly2sym
polyval in t he online MATLAB Funct ion Refer ence
symsum
2-120
symsum
Purpose Symbolic summat ion.
Syntax r = symsum(s)
r = symsum(s,v)
r = symsum(s,a,b)
r = symsum(s,v,a,b)
Description symsum(s) is t he summat ion of t he symbolic expr ession s wit h r espect t o it s
symbolic var iable k as det er mined by findsym fr om 0 t o k–1.
symsum(s,v) is t he summat ion of t he symbolic expr ession s wit h r espect t o t he
symbolic var iable v fr om 0 t o v–1.
symsum(s,a,b) and symsum(s,v,a,b) ar e t he definit e summat ions of t he
symbolic expr ession fr om v=a t o v=b.
Examples The commands
syms k n x
symsum(k^z)
r et ur n
1/3*k^3–1/2*k^2+1/6*k
symsum(k) r et ur ns
1/2*k^2–1/2*k
symsum(sin(k*pi)/k,0,n) r et ur ns
–1/2*sin(k*(n+1))/k+1/2*sin(k)/k/(cos(k)–1)*cos(k*(n+1))–
1/2*sin(k)/k/(cos(k)–1)
symsum(k^2,0,10) r et ur ns
385
symsum(x^k/sym(‘k!'), k, 0,inf) r et ur ns
exp(x)
symsum
2-121
Note The pr eceding example uses sym t o cr eat e t he symbolic expr ession
k! in or der t o bypass MATLAB’s expr ession par ser, which does not r ecognize
! as a fact or ial oper at or.
See Also findsym, int, syms
taylor
2-122
t aylor
Purpose Taylor ser ies expansion.
Syntax r = taylor(f)
r = taylor(f,n,v)
r = taylor(f,n,v,a)
Description taylor(f,n,v) r et ur ns t he (n–1)-or der Maclaur in polynomial appr oximat ion
t o f, wher e f is a symbolic expr ession r epr esent ing a funct ion and v specifies
t he independent var iable in t he expr ession. v can be a st r ing or symbolic
var iable.
taylor(f,n,v,a) r et ur ns t he Taylor ser ies appr oximat ion t o f about a. The
ar gument a can be a numer ic value, a symbol, or a st r ing r epr esent ing a
numer ic value or an unknown.
You can supply t he ar gument s n, v, and a in any or der . taylor det er mines t he
pur pose of t he ar gument s fr om t heir posit ion and t ype.
You can also omit any of t he ar gument s n, v, and a. If you do not specify v,
taylor uses findsym t o det er mine t he funct ion’s independent var iable. n
default s t o 6.
The Taylor ser ies for an analyt ic funct ion f(x) about t he basepoint x=a is given
below.
Examples This t able descr ibes t he var ious uses of t he taylor command and it s r elat ion
t o Taylor and MacLaur in ser ies.
f x ( ) x a – ( )
n f
n ( )
a ( )
n!
----------------- ⋅
n 0 =


=
Mathematical Operation MATLAB
syms x
taylor(f)
x
n f
n ( )
0 ( )
n!
----------------- ⋅
n 0 =
5

taylor
2-123
In t he case wher e f is a funct ion of t wo or mor e var iables (f=f(x,y,...)), t her e
is a four t h par amet er t hat allows you t o select t he var iable for t he Taylor
expansion. Look at t his t able for illust r at ions of t his feat ur e.
, m is a posit ive int eger
taylor(f,m)
m is a posit ive int eger
, a is a r eal number
taylor(f,a)
a is a r eal number
m
1
, m
2
ar e posit ive int eger s
taylor(f,m1,m2)
m
1
, m
2
ar e posit ive int eger s
a is r eal and m is a posit ive int eger
taylor(f,m,a)
a is r eal and m is a posit ive
int eger
Mathematical Operation MATLAB
taylor(f,y)
Mathematical Operation MATLAB
x
n f
n ( )
0 ( )
n!
----------------- ⋅
n 0 =
m

x a – ( )
n f
n ( )
a ( )
n!
----------------- ⋅
n 0 =
5

x m
2
– ( )
n
f
n ( )
m
2
( )
n!
---------------------- ⋅
n 0 =
m
1

x a – ( )
n f
n ( )
a ( )
n!
----------------- ⋅
n 0 =
m

y
n
n!
------
y
n
n


f x y 0 = , ( ) ⋅
n 0 =
5

taylor
2-124
See Also findsym
m is a posit ive int eger
taylor(f,y,m) or
taylor(f,m,y)
m is a posit ive int eger
a is r eal and m is a posit ive int eger
taylor(f,m,y,a)
a is r eal and m is a posit ive
int eger
a is r eal
taylor(f,y,a)
a is r eal
Mathematical Operation MATLAB
y
n
n!
------
y
n
n


f x y 0 = , ( ) ⋅
n 0 =
m

y a – ( )
n
n!
--------------------
y
n
n


f x y a = , ( ) ⋅
n 0 =
m

y a – ( )
n
n!
--------------------
y
n
n


f x y a = , ( ) ⋅
n 0 =
5

taylortool
2-125
t aylort ool
Purpose Taylor ser ies calculat or .
Syntax taylortool
taylortool('f')
Description taylortool init iat es a GUI t hat gr aphs a funct ion against t he Nt h par t ial sum
of it s Taylor ser ies about a basepoint x = a. The default funct ion, value of N,
basepoint , and int er val of comput at ion for taylortool ar e f = x*cos(x),
N = 7, a = 0, and [-2*pi,2*pi], r espect ively.
taylortool('f') init iat es t he GUI for t he given expr ession f.
Examples taylortool('exp(x*sin(x))')
taylortool('sin(tan(x)) – tan(sin(x))')
See Also funtools, rsums
tril
2-126
t r il
Purpose Symbolic lower t r iangle.
Syntax tril(X)
tril(X,K)
Description tril(X) is t he lower t r iangular par t of X.
tril(X,K) r et ur ns a lower t r iangular mat r ix t hat r et ains t he element s of X on
and below t he k-t h diagonal and set s t he r emaining element s t o 0. The values
k=0, k>0, and k<0 cor r espond t o t he main, super diagonals, and subdiagonals,
r espect ively.
Examples Suppose
A =
[ a, b, c ]
[ 1, 2, 3 ]
[ a+1, b+2, c+3 ]
Then tril(A) r et ur ns
[ a, 0, 0 ]
[ 1, 2, 0 ]
[ a+1, b+2, c+3 ]
tril(A,1) r et ur ns
[ a, b, 0 ]
[ 1, 2, 3 ]
[ a+1, b+2, c+3 ]
triu(A,–1) r et ur ns
[ 0, 0, 0 ]
[ 1, 0, 0 ]
[ a+1, b+2, 0 ]
See Also diag, triu
triu
2-127
t r iu
Purpose Symbolic upper t r iangle.
Syntax triu(X)
triu(X, K)
Description triu(X) is t he upper t r iangular par t of X.
triu(X, K) r et ur ns an upper t r iangular mat r ix t hat r et ains t he element s of X
on and above t he k-t h diagonal and set s t he r emaining element s t o 0. The
values k=0, k>0, and k<0 cor r espond t o t he main, super diagonals, and
subdiagonals, r espect ively.
Examples Suppose
A =
[ a, b, c ]
[ 1, 2, 3 ]
[ a+1, b+2, c+3 ]
Then triu(A) r et ur ns
[ a, b, c ]
[ 0, 2, 3 ]
[ 0, 0, c+3 ]
triu(A,1) r et ur ns
[ 0, b, c ]
[ 0, 0, 3 ]
[ 0, 0, 0 ]
triu(A,–1) r et ur ns
[ a, b, c ]
[ 1, 2, 3 ]
[ 0, b+2, c+3 ]
See Also diag, tril
vpa
2-128
vpa
Purpose Var iable pr ecision ar it hmet ic.
Syntax R = vpa(A)
R = vpa(A,d)
Description vpa(A) uses var iable-pr ecision ar it hmet ic (VPA) t o comput e each element of A
t o d decimal digit s of accur acy, wher e d is t he cur r ent set t ing of digits. Each
element of t he r esult is a symbolic expr ession.
vpa(A,d) uses d digit s, inst ead of t he cur r ent set t ing of digits.
Examples The st at ement s
digits(25)
q = vpa(sym(sin(pi/6)))
p = vpa(pi)
w = vpa('(1+sqrt(5))/2')
r et ur n
q =
.5000000000000000000000000
p = 3.141592653589793238462643
w =
1.618033988749894848204587
vpa pi 75 comput es π t o 75 digit s.
The statements
A = vpa(hilb(2),25)
B = vpa(hilb(2),5)
vpa
2-129
r et ur n
A =
[ 1., .5000000000000000000000000]
[.5000000000000000000000000, .3333333333333333333333333]
B =
[ 1., .50000]
[.50000, .33333]
See Also digits, double
zeta
2-130
zet a
Purpose Riemann Zet a funct ion.
Syntax Y = zeta(X)
Y = zeta(n, X)
Description zeta(X) evaluat es t he Zet a funct ion at t he element s of X, a numer ic mat r ix, or
a symbolic mat r ix. The Zet a funct ion is defined by
zeta(n, X) r et ur ns t he n-t h der ivat ive of zeta(X).
Examples zeta(1.5) returns 2.6124.
zeta(1.2:0.1:2.1) r et ur ns
Columns 1 through 7

5.5916 3.9319 3.1055 2.6124 2.2858 2.0543 1.8822

Columns 8 through 10

1.7497 1.6449 1.5602
zeta([x 2;4 x+y]) r et ur ns
[ zeta(x), 1/6*pi^2]
[ 1/90*pi^4, zeta(x+y)]
diff(zeta(x),x,3) r et ur ns zeta(3,x).
ζ w ( )
1
k
w
-------
k 1 =


=
ztrans
2-131
zt r ans
Purpose z-t r ansfor m.
Syntax F = ztrans(f)
F = ztrans(f,w)
F = ztrans(f,k,w)
Description F = ztrans(f) is t he z-t r ansfor m of t he scalar symbol f wit h default
independent var iable n. The default r et ur n is a funct ion of z.
The z-t r ansfor m of f is defined as:
wher e n is f’s symbolic var iable as det er mined by findsym. If
f = f(z), t hen ztrans(f) r et ur ns a funct ion of w.
F = ztrans(f,w) makes F a funct ion of t he symbol w inst ead of t he default z.
F = ztrans(f,k,w) t akes f t o be a funct ion of t he symbolic var iable k.
f f n ( ) = F F z ( ) = ⇒
F z ( )
f n ( )
z
n
----------
0


=
F F w ( ) =
F w ( )
f n ( )
w
n
----------
0


=
F w ( )
f k ( )
w
k
----------
0


=
ztrans
2-132
Examples
Z-Transform MATLAB Operation
f = n^4
ztrans(f)
r et ur ns
z*(z^3+11*z^2+11*z+1)/(z–1)^5
g = a^z
ztrans(g)
r et ur ns
–w/(–w+a)
f = sin(a*n)
ztrans(f,w)
r et ur ns
sin(a)*w/(1–w*cos(a)+w^2)
f n ( ) n
4
=
Z f [ ] f n ( )z
n –
z z
3
11z
2
11z 1 + + + ( )
z 1 – ( )
5
---------------------------------------------------------- =
n 0 =


=
g z ( ) a
z
=
Z g [ ] g z ( )w
z –
w
a w –
-------------- =
z 0 =


=
f n ( ) an sin =
Z f [ ] f n ( )w
n –
w a sin
1 2w a cos – w
2
+
-------------------------------------------- =
n 0 =


=
ztrans
2-133
See Also fourier, iztrans, laplace
f = exp(k*n^2)*cos(k*n)
ztrans(f,k,x)
r et ur ns
x*(–exp(–n*2)*cos(n)+x)/
(–2*x*exp(–n^2)*cos(n) + x^2+
exp(–2*n^2))
Z-Transform MATLAB Operation
f n k , ( ) e
k n
2

k n cos =
Z f [ ] f n k , ( )x
k –
x
2
e
n
2

n cos ( )x –
x
2
2e
n
2

n cos ( )x e
2n
2

+ –
------------------------------------------------------------------- =
k 0 =


=
ztrans
2-134
A
Compat ibilit y Guide
Compati bi li ty wit h Earli er Versi ons . . . . . . . . . A-2
Obsolete Funct i ons . . . . . . . . . . . . . . . . . A-3
A Compatibility Guide
A-2
Compatibility with Earlier Versions
Ear lier ver sions of t he Symbolic Mat h Toolboxes wor k wit h ver sion 4.0 or 4.1
of MATLAB and ver sion V, r elease 2 of Maple. The goal was t o pr ovide access
t o Maple wit h a language synt ax t hat is familiar t o MATLAB user s. This was
been done wit hout modifying eit her of t he t wo under lying syst ems.
However , it is not possible t o pr ovide complet ely seamless int egr at ion wit hout
modifying MATLAB. For example, if f and g ar e st r ings r epr esent ing symbolic
expr essions, we would pr efer t o use t he not at ion f+g for t heir sum, inst ead of
symadd(f,g). But f+g at t empt s t o add t he individual char act er s in t he t wo
st r ings, r at her t han concat enat e t hem wit h a plus sign in bet ween. Similar ly,
if A is a mat r ix whose element s ar e symbolic expr essions, we would pr efer t o
use A(i,j) t o access a individual expr ession, inst ead of sym(A,i,j). But if A
is a mat r ix of st r ings, t hen A(i,j) is a single char act er , not a complet e
expr ession.
This ver sion of t he Symbolic Mat h Toolboxes makes ext ensive use of t he new
MATLAB object capabilit ies and wor ks wit h Maple V, Release 4. For t his
r eason, it is not fully compat ible wit h ver sion 1 of t he Symbolic Mat h Toolbox.
Obsolete Functions
A-3
Obsolete Functions
This ver sion maint ains some compat ibilit y wit h ver sion 1. For example, t he
following obsolet e funct ions cont inue t o be available in ver sion 2, t hough you
should avoid using t hem as fut ur e r eleases may not include t hem.
In ver sion 1, t hese funct ions accept ed st r ings as ar gument s and r et ur ned
st r ings as r esult s. In ver sion 2, t hey accept eit her st r ings or symbolic object s as
input ar gument s and pr oduce symbolic object s as r esult s. ver sion 2 pr ovides
over loaded MATLAB oper at or s or new funct ions t hat you can use t o r eplace
most of t hese funct ions in your exist ing code.
For example, t he ver sion 1 st at ement s
f = '1/(5+4*cos(x))'
g = int(int(diff(f,2)))
e = symsub(f,g)
simple(e)
Function Description
determ Symbolic mat r ix det er minant
linsolve Solve simult aneous linear equat ions
eigensys Symbolic eigenvalues and eigenvect or s
singvals Symbolic singular values and singular vect or s
numeric Conver t symbolic mat r ix t o numer ic for m
symop Symbolic oper at ions
symadd Add symbolic expr essions
symsub Subt r act symbolic expr essions
symmul Mult iply symbolic expr essions
symdiv Divide symbolic expr essions
sympow Power of symbolic expr ession
eval Evaluat e a symbolic expr ession
A Compatibility Guide
A-4
cont inue t o wor k in ver sion 2. However , wit h ver sion 2, t he pr efer r ed appr oach
is
syms x
f = 1/(5+4*cos(x))
g = int(int(diff(f,2)))
e = f - g
simple(e)
The ver sion 1 st at ement s
H = sym(hilb(3))
I = sym(eye(3))
X = linsolve(H,I)
t = sym(0)
for j = 1:3
t = symadd(t,sym(X,j,j))
end
t
cont inue t o wor k in ver sion 2. However , t he pr efer r ed appr oach is
H = sym(hilb(3))
I = eye(3)
X = H\I
t = sum(diag(X))
You can no longer use t he sym funct ion in t his way.
M = sym(3,3,'1/(i+j–t)')
Inst ead, you must change t he code t o somet hing like t his
syms t
[J,I] = meshgrid(1:3)
M = 1./(I+J–t)
As in ver sion 1, you can supply diff, int, solve, and dsolve wit h st r ing
ar gument s in ver sion 2. In ver sion 2, however , t hese funct ions r et ur n symbolic
object s inst ead of st r ings.
For some comput at ions, t he new r elease of Maple pr oduces r esult s in a
differ ent for mat .
Obsolete Functions
A-5
For example, wit h ver sion 1, t he st at ement
[x,y] = solve('x^2 + 2*x*y + y^2 = 4', 'x^3 + 4*y^3 = 1')
pr oduces
x =
[ –RootOf(_Z^3–2*_Z^2–4*_Z–3)–2]
[–RootOf(3*_Z^3+6*_Z^2–12*_Z+7)+2]

y =
[ RootOf(_Z^3–2*_Z^2–4*_Z–3)]
[RootOf(3*_Z^3+6*_Z^2–12*_Z+7)]
The same st at ement wor ks in ver sion 2, but pr oduces r esult s wit h t he RootOf
expr essions expanded t o exhibit t he mult iple solut ions.
A Compatibility Guide
A-6
I-1
Index
Symbols
- 2-8
* 2-8
+ 2-8
.* 2-8
./ 2-8
.<bd> 2-8
.^ 2-9
.’ 2-9
/ 2-8
@sym dir ect or y 1-16
\ 1-71, 1-72
\<bd> 2-8
^ 2-9
’ 2-9
A
abst r act funct ions 1-10
Air y differ ent ial equat ion 1-110, 1-113
Air y funct ion 1-110, 1-130
algebr aic equat ions
solving 2-109
all 2-29
ar it hmet ic oper at ions 2-8-2-9
left division
ar r ay 2-8
mat r ix 2-8
mat r ix addit ion 2-8
mult iplicat ion
ar r ay 2-8
mat r ix 2-8
power
ar r ay 2-9
mat r ix 2-9
r ight division
ar r ay 2-8
mat r ix 2-8
subt r act ion 2-8
t r anspose
ar r ay 2-9
mat r ix 2-9
B
backslash oper at or 1-71
beam equat ion 1-115
Ber noulli polynomials 1-130
Bessel funct ions 1-114, 1-131
differ ent iat ing 1-18
int egr at ing 1-26
besseli 1-114
besselj 1-18
besselk 1-110, 1-113, 1-114
bet a funct ion 1-131
binomial coefficient s 1-130
br anch cut 1-46
C
calculus 1-17-1-46
ccode 2-11
char act er ist ic polynomial 1-75, 1-77, 2-97
Chebyshev polynomial 1-132
cir cuit analysis
using t he Laplace t r ansfor m for 1-120
cir culant mat r ix 1-11, 1-59
clear 1-28
clear ing var iables
in t he Maple wor kspace 1-28
in t he MATLAB wor kspace 1-28, 2-118
Index
I-2
collect 1-48, 2-12
colspace 1-73, 2-13
column space 1-73
complement ar y er r or funct ion 1-131
complex conjugat e 2-15
complex number
imaginar y par t of 2-66
r eal par t of 2-102
complex symbolic var iables 1-9
compose 2-14
conj 1-10, 2-15, 2-116
conver t ing symbolic mat r ices t o numer ic for m
1-9
cosine int egr al funct ion 2-16
cosine int egr als 1-131
cosint 2-16
D
Dawson’s int egr al 1-131
decimal symbolic expr essions 1-8
default symbolic var iable 1-13
definit e int egr at ion 1-25
det 2-17
diag 2-18
diff 1-17, 2-20
differ ence equat ions
solving 1-126
differ ent iat ion 1-17-1-21
diffr act ion 1-132
digamma funct ion 1-131
digits 1-9, 2-21
Dir ac Delt a funct ion 1-115, 1-131
discont inuit ies 1-45
discrim 1-93
double 1-67, 2-22
dsolve 1-108, 1-114, 2-23
E
eig 1-74, 2-25
eigenvalue t r aject or ies 1-86-1-95
eigenvalues 1-74-1-80, 1-87, 2-25
comput ing 1-74
eigenvect or s 1-75
ellipt ic int egr als 1-131
eps 1-8
er r or funct ion 1-131
Euler polynomials 1-130
expand 1-49, 2-28
expm 2-27
exponent ial int egr als 1-131
Ext ended Symbolic Mat h Toolbox 1-3, 1-131,
1-143-1-148, 2-93, 2-100
ezplot 1-34
F
factor 1-50, 2-47
fact or ial funct ion 1-11
fact or ial oper at or 2-121
findsym 1-14, 2-48
finverse 2-49
float ing-point ar it hmet ic 1-64
float ing-point symbolic expr essions 1-7
format 1-64
fortran 2-50
fourier 2-51
Four ier t r ansfor m 1-112-1-119, 2-51
Fr esnel int egr al 1-131
funct ion calculat or 2-54
funct ional composit ion 2-14
funct ional inver se 2-49
funtool 2-54
Index
I-3
G
gamma funct ion 1-131
Gegenbauer polynomial 1-131
gener alized hyper geomet r ic funct ion 1-131
Givens t r ansfor mat ion 1-69, 1-78
golden r at io 1-6
H
har monic funct ion 1-131
Heaviside funct ion 1-117, 1-131
Her mit e polynomial 1-131
Hilber t mat r ix 1-9, 1-70
horner 1-49, 2-57
hyper bolic cosine funct ion 1-131
hyper bolic sine funct ion 1-131
hyper geomet r ic funct ion 1-131
I
IEEE float ing-point ar it hmet ic 1-65
ifourier 1-113, 2-60
ilaplace 2-63
imag 2-66
incomplet e gamma funct ion 1-131
init ializing t he Maple ker nel 2-84
initstring var iable 2-84
int 1-23, 2-67
int egr al t r ansfor ms 1-112-1-129
Four ier 1-112-1-119
Laplace 1-120-1-125
z-t r ansfor m 1-126-1-129
int egr at ion 1-23-1-29
definit e 1-25
wit h r eal const ant s 1-26
inv 2-68
inver se Four ier t r ansfor m 2-60
inver se Laplace t r ansfor m 2-63
inver se z-t r ansfor m 2-70
iztrans 2-70
J
J acobi polynomial 1-132
jacobian 1-20, 2-72
J acobian mat r ix 1-20, 2-72
jordan 1-81, 2-73
J or dan canonical for m 1-81-1-82, 2-73
L
Laguer r e polynomial 1-132
Lamber t ’s W funct ion 1-131, 2-75
lambertw 2-75
laplace 2-76
Laplace t r ansfor m 1-120-1-125, 2-76
latex 2-79
left division
ar r ay 2-8
mat r ix 2-8
Legendr e polynomial 1-132
limit 1-21, 2-80
limit s 1-21-1-23
t wo-sided 1-22
undefined 1-22
linear algebr a 1-69-1-95
logar it hm funct ion 1-131
logar it hmic int egr al 1-131
M
machine epsilon 1-8
MacLaur in ser ies 1-31
Maple 1-2
Index
I-4
maple 2-81
out put ar gument 1-141
Maple funct ions
accessing 1-11, 1-136-1-142
Maple help 2-94
Maple ker nel
accessing 2-81
init ializing 2-84
Maple libr ar y 2-84
Maple Or t hogonal Polynomial Package 2-93
Maple packages 1-143
loading 1-144
Maple pr ocedur e 1-143, 2-100
compiling 1-148
inst alling 2-100
wr it ing 1-145-1-147
mapleinit 2-84
mat r ix addit ion 2-8
mat r ix condit ion number 1-72
mat r ix diagonal 2-18
mat r ix exponent ial 2-27
mat r ix inver se 2-68
mat r ix lower t r iangle 2-126
mat r ix r ank 2-101
mat r ix size 2-108
mat r ix upper t r iangle 2-127
M-file
cr eat ing 1-16
mfun 1-130, 2-85
mfunlist 2-86
mhelp 2-94
mult iplicat ion
ar r ay 2-8
mat r ix 2-8
N
null 1-72, 2-95
null space 1-72
null space basis 2-95
numden 2-96
numer ic symbolic expr essions 1-7
O
or dinar y differ ent ial equat ions
solving 2-23
or t hogonal polynomials 1-131, 2-93
P
poly 1-75, 2-97
poly2sym 2-98
polygamma funct ion 1-131
polynomial discr iminant s 1-93
power
ar r ay 2-9
mat r ix 2-9
pretty 1-32, 2-99
procread 1-146, 2-100
prod 1-11
R
rank 2-101
r at ional ar it hmet ic 1-65
r at ional symbolic expr essions 1-7
real 2-102
real pr oper t y 1-9
r eal symbolic var iables 1-9, 1-28
r educed r ow echelon for m 2-103
Riemann sums
evaluat ing 2-104
Index
I-5
Riemann Zet a funct ion 1-130, 2-130
r ight division
ar r ay 2-8
mat r ix 2-8
Rosser mat r ix 1-76, 1-77
r r ef 2-103
rsums 2-104
S
shift ed sine int egr al 1-131
simple 1-52, 2-105
simplificat ions 1-47-1-55
simplify 1-52, 2-106
simult aneous differ ent ial equat ions
solving 1-109-1-110, 1-122
simult aneous linear equat ions
solving syst ems of 1-71, 1-106
sine int egr al funct ion 2-107
sine int egr als 1-131
singular value decomposit ion 1-82-1-86, 2-114
sinint 2-107
solve 1-96, 2-109
solving equat ions 1-96-1-111
algebr aic 1-96-1-107, 2-109
differ ence 1-126
or dinar y differ ent ial 1-107-1-111, 2-23
special funct ions 1-130-1-135
evaluat ing numer ically 2-85
list ing 2-86
spher ical coor dinat es 1-19
subexpr 1-56, 2-111
subexpr essions 1-56-1-58
subs 1-59, 2-112
subst it ut ing in symbolic expr essions 2-112
subst it ut ions 1-56-1-63
subt r act ion 2-8
summat ion
symbolic 1-30
svd 1-82, 2-114
sym 1-5, 1-6, 1-7, 1-9, 1-11, 1-28, 2-116
sym2poly 2-119
symbolic expr essions 1-96
C code r epr esent at ion of 2-11
cr eat ing 1-6
decimal 1-8
differ ent iat ing 2-20
expanding 2-28
fact or ing 2-47
finding var iables in 2-48
float ing-point 1-7
For t r an r epr esent at ion of 2-50
int egr at ing 2-67
LaTeX r epr esent at ion of 2-79
numer ic 1-7
pr et t ypr int ing 2-99
r at ional 1-7
simplifying 2-105, 2-106, 2-111
subst it ut ing in 2-112
summat ion of 2-120
t aking a limit of 2-80
Taylor ser ies expansion of 2-122
symbolic mat h funct ions
cr eat ing 1-15
symbolic mat h pr ogr ams
debugging 1-141
wr it ing 1-136-1-140
Symbolic Mat h Toolbox
compat ibilit y wit h ear lier ver sions A-2
demo 1-5
obsolet e funct ions A-3
symbolic mat r ix
comput ing eigenvalue of 1-77
cover t ing t o numer ic for m 1-9
Index
I-6
cr eat ing 1-11
differ ent iat ing 1-19
symbolic object s
about 1-5
cr eat ing 2-116, 2-118
symbolic polynomials
conver t ing t o numer ic for m 2-119
cr eat ing fr om coefficient vect or 2-98
Hor ner r epr esent at ion of 2-57
symbolic summat ion 1-30-??
symbolic var iables
clear ing 2-118
complex 1-9
cr eat ing 1-6
default 1-13
r eal 1-9, 1-28
syms 1-7, 2-118
symsize 2-108
symsum 1-30, 2-120
T
taylor 1-31, 2-122, 2-122
Taylor ser ies 1-31
Taylor ser ies expansion 2-122
taylortool 2-125
Tony’s t r ick 1-84
t r ace mode 1-141
t r anspose
ar r ay 2-9
mat r ix 2-9
tril 2-126
triu 2-127
U
unreal pr oper t y 1-10
V
var iable-pr ecision ar it hmet ic 1-64-1-68, 2-128
set t ing accur acy of 2-21
var iable-pr ecision number s 1-66
vpa 1-66, 2-128
Z
zeta 2-130
ztrans 2-131
z-t r ansfor m 1-126-1-129, 2-131

Sign up to vote on this title
UsefulNot useful