Download as pdf or txt
Download as pdf or txt
You are on page 1of 523

Symbolic Math Toolbox 5

MuPAD Tutorial
How to Contact The MathWorks
www.mathworks.com Web
comp.soft-sys.matlab Newsgroup
www.mathworks.com/contact_TS.html Technical Support
suggest@mathworks.com Product enhancement suggestions
bugs@mathworks.com Bug reports
doc@mathworks.com Documentation error reports
service@mathworks.com Order status, license renewals, passcodes
info@mathworks.com Sales, pricing, and general information
508-647-7000 (Phone)
508-647-7001 (Fax)
The MathWorks, Inc.
3 Apple Hill Drive
Natick, MA 01760-2098
For contact information about worldwide offices, see the MathWorks Web site.
Symbolic Math Toolbox MuPAD Tutorial
COPYRIGHT 19972008 by SciFace Software GmbH & Co. KG.
The software described in this document is furnished under a license agreement. The software may be used
or copied only under the terms of the license agreement. No part of this manual may be photocopied or
reproduced in any form without prior written consent from The MathWorks, Inc.
FEDERAL ACQUISITION: This provision applies to all acquisitions of the Program and Documentation
by, for, or through the federal government of the United States. By accepting delivery of the Program or
Documentation, the government hereby agrees that this software or documentation qualifies as commercial
computer software or commercial computer software documentation as such terms are used or defined
in FAR 12.212, DFARS Part 227.72, and DFARS 252.227-7014. Accordingly, the terms and conditions of
this Agreement and only those rights specified in this Agreement, shall pertain to and govern the use,
modification, reproduction, release, performance, display, and disclosure of the Program and Documentation
by the federal government (or other entity acquiring for or through the federal government) and shall
supersede any conflicting contractual terms or conditions. If this License fails to meet the governments
needs or is inconsistent in any respect with federal procurement law, the government agrees to return the
Program and Documentation, unused, to The MathWorks, Inc.
Trademarks
MuPAD is a registered trademark of SciFace Software GmbH & Co. KG. MATLAB and Simulink
are registered trademarks of The MathWorks, Inc. See www.mathworks.com/trademarks for a list
of additional trademarks. Other product or brand names may be trademarks or registered
trademarks of their respective holders.
Patents
The MathWorks products are protected by one or more U.S. patents. Please see
www.mathworks.com/patents for more information.
Frelute
TIIs book expIuIns LIe busIc use oI LIe MuPAD

compuLer uIgebru sysLem, und


gIves some InsIgIL InLo LIe power oI LIe sysLem. MuPAD Is uvuIIubIe us purL oI LIe
SymboIIc MuLI TooIbox In MATAB

.
TIIs InLroducLIon uddresses muLIemuLIcIuns, engIneers, compuLer scIenLIsLs,
nuLuruI scIenLIsLs und, more generuIIy, uII LIose In need oI muLIemuLIcuI
compuLuLIons Ior LIeIr educuLIon or LIeIr proIessIon. GeneruIIy speukIng, LIIs
book uddresses unybody wIo wunLs Lo use LIe power oI u modern compuLer
uIgebru puckuge.
TIere ure Lwo wuys Lo use u compuLer uIgebru sysLem. On LIe one Iund, you muy
use LIe muLIemuLIcuI knowIedge IL IncorporuLes by cuIIIng sysLem IuncLIons
InLerucLIveIy. or exumpIe, you cun compuLe symboIIc InLegruIs or generuLe und
InverL muLrIces by cuIIIng upproprIuLe IuncLIons. TIey comprIse LIe sysLem`s
muLIemuLIcuI InLeIIIgence und muy ImpIemenL sopIIsLIcuLed uIgorILIms.
CIupLers z LIrougI 1q dIscuss LIIs wuy oI usIng LIe MuPAD engIne.
On LIe oLIer Iund, wILI LIe IeIp oI LIe MuPAD progrummIng Iunguuge, you cun
eusIIy udd IuncLIonuIILy Lo LIe sysLem by ImpIemenLIng your own uIgorILIms us
MuPAD procedures. TIIs Is useIuI Ior specIuI purpose uppIIcuLIons II no
upproprIuLe sysLem IuncLIons exIsL. CIupLers 1 LIrougI 1; ure un InLroducLIon Lo
MuPAD progrummIng.
You cun reud LIIs book In LIe sLundurd wuy IIneurIy Irom LIe IIrsL Lo LIe IusL
puge. However, LIere ure reusons Lo proceed oLIerwIse. TIIs muy be LIe cuse, e.g.,
II you ure InLeresLed In u purLIcuIur probIem, or II you uIreudy know someLIIng
ubouL MuPAD.
or begInners, we recommend Lo sLurL reudIng CIupLer z, wIIcI gIves u IIrsL
survey oI MuPAD. TIe descrIpLIon oI LIe onIIne IeIp sysLem In SecLIon z.z Is
probubIy LIe mosL ImporLunL purL oI LIIs cIupLer. TIe IeIp sysLem provIdes
InIormuLIon ubouL deLuIIs oI sysLem IuncLIons, LIeIr synLux, LIeIr cuIIIng
purumeLers, eLc. L Is uvuIIubIe onIIne wIenever LIe MuPAD noLebook InLerIuce Is
runnIng. n LIe begInnIng, requesLIng u IeIp puge Is probubIy your mosL IrequenL
query Lo LIe sysLem. AILer you Iuve grown IumIIIur wILI LIe IeIp sysLem, you muy
sLurL Lo experImenL wILI MuPAD. CIupLer z demonsLruLes some oI LIe mosL
ImporLunL sysLem IuncLIons uL work. You wIII IInd IurLIer deLuIIs ubouL LIese
IuncLIons In IuLer purLs oI LIe book or In LIe IeIp puges. or u deeper
Preloce
undersLundIng oI LIe duLu sLrucLures InvoIved, you muy consuIL LIe correspondIng
secLIons In CIupLer q.
CIupLer dIscusses LIe MuPAD IIbrurIes und LIeIr use. TIey conLuIn muny
IuncLIons und uIgorILIms Ior purLIcuIur muLIemuLIcuI LopIcs.
TIe busIc duLu Lypes und LIe mosL ImporLunL sysLem IuncLIons Ior LIeIr
munIpuIuLIon ure InLroduced In CIupLer q. L Is noL necessury Lo sLudy uII oI LIem
In LIe sume depLI. DependIng on your InLended uppIIcuLIon, you muy seIecLIveIy
reud onIy LIe pussuges ubouL LIe reIevunL LopIcs.
CIupLer expIuIns Iow MuPAD evuIuuLes objecLs; we sLrongIy recommend Lo reud
LIIs cIupLer.
CIupLers 6 LIrougI 11 dIscuss LIe use oI some purLIcuIurIy ImporLunL sysLem
IuncLIons: subsLILuLIon, dIIIerenLIuLIon, symboIIc InLegruLIon, equuLIon soIvIng,
rundom number generuLIon, und grupIIc communds.
SeveruI useIuI IeuLures sucI us LIe IIsLory mecIunIsm, InpuL und ouLpuL rouLInes,
or LIe deIInILIon oI user preIerences ure descrIbed In CIupLers 1.z LIrougI 1.
PreIerences cun be used Lo conIIgure LIe sysLem`s InLerucLIve beIuvIor uILer LIe
user`s Iuncy Lo u cerLuIn exLenL.
CIupLers 1 LIrougI 1; gIve un InLroducLIon Lo LIe busIc concepLs oI LIe MuPAD
progrummIng Iunguuge.
MuPAD provIdes uIgorILIms LIuL cun IundIe u Iurge cIuss oI muLIemuLIcuI objecLs
und compuLuLIonuI Lusks reIuLed Lo LIem. Upon reudIng LIIs InLroducLIon, IL Is
possIbIe LIuL you encounLer unknown muLIemuLIcuI noLIons sucI us rIngs or
IIeIds. TIIs InLroducLIon Is noL InLended Lo expIuIn LIe muLIemuLIcuI buckground
Ior sucI objecLs. BusIc muLIemuLIcuI knowIedge Is IeIpIuI buL noL munduLory Lo
undersLund LIe LexL. SomeLImes you muy usk wIuL uIgorILIm MuPAD uses Lo
soIve u purLIcuIur probIem. TIe InLernuI mode oI operuLIon oI LIe MuPAD
procedures Is noL uddressed Iere: we do noL InLend Lo gIve u generuI InLroducLIon
Lo compuLer uIgebru und ILs uIgorILIms. TIe InLeresLed reuder muy consuIL LexL
books sucI us, e.g., |GCqz| or |GGqq|.
TIIs book gIves un elementcr InLroducLIon Lo MuPAD. SomewIuL more ubsLrucL
muLIemuLIcuI objecLs sucI us, e.g., IIeId exLensIons, ure eusy Lo descrIbe und Lo
IundIe In MuPAD. However, sucI udvunced uspecLs oI LIe sysLem ure noL
dIscussed Iere. TIe muLIemuLIcuI uppIIcuLIons LIuL ure menLIoned In LIe LexL ure
ii
Preloce
InLenLIonuIIy kepL on u ruLIer eIemenLury IeveI. TIIs Is Lo keep LIIs LexL pIuIn Ior
reuders wILI IILLIe muLIemuLIcuI buckground und Lo muke IL uppIIcubIe uL scIooI
IeveI.
We cunnoL expIuIn LIe compIeLe IuncLIonuIILy oI MuPAD In LIIs InLroducLIon.
Some purLs oI LIe sysLem ure menLIoned onIy brIeIIy. L Is beyond LIe scope oI LIIs
LuLorIuI Lo go InLo LIe deLuIIs oI LIe IuII power oI LIe MuPAD progrummIng
Iunguuge. You IInd LIese In LIe MuPAD IeIp sysLem, uvuIIubIe onIIne durIng u
MuPAD sessIon.
TIIs LuLorIuI reIers Lo MuPAD versIon und IuLer. SInce LIe deveIopmenL oI LIe
sysLem udvunces conLInuousIy, some oI LIe deLuIIs descrIbed muy cIunge In LIe
IuLure. uLure versIons wIII deIInILeIy provIde uddILIonuI IuncLIonuIILy LIrougI
new sysLem IuncLIons und uppIIcuLIon puckuges. n LIIs LuLorIuI, we muInIy
presenL LIe busIc LooIs und LIeIr use, wIIcI wIII probubIy remuIn essenLIuIIy
uncIunged. We Lry Lo word uII sLuLemenLs In LIe LexL In sucI u wuy LIuL LIey sLuy
busIcuIIy vuIId Ior IuLure MuPAD versIons.
iii
feaIeaIs
PreIuce
i
Introdoction
T
NumerIcuI CompuLuLIons . . . . . . . . . . . . . . . . . . . . . . . . . . 1-z
CompuLer AIgebru . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-
CIurucLerIsLIcs oI CompuLer AIgebru SysLems . . . . . . . . . . . . . . . 1-
MuPAD

SoILwure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-6
Iirst Steps in MoPA

2
NoLebook InLerIuce . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . z-z
ExpIunuLIons und HeIp . . . . . . . . . . . . . . . . . . . . . . . . . . . z-q
CompuLIng wILI Numbers . . . . . . . . . . . . . . . . . . . . . . . . . . z-
ExucL CompuLuLIons . . . . . . . . . . . . . . . . . . . . . . . . . z-6
NumerIcuI ApproxImuLIons . . . . . . . . . . . . . . . . . . . . . z-;
CompIex Numbers . . . . . . . . . . . . . . . . . . . . . . . . . . z-q
SymboIIc CompuLuLIon . . . . . . . . . . . . . . . . . . . . . . . . . . . z-11
nLroducLory ExumpIes . . . . . . . . . . . . . . . . . . . . . . . . z-11
Curve SkeLcIIng . . . . . . . . . . . . . . . . . . . . . . . . . . . . z-z1
EIemenLury Number TIeory . . . . . . . . . . . . . . . . . . . . . z-zq
Con|en|s
The MoPA

Libruries
3
nIormuLIon AbouL u PurLIcuIur Ibrury . . . . . . . . . . . . . . . . . . -z
ExporLIng IbrurIes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . -q
TIe SLundurd Ibrury . . . . . . . . . . . . . . . . . . . . . . . . . . . . -6
MoPA

Objects
4
Operunds: LIe uncLIons op und nops . . . . . . . . . . . . . . . . . . . q-
Numbers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . q-6
denLIIIers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . q-8
SymboIIc ExpressIons . . . . . . . . . . . . . . . . . . . . . . . . . . . . q-1z
OperuLors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . q-1z
ExpressIon Trees . . . . . . . . . . . . . . . . . . . . . . . . . . . q-1q
Operunds . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . q-z1
Sequences . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . q-zq
IsLs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . q-z8
SeLs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . q-6
TubIes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . q-qo
Arruys . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . q-qq
BooIeun ExpressIons . . . . . . . . . . . . . . . . . . . . . . . . . . . . . q-q;
SLrIngs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . q-qq
uncLIons . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . q-z
SerIes ExpunsIons . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . q-6
AIgebruIc SLrucLures: IeIds, RIngs, eLc. . . . . . . . . . . . . . . . . . . q-6o
VecLors und MuLrIces . . . . . . . . . . . . . . . . . . . . . . . . . . . . q-6q
DeIInILIon oI MuLrIces und VecLors . . . . . . . . . . . . . . . . . q-6q
CompuLIng wILI MuLrIces . . . . . . . . . . . . . . . . . . . . . . q-;o
SpecIuI MeLIods Ior MuLrIces . . . . . . . . . . . . . . . . . . . . q-;z
TIe IbrurIes iinoig und numeric . . . . . . . . . . . . . . . . . q-;q
Spurse MuLrIces . . . . . . . . . . . . . . . . . . . . . . . . . . . . q-;;
An AppIIcuLIon . . . . . . . . . . . . . . . . . . . . . . . . . . . . q-;8
PoIynomIuIs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . q-81
vi
Con|en|s
DeIInILIon oI PoIynomIuIs . . . . . . . . . . . . . . . . . . . . . . q-81
CompuLIng wILI PoIynomIuIs . . . . . . . . . . . . . . . . . . . . q-8
Hurdwure IouL Arruys . . . . . . . . . . . . . . . . . . . . . . . . . . . q-qz
nLervuI ArILImeLIc . . . . . . . . . . . . . . . . . . . . . . . . . . . . . q-qq
NuII ObjecLs: nuii(}, WTL, FATL, undefined . . . . . . . . . . . . . . . . q-qq
Ivuloution und SimpliIicution
5
denLIIIers und TIeIr VuIues . . . . . . . . . . . . . . . . . . . . . . . . . -1
CompIeLe, ncompIeLe, und EnIorced EvuIuuLIon . . . . . . . . . . . . . -q
AuLomuLIc SImpIIIIcuLIon . . . . . . . . . . . . . . . . . . . . . . . . . . -1o
EvuIuuLIon uL u PoInL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . -1
Sobstitotion: subs, subsex, und subsop

iIIerentiution und Integrution


7
DIIIerenLIuLIon . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ;-z
nLegruLIon . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ;-q
Solving Iqoutions: soive
8
PoIynomIuI EquuLIons . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-z
GeneruI EquuLIons und nequuIILIes . . . . . . . . . . . . . . . . . . . . 8-q
DIIIerenLIuI EquuLIons . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-1z
vii
Con|en|s
Recurrence EquuLIons . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-1
Munipoluting Ixpressions

TrunsIormIng ExpressIons . . . . . . . . . . . . . . . . . . . . . . . . . q-
SImpIIIyIng ExpressIons . . . . . . . . . . . . . . . . . . . . . . . . . . . q-1
AssumpLIons ubouL MuLIemuLIcuI ProperLIes . . . . . . . . . . . . . . . q-18
Chunce und Probubility
T0
Gruphics
TT
nLroducLIon . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11-1
Eusy PIoLLIng: GrupIs oI uncLIons . . . . . . . . . . . . . . . . . . . . 11-z
zD uncLIon GrupIs . . . . . . . . . . . . . . . . . . . . . . . . . 11-z
D uncLIon GrupIs . . . . . . . . . . . . . . . . . . . . . . . . . 11-18
Advunced PIoLLIng: PrIncIpIes und IrsL ExumpIes . . . . . . . . . . . . 11-
GeneruI PrIncIpIes . . . . . . . . . . . . . . . . . . . . . . . . . . 11-
Some ExumpIes . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11-q
TIe uII PIcLure: GrupIIcuI Trees . . . . . . . . . . . . . . . . . . . . . 11-q6
VIewer, Browser, und nspecLor: nLerucLIve MunIpuIuLIon . . . . . . . 11-o
PrImILIves . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11-q
ALLrIbuLes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11-;
DeIuuIL VuIues . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11-;
nIerILunce oI ALLrIbuLes . . . . . . . . . . . . . . . . . . . . . . . 11-8
PrImILIves RequesLIng Scene ALLrIbuLes: HInLs . . . . . . . . . 11-6z
TIe HeIp Puges oI ALLrIbuLes . . . . . . . . . . . . . . . . . . . . . 11-6
viii
Con|en|s
CoIors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11-6;
RGB CoIors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11-6;
HSV CoIors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11-6q
AnImuLIons . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11-;1
GeneruLIng SImpIe AnImuLIons . . . . . . . . . . . . . . . . . . . 11-;1
PIuyIng AnImuLIons . . . . . . . . . . . . . . . . . . . . . . . . . . 11-;
TIe Number oI rumes und LIe TIme Runge . . . . . . . . . . . . 11-;6
WIuL Cun Be AnImuLed? . . . . . . . . . . . . . . . . . . . . . . . 11-;8
Advunced AnImuLIons: TIe SyncIronIzuLIon ModeI . . . . . . . . 11-;q
rume by rume AnImuLIons . . . . . . . . . . . . . . . . . . . . . 11-8
ExumpIes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11-qo
Groups oI PrImILIves . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11-q
TrunsIormuLIons . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11-q;
egends . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11-1oo
onLs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11-1oq
SuvIng und ExporLIng PIcLures . . . . . . . . . . . . . . . . . . . . . . . 11-1o;
nLerucLIve SuvIng und ExporLIng . . . . . . . . . . . . . . . . . . 11-1o;
BuLcI Mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11-1o8
mporLIng PIcLures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11-11o
Cumerus In D . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11-11z
SLrunge EIIecLs In D? AcceIeruLed OpenG

IIbrury? . . . . . . . . . . 11-1zo
Inpot und Ootpot
T2
OuLpuL oI ExpressIons . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1z-1
PrInLIng ExpressIons on LIe Screen . . . . . . . . . . . . . . . . . 1z-1
ModIIyIng LIe OuLpuL ormuL . . . . . . . . . . . . . . . . . . . . 1z-
ReudIng und WrILIng IIes . . . . . . . . . . . . . . . . . . . . . . . . . . 1z-
TIe uncLIons Wrile und reod . . . . . . . . . . . . . . . . . . . . 1z-
SuvIng u MuPAD

SessIon . . . . . . . . . . . . . . . . . . . . . . 1z-6
ReudIng DuLu Irom u TexL IIe . . . . . . . . . . . . . . . . . . . . 1z-6
ix
Con|en|s
Ltilities
T3
User-DeIIned PreIerences . . . . . . . . . . . . . . . . . . . . . . . . . . 1-z
TIe HIsLory MecIunIsm . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-6
nIormuLIon on MuPAD

AIgorILIms . . . . . . . . . . . . . . . . . . . 1-q
ResLurLIng u MuPAD

SessIon . . . . . . . . . . . . . . . . . . . . . . . 1-11
ExecuLIng Communds oI LIe OperuLIng SysLem . . . . . . . . . . . . . . 1-1z
Type SpeciIiers
T4
TIe uncLIons lype und lesllype . . . . . . . . . . . . . . . . . . . . . 1q-z
ComIorLubIe Type CIeckIng: LIe Type Ibrury . . . . . . . . . . . . . . 1q-q
Loops
T5
Brunching: if-lhen-eise und cose
T
MoPA

Procedores
T7
DeIInIng Procedures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1;-
TIe ReLurn VuIue oI u Procedure . . . . . . . . . . . . . . . . . . . . . . 1;-
ReLurnIng SymboIIc uncLIon CuIIs . . . . . . . . . . . . . . . . . . . . . 1;-;
ocuI und GIobuI VurIubIes . . . . . . . . . . . . . . . . . . . . . . . . . 1;-q
x
Con|en|s
Subprocedures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1;-1q
Scope oI VurIubIes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1;-1;
Type DecIuruLIon . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1;-zo
Procedures wILI u VurIubIe Number oI ArgumenLs . . . . . . . . . . . . 1;-z1
OpLIons: LIe Remember TubIe . . . . . . . . . . . . . . . . . . . . . . . 1;-z
npuL PurumeLers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1;-z;
EvuIuuLIon WILIIn Procedures . . . . . . . . . . . . . . . . . . . . . . . 1;-zq
uncLIon EnvIronmenLs . . . . . . . . . . . . . . . . . . . . . . . . . . . 1;-1
A ProgrummIng ExumpIe: DIIIerenLIuLIon . . . . . . . . . . . . . . . . . 1;-8
ProgrummIng ExercIses . . . . . . . . . . . . . . . . . . . . . . . . . . . 1;-q1
Solotions to Ixercises
A
ocomentution und ReIerences

Gruphics Gullery
C
Comments on the Gruphics Gullery
D
xi
Con|en|s
Index
lnoex
xii
T
Introdoction
To expIuIn LIe noLIon oI compuLer uIgebru, we compure uIgebruIc und numerIcuI
compuLuLIons. BoLI kInds ure supporLed by u compuLer, buL LIere ure
IundumenLuI dIIIerences, wIIcI ure dIscussed In wIuL IoIIows.
T In|roduc|ion
umeritul fempuIuIieas
Muny u muLIemuLIcuI probIem cun be soIved upproxImuLeIy by numerIcuI
compuLuLIons. TIe compuLuLIon sLeps operuLe on numbers, wIIcI ure sLored
InLernuIIy In jloctin-point representction. TIIs represenLuLIon Ius LIe druwbuck
LIuL neILIer compuLuLIons nor soIuLIons ure exucL due Lo roundIng errors. n
generuI, numerIcuI uIgorILIms IInd upproxImuLe soIuLIons us IusL us possIbIe.
OILen sucI soIuLIons ure LIe onIy wuy Lo IundIe u muLIemuLIcuI probIem
compuLuLIonuIIy, In purLIcuIur II LIere Is no cIosed Iorm soIuLIon known. (TIe
mosL popuIur exumpIe Ior LIIs sILuuLIon ure rooLs oI poIynomIuIs oI IIgI degrees.)
Moreover, upproxImuLe soIuLIons ure useIuI II exucL resuILs ure unnecessury (e.g.,
In vIsuuIIzuLIon).
1-
Compu|er Algebro
fempuIer klgebru
n conLrusL Lo numerIcuI compuLuLIons, LIere ure smbolic compuLuLIons In
compuLer uIgebru. |Hec q| deIInes LIem us computctions uith smbols
representin mcthemcticcl objects. Here, un object muy be u number, buL uIso u
poIynomIuI, un equuLIon, un expressIon or u IormuIu, u IuncLIon, u group, u rIng,
or uny oLIer muLIemuLIcuI objecL. SymboIIc compuLuLIons wILI numbers ure
currIed ouL excctl. nLernuIIy, numbers ure represenLed us quoLIenLs oI InLegers
oI urbILrury IengLI (IImILed by LIe umounL oI sLoruge uvuIIubIe, oI course). TIese
kInds oI compuLuLIons ure cuIIed smbolic or clebrcic. |Hec q| gIves LIe
IoIIowIng deIInILIons:
1. SymboIIc empIusIzes LIuL In muny cuses LIe uILImuLe gouI oI muLIemuLIcuI
probIem soIvIng Is expressIng LIe unswer In u cIosed IormuIu or IIndIng u
symboIIc upproxImuLIon.
z. AIgebruIc meuns LIuL compuLuLIons ure currIed ouL exucLIy, uccordIng Lo
LIe ruIes oI uIgebru, InsLeud oI usIng upproxImuLe IIouLIng-poInL urILImeLIc.
SomeLImes symboIIc munIpuIuLIon or IormuIu munIpuIuLIon ure used us
synonyms Ior compuLer uIgebru, sInce compuLuLIons operuLe on symboIs und
IormuIue. ExumpIes ure symboIIc InLegruLIon or dIIIerenLIuLIon sucI us
_
xdx =
x
2
2
,
_
4
1
xdx =
15
2
,
d
dx
InInx =
1
xInx
or symboIIc soIuLIons oI equuLIons. or exumpIe, we consIder LIe equuLIon
x
4
+p x
2
+ 1 = 0 In x wILI one purumeLer p. Ls soIuLIon seL Is
_
_
_

2
_
p
_
p
2
4
2
,

2
_
p +
_
p
2
4
2
_
_
_
.
TIe symboIIc compuLuLIon oI un exucL soIuLIon usuuIIy requIres more compuLIng
LIme und more sLoruge LIun LIe numerIc compuLuLIon oI un upproxImuLe soIuLIon.
However, u symboIIc soIuLIon Is exucL, more generuI, und oILen provIdes more
InIormuLIon ubouL LIe probIem und ILs soIuLIon. TIe ubove IormuIu expresses LIe
soIuLIons oI LIe equuLIon In Lerms oI LIe purumeLer p. L sIows Iow LIe soIuLIons
1-
T In|roduc|ion
depend IuncLIonuIIy on p. TIIs InIormuLIon cun be used, Ior exumpIe, Lo exumIne
Iow sensILIve LIe soIuLIons beIuve wIen LIe purumeLer cIunges.
CombInuLIons oI symboIIc und numerIc meLIods ure useIuI Ior specIuI
uppIIcuLIons. or exumpIe, LIere ure uIgorILIms In compuLer uIgebru LIuL beneIIL
Irom eIIIcIenL Iurdwure IIouLIng-poInL urILImeLIc. On LIe oLIer Iund, IL muy be
useIuI Lo sImpIIIy u probIem Irom numerIcuI unuIysIs symboIIcuIIy beIore uppIyIng
LIe ucLuuI upproxImuLIon uIgorILIm.
1-q
Choroc|eris|ics ol Compu|er Algebro 5ys|ems
fhurutIerisIits el fempuIer klgebru $ysIems
MosL oI LIe currenL compuLer uIgebru sysLems cun be used InLerucLIveIy. TIe user
enLers some IormuIue und communds, und LIe sysLem etcluctes LIem. TIen IL
reLurns un unswer, wIIcI cun be munIpuIuLed IurLIer II necessury.
n uddILIon Lo exucL symboIIc compuLuLIons, mosL compuLer uIgebru puckuges cun
upproxImuLe soIuLIons numerIcuIIy us weII. TIe user cun seL LIe precIsIon Lo LIe
desIred number oI dIgILs. n MuPAD

, LIe gIobuI vurIubIe 0TCTTS IundIes LIIs.


or exumpIe, II you enLer LIe sImpIe commund 0TCTTS.=100, LIen MuPAD
perIorms uII IIouLIng-poInL cuIcuIuLIons wILI u precIsIon oI 100 decImuI dIgILs. OI
course, sucI compuLuLIons need more compuLIng LIme und more sLoruge LIun LIe
use oI Iurdwure IIouLIng-poInL urILImeLIc.
Moreover, modern compuLer uIgebru sysLems provIde u powerIuI progrummIng
Iunguuge
1
und LooIs Ior vIsuuIIzuLIon und unImuLIon oI muLIemuLIcuI duLu. AIso,
muny sysLems cun produce IuyouLed documenLs (known us notebools or
uorlsheets). TIe MuPAD sysLem Ius sucI u noLebook concepL, buL we wIII onIy
skeLcI IL brIeIIy In LIIs LuLorIuI. PIeuse cIeck LIe user InLerIuce documenLuLIon
InsLeud Ior more deLuIIs. TIe gouI oI LIIs book Is Lo gIve un InLroducLIon Lo LIe
mcthemcticcl power oI LIe MuPAD Iunguuge.
1
TIe MuPAD progrummIng Iunguuge Is sLrucLured sImIIurIy Lo PuscuI, wILI exLensIons sucI us Iun-
guuge consLrucLs Ior objecL orIenLed progrummIng.
1-g
T In|roduc|ion
MuFk0

$elIwure
n compurIson Lo oLIer compuLer uIgebru sysLems, MuPAD

Ius LIe IoIIowIng


noLeworLIy IeuLures, wIIcI ure noL dIscussed In deLuII In LIIs book:
TIere ure MuPAD Iunguuge consLrucLs Ior objecL orIenLed progrummIng.
You cun deIIne your own duLu Lypes, e.g., Lo represenL muLIemuLIcuI
sLrucLures. AImosL uII exIsLIng operuLors und IuncLIons cun be overIouded.
TIere Is u IIgIIy InLerucLIve MuPAD source code debugger.
Progrums wrILLen In C or C++ cun be udded Lo LIe kerneI by LIe MuPAD
dynumIc moduIe concepL.
TIe IeurL oI LIe MuPAD engIne Is ILs lernel, wIIcI Is ImpIemenLed In C++. L
comprIses LIe IoIIowIng muIn componenLs:
- TIe pcrser reuds LIe InpuL Lo LIe sysLem und perIorms u synLux cIeck. I no
errors ure Iound, IL converLs LIe InpuL Lo u MuPAD duLu Lype.
- TIe etcluctor processes und sImpIIIIes LIe InpuL. Ls mode oI operuLIon Is
dIscussed IuLer.
- TIe memor mcncement Is responsIbIe Ior LIe eIIIcIenL sLoruge oI MuPAD
objecLs.
- Some IrequenLIy used uIgorILIms sucI us, e.g., urILImeLIcuI IuncLIons ure
ImpIemenLed us lernel junctions In C.
Purser und evuIuuLor deIIne LIe MuPAD Iunguuge us descrIbed In LIIs book. TIe
MuPAD IIbrurIes, wIIcI conLuIn mosL oI LIe muLIemuLIcuI knowIedge oI LIe
sysLem, ure ImpIemenLed In LIIs Iunguuge.
n uddILIon, MuPAD oIIers comIorLubIe user InLerIuces Ior generuLIng notebools
or grupIIcs, or Lo debug progrums wrILLen In LIe MuPAD Iunguuge. TIe MuPAD
IeIp sysLem Ius IyperLexL IuncLIonuIILy. You cun nuvIguLe wILIIn documenLs und
execuLe exumpIes by u mouse cIIck.
SymboIIc MuLI TooIbox uIso oIIers u wuy oI usIng LIe MuPAD engIne Lo soIve
probIems dIrecLIy Irom LIe MATAB

envIronmenL, usIng eILIer communds us


1-6
NuPAD

5ol|wore
presenLed Iere or, Ior u seIecLed subseL oI communds, uILernuLIves IILLIng more
cIoseIy InLo u MATAB Iunguuge progrum. TIIs book does noL dIscuss LIese
opLIons, buL IImILs ILseII Lo usIng LIe MuPAD engIne dIrecLIy, uIong wILI LIe
MuPAD GUs.
1-,
2
Iirst Steps in MoPA

CompuLer uIgebru sysLems sucI us MuPAD

ure oILen used InLerucLIveIy. or


exumpIe, you cun enLer un InsLrucLIon Lo muILIpIy Lwo numbers und Iuve MuPAD
compuLe LIe resuIL und prInL IL on LIe screen.
TIe IoIIowIng secLIon wIII gIve u sIorL descrIpLIon oI LIe user InLerIuce. TIe nexL
one uILer LIuL descrIbes LIe IeIp sysLem. RequesLIng u IeIp puge Is probubIy LIe
mosL IrequenLIy used commund Ior LIe begInner. TIe secLIon uILer LIuL Is ubouL
usIng MuPAD us un InLeIIIgenL pockeL cuIcuIuLor: cuIcuIuLIng wILI numbers.
TIIs Is LIe eusIesL und LIe mosL InLuILIve purL oI LIIs LuLorIuI. AILerwurds we
InLroduce some sysLem IuncLIons Ior symboIIc compuLuLIons. TIe correspondIng
secLIon Is wrILLen quILe InIormuIIy und gIves u IIrsL InsIgIL InLo LIe symboIIc
IeuLures oI LIe sysLem.
2 Firs| 5|eps in NuPAD

eIebeek iaIerlute
AILer you cuII LIe MuPAD

progrum, you wIII see LIe weIcome dIuIog. rom LIere,


you cun enLer LIe IeIp sysLem (wIIcI Is, oI course, uIso uvuIIubIe IuLer und wIII be
descrIbed on puge z-q), open un exIsLIng IIIe, creuLe u new MuPAD source IIIe or
open u new noLebook. UsuuIIy, you wIII wIsI Lo open un exIsLIng or u new
noLebook.
AILer sLurLIng LIe progrum, you cun enLer communds In LIe MuPAD Iunguuge.
TIese communds sIouId be Lyped InLo InpuL regIons, wIIcI Iook IIke LIIs:
I you press LIe <ReLurn> key, LIIs IInIsIes your InpuL und MuPAD evuIuuLes LIe
commund LIuL you Iuve enLered. HoIdIng <SIIIL> wIIIe pressIng <ReLurn>
provokes u IIneIeed, wIIcI you cun use Lo IormuL your InpuL.
AILer InvokIng LIe commund, you wIII see ILs resuIL prInLed In LIe sume bruckeL,
beIow LIe InpuL, und II you were uL LIe end oI LIe noLebook, u new InpuL regIon
wIII be opened beIow:
sin(3.141}
0.0005926535551
TIe sysLem evuIuuLed LIe usuuI sIne IuncLIon uL LIe poInL 3.141 und reLurned u
IIouLIng-poInL upproxImuLIon oI LIe vuIue, sImIIur Lo LIe ouLpuL oI u pockeL
cuIcuIuLor.
You cun uL uny LIme go buck Lo oIder InpuLs und edIL LIem. AIso, you cun cIIck
beLween LIe bruckeLs und udd LexL. EdILIng ouLpuL Is noL possIbIe, buL you cun
copy IormuIus Irom LIe ouLpuL und pusLe LIem somepIuce eIse. (WIen copyIng u
IormuIu Lo un InpuL regIon, IL wIII be uuLomuLIcuIIy LrunsIuLed InLo un equIvuIenL
commund In LexLuuI Iorm.)
I you LermInuLe your commund wILI u coIon, LIen MuPAD execuLes LIe commund
wILIouL prInLIng ILs resuIL on LIe screen. TIIs enubIes you Lo suppress LIe ouLpuL
oI IrreIevunL InLermedIuLe resuILs.
-
No|ebook in|erloce
You cun enLer more LIun one commund In one IIne. Two subsequenL communds
Iuve Lo be sepuruLed by u semIcoIon or u coIon, II LIe resuIL oI LIe IIrsL commund
Is Lo be prInLed or noL, respecLIveIy:
diff(sin(x^Z} x} inl(x x}
2 x cos
_
x
2
_
sIn
_
x
2
_
Here x^Z denoLes LIe squure oI x, und LIe MuPAD IuncLIons diff und inl
perIorm LIe operuLIons dIIIerenLIuLe und InLegruLe (CIupLer ;). TIe cIurucLer
x reLurns LIe prevIous expressIon (In LIe exumpIe, LIIs Is LIe derIvuLIve oI sIn(x
2
)).
TIe concepL underIyIng x Is dIscussed In CIupLer 1.z.
n LIe IoIIowIng exumpIe, LIe ouLpuL oI LIe IIrsL commund Is suppressed by LIe
coIon, und onIy LIe resuIL oI LIe second commund uppeurs on LIe screen:
equolions .= {x + y = 1 x - y = 1].
soive(equolions}
{[x = 1, y = 0]}
n LIe prevIous exumpIe, u seL oI Lwo equuLIons Is ussIgned Lo LIe IdenLIIIer
equolions. TIe commund soive(equolions} compuLes LIe soIuLIon. CIupLer 8
dIscusses LIe soIver In more deLuII.
To quIL u MuPAD sessIon, use LIe correspondIng enLry In LIe IIe menu.
-
2 Firs| 5|eps in NuPAD

xpluauIieas uad kelp


I you do noL know LIe correcL synLux oI u MuPAD

commund, you cun obLuIn LIIs


InIormuLIon dIrecLIy Irom LIe onIIne IeIp sysLem. or u brIeI expIunuLIon, sImpIy
Lype LIe commund nume, poInL your mouse cursor uL LIe commund und IeL IL resL
LIere Ior u momenL. You wIII geL u LooILIp wILI u brIeI expIunuLIon.
TIe help pce oI LIe correspondIng IuncLIon provIdes more deLuIIed InIormuLIon.
You cun requesL IL by enLerIng heip("nome"}, wIere nome Is LIe nume oI LIe
IuncLIon. TIe IuncLIon heip expecLs ILs urgumenL Lo be u sLrIng, wIIcI Is
generuLed by doubIe quoLes " (SecLIon q.11). TIe operuLor ? Is u sIorL Iorm Ior
heip. L Is used wILIouL purenLIesIs or quoLes:
?soive
TIe IeIp sysLem Is u IyperLexL sysLem, I.e., sImIIur Lo browsIng LIe web. AcLIve
keywords ure underIIned. I you cIIck on LIem, you obLuIn IurLIer InIormuLIon
ubouL LIe correspondIng noLIon. TIe LooILIps menLIoned ubove uIso work In LIe
IeIp sysLem. You cun edIL und execuLe LIe exumpIes In LIe IeIp sysLem or copy
und pusLe LIem Lo u noLebook.
Ixercise .1: Ind ouL Iow Lo use LIe MuPAD dIIIerenLIuLor diff, und compuLe
LIe IIILI derIvuLIve oI sIn(x
2
).
-q
Compu|ing wi|h Numbers
fempuIiag wiIh umbers
To compuLe wILI numbers, you cun use MuPAD

IIke u pockeL cuIcuIuLor. TIe


resuIL oI LIe IoIIowIng InpuL Is u ruLIonuI number:
1 + 5/Z
7
2
You see LIuL LIe reLurns ure exucL resuILs (und noL rounded IIouLIng-poInL
numbers) wIen compuLIng wILI InLegers und ruLIonuI numbers:
(1 + (5/Z*3}}/(1/7 + 7/9}^Z
67473
6728
TIe symboI ^ represenLs exponenLIuLIon. MuPAD cun compuLe bIg numbers
eIIIcIenLIy. TIe IengLI oI u number LIuL you muy compuLe Is onIy IImILed by LIe
uvuIIubIe muIn sLoruge. or exumpIe, LIe 123rd power oI 1234 Is u IuIrIy bIg
InLeger:
1
1Z34^1Z3
17051506Z1Z7Z704Z750597Z76Z06Z6ZZ65430Z31311106Z9`
04705Z96193ZZ139133460074713663067170605957Z6415`
9Z314554345900570596706714997090610Z53990446514793`
1356173055636699939501046ZZ0356Z0Z735575775507003Z3`
444147773960Z63706704Z65700404003Z704Z40639606`
966557650166993333319045915994Z4537Z414601`
094Z97177Z61076Z595Z4340601014415Z9766Z793067Z0`
356Z799104
BesIdes LIe busIc urILImeLIc IuncLIons, MuPAD provIdes u vurIeLy oI IuncLIons
operuLIng on numbers.
1
n LIIs prInLouL, LIe bucksIusI \ uL LIe end oI u IIne IndIcuLes LIuL LIe resuIL Is conLInued on LIe
nexL IIne. To breuk Iong IInes In LIIs wuy, you need Lo swILcI oII LypeseLLIng In LIe NoLebook menu.
-g
2 Firs| 5|eps in NuPAD

A sImpIe exumpIe Is LIe IucLorIuI n! = 1 2 n oI u nonneguLIve InLeger, wIIcI


cun be enLered In muLIemuLIcuI noLuLIon:
100!
933Z6Z1544394415Z61699Z356Z6670049071596Z64316Z1`
4659Z96395Z17599993ZZ99156094146397615651Z6Z5369`
79Z0Z7ZZ375Z5115Z1091664000000000000000000000000
TIe IuncLIon isprime cIecks wIeLIer u posILIve InLeger Is prIme. L reLurns eILIer
TRuE or FALSE.
isprime(1Z345679}
ASE
UsIng ifoclor, you cun obLuIn LIe prIme IucLorIzuLIon:
ifoclor(1Z345679}
3
2
3607 3803
Ixuct Compotutions
Now suppose LIuL we wunL Lo compuLe LIe number

56. TIe probIem Is LIuL LIe


vuIue oI LIIs IrruLIonuI number cunnoL be expressed us u quoLIenL
numeruLorJdenomInuLor oI Lwo InLegers exucLIy. TIus compuLuLIon cun onIy
meun Lo IInd un exucL represenLuLIon LIuL Is cs simple cs possible. WIen you
InpuL

56 vIu sqrl, MuPAD reLurns LIe IoIIowIng:


sqrl(56}
2

14
TIe resuIL oI LIe sImpIIIIcuLIon oI

56 Is LIe exucL vuIue 2

14. n MuPAD,

14
(or, someLImes, 14^(1/Z}) represenLs LIe posILIve soIuLIon oI LIe equuLIon
x
2
= 14. ndeed, LIIs Is probubIy LIe mosL sImpIe represenLuLIon oI LIe resuIL. We
sLress LIuL

14 Is u genuIne objecL wILI cerLuIn properLIes (e.g., LIuL ILs squure cun
be sImpIIIIed Lo 14). TIe sysLem uppIIes LIem uuLomuLIcuIIy wIen compuLIng wILI
sucI objecLs. or exumpIe:
sqrl(14}^4
196
-6
Compu|ing wi|h Numbers
As unoLIer exumpIe Ior exucL compuLuLIon, IeL us deLermIne LIe IImIL
e = IIm
n
_
1 +
1
n
_
n
.
We use LIe IuncLIon iimil und LIe symboI infinily:
iimil((1 + 1/n}^n n = infinily}
e
To enLer LIIs number In MuPAD, you Iuve Lo use E or exp(1}, wIere exp
represenLs LIe exponenLIuI IuncLIon. MuPAD knows exucL ruIes oI munIpuIuLIon
Ior LIIs objecL. or exumpIe, usIng LIe nuLuruI IogurILIm in we IInd:
in(1/exp(1}}
1
We wIII encounLer more exucL compuLuLIons IuLer In LIIs LuLorIuI.
Nomericul Approximutions
BesIdes exucL compuLuLIons, MuPAD cun uIso perIorm numerIcuI upproxImuLIons.
or exumpIe, you cun use LIe IuncLIon fiool Lo IInd u decImuI upproxImuLIon Lo

56. TIIs IuncLIon compuLes LIe vuIue oI ILs urgumenL In jloctin-point


representction:
fiool(sqrl(56}}
7.483314774
TIe precIsIon oI LIe upproxImuLIon depends on LIe vuIue oI LIe gIobuI vurIubIe
0TCTTS, wIIcI deLermInes LIe number oI decImuI dIgILs Ior numerIcuI
compuLuLIons. Ls deIuuIL vuIue Is 10:
0TCTTS fiool(67473/67Z}
10
10.02868609
-,
2 Firs| 5|eps in NuPAD

GIobuI vurIubIes sucI us 0TCTTS uIIecL LIe beIuvIor oI MuPAD, und ure uIso cuIIed
entironment tcricbles.
z
You IInd u compIeLe IIsL oI uII envIronmenL vurIubIes In
SecLIon EnvIronmenL VurIubIes oI LIe MuPAD QuIck ReIerence In LIe onIIne
documenLuLIon. TIe vurIubIe 0TCTTS cun ussume uny InLegruI vuIue beLween 1 und
2
32
1, uILIougI 1000 cun uIreudy be consIdered very Iurge und IL Is unIIkeIy LIuL
usIng more LIun 10 000 dIgILs Is reusonubIe Ior unyLIIng buL LIe mosL unusuuI
cuIcuIuLIons:
0TCTTS .= 100. fiool(67473/67Z} 0TCTTS .= 10.
10.0Z66079904751463Z50Z61593341Z60404Z0613115`
33ZZZ99643Z10737Z175909750Z97Z651605Z317
We Iuve reseL LIe vuIue oI 0TCTTS Lo 10 Ior LIe IoIIowIng compuLuLIons. TIIs cun
uIso be ucIIeved vIu LIe commund deiele 0TCTTS. or urILImeLIc operuLIons wILI
numbers, MuPAD uuLomuLIcuIIy uses upproxImuLe compuLuLIon us soon us ct
lecst one oI LIe numbers InvoIved Is u IIouLIng-poInL vuIue:
(1.0 + (5/Z*3}}/(1/7 + 7/9}^Z
10.02868609
PIeuse noLe LIuL none oI LIe Lwo IoIIowIng cuIIs
Z/3*sin(Z} 0.6666666666*sin(Z}
resuILs In un upproxImuLe compuLuLIon oI sIn(2), sInce, LecInIcuIIy, sin(Z} Is un
expressIon represenLIng LIe (exucL) vuIue oI sIn(2) und not u number:
Z/3*sin(Z} 0.6666666666*sin(Z}
2 sIn(2)
3
, 0.6666666666 sIn(2)
(TIe sepuruLIon oI boLI vuIues by u commu generuLes u specIuI duLu Lype, numeIy u
sequence, wIIcI Is descrIbed In SecLIon q..)
z
You sIouId be purLIcuIurIy cuuLIous wIen LIe sume compuLuLIon Is perIormed wILI dIIIerenL vuIues
oI 0TCTTS. Some oI LIe more InLrIcuLe numerIcuI uIgorILIms In MuPAD empIoy LIe opLIon remember.
TIIs ImpIIes LIuL LIey sLore prevIousIy compuLed vuIues Lo be used uguIn (SecLIon 1;.q), wIIcI cun Ieud
Lo InuccuruLe numerIcuI resuILs II LIe remembered vuIues were compuLed wILI Iower precIsIon. To be
suIe, you sIouId resLurL LIe MuPAD sessIon usIng resel(} beIore IncreusIng LIe vuIue oI 0TCTTS. TIIs
commund cIeurs memory und reseLs uII envIronmenL vurIubIes Lo LIeIr deIuuIL vuIues (SecLIon 1.q).
-S
Compu|ing wi|h Numbers
You Iuve Lo use LIe IuncLIon fiool Lo compuLe IIouLIng-poInL upproxImuLIons oI
LIe ubove expressIons:

fiool(Z/3*sin(Z}} 0.6666666666*fiool(sin(Z}}
0.6061982846, 0.6061982845
MosL urILImeLIc IuncLIons,sucI us LIe squure rooL, LIe LrIgonomeLrIc IuncLIons,
LIe exponenLIuI IuncLIon, or LIe IogurILIm, uuLomuLIcuIIy reLurn upproxImuLe
vuIues wIen LIeIr urgumenL Is u IIouLIng-poInL number:
sqrl(56.0} sin(3.14}
7.483314774, 0.001592652916
TIe consLunLs und e ure denoLed by PT und E=exp(1}, respecLIveIy. MuPAD cun
perIorm exucL compuLuLIons wILI LIem:
cos(PT} in(E}
1, 1
I desIred, you cun obLuIn numerIcuI upproxImuLIons oI LIese consLunLs by
uppIyIng fiool:
0TCTTS .= 100. fiool(PT} fiool(E} deiele 0TCTTS.
3.14159Z65359793Z346Z64333Z7950Z4197169399375105`
Z097494459Z30716406Z6Z0996Z034Z534Z11706
Z.71Z1Z459045Z35360Z747135Z66Z497757Z47093699959`
5749669676Z77Z40766303535475945713Z175Z51664Z7
Ixercise .: CompuLe

27 2

3 und cos(/8) exucLIy. DeLermIne numerIcuI


upproxImuLIons Lo u precIsIon oI dIgILs.
Complex Nombers
TIe ImugInury unIL

1 Is represenLed In MuPAD by LIe symboI T In LIe InpuL


und un uprIgIL I In LIe LypeseL ouLpuL:

Tuke u Iook uL LIe IusL dIgILs. TIe second commund yIeIds u sIIgILIy Iess uccuruLe resuIL, sInce
0.666 . . . Is uIreudy un upproxImuLIon oI 2/3 und LIe roundIng error Is propuguLed Lo LIe IInuI resuIL.
-q
2 Firs| 5|eps in NuPAD

sqrl(-1} T^Z
I, 1
You cun InpuL compIex numbers In LIe usuuI muLIemuLIcuI noLuLIon x +y I. BoLI
LIe reuI purL x und LIe ImugInury purL y muy be InLegers, ruLIonuI numbers, or
IIouLIng-poInL numbers:
(1 + Z*T}*(4 + T} (1/Z + T}*(0.1 + T/Z}^3
2 + 9 I, 0.073 0.129 I
I you use symboIIc expressIons sucI us, e.g., sqrl(Z}, MuPAD muy noL reLurn LIe
resuIL oI u cuIcuIuLIon In CurLesIun coordInuLes:
1/(sqrl(Z} + T}
1

2 + I
TIe IuncLIon reclform (sIorL Ior: recLunguIur Iorm) ensures LIuL LIe resuIL Is spIIL
InLo ILs reuI und ImugInury purLs:
reclform(1/(sqrl(Z} + T}}

2
3

I
3
TIe IuncLIons Re und Tm reLurn LIe reuI purL x und LIe ImugInury purL y,
respecLIveIy, oI u compIex number x +y I. TIe IuncLIons congugole, obs, und org
compuLe LIe compIex conjuguLe x y I, LIe ubsoIuLe vuIue |x +y I| =
_
x
2
+y
2
,
und LIe poIur ungIe, respecLIveIy:
Re(1/(sqrl(Z} + T}} Tm(1/(sqrl(Z} + T}}
congugole(1/(sqrl(Z} + T}}
obs(1/(sqrl(Z} + T}} org(1/(sqrl(Z} + T}}
reclform(congugole(1/(sqrl(Z} + T}}}

2
3
,
1
3
,
1

2 I
,

3
3
, urcLun
_

2
2
_
,

2
3
+
I
3
-1o
5ymbolic Compu|o|ion
$ymbelit fempuIuIiea
TIIs secLIon comprIses some exumpIes oI MuPAD

sessIons LIuL IIIusLruLe u smuII


seIecLIon oI LIe sysLem`s power Ior symboIIc munIpuIuLIon. TIe muLIemuLIcuI
knowIedge Is conLuIned essenLIuIIy In LIe MuPAD IuncLIons Ior dIIIerenLIuLIon,
InLegruLIon, sImpIIIIcuLIon oI expressIons eLc. TIIs demonsLruLIon does noL
proceed In u purLIcuIurIy sysLemuLIc munner: we uppIy LIe sysLem IuncLIons Lo
objecLs oI vurIous Lypes, sucI us sequences, seLs, IIsLs, expressIons eLc. TIey ure
expIuIned In deLuII one by one In CIupLer q.
Introdoctory Ixumples
A symboIIc expressIon muy conLuIn undeLermIned quunLILIes (IdenLIIIers). TIe
IoIIowIng expressIon conLuIns Lwo unknowns x und y:
f .= y^Z + 4*x + 6*x^Z + 4*x^3 + x^4
x
4
+ 4 x
3
+ 6 x
2
+ 4 x +y
2
UsIng LIe ussIgnmenL operuLor .=, we Iuve ussIgned LIe expressIon Lo un
IdenLIIIer f, wIIcI cun now be used us un ubbrevIuLIon Ior LIe expressIon. We suy
LIuL LIe IuLLer Is LIe tclue oI LIe IdenLIIIer f. We noLe LIuL MuPAD Ius excIunged
LIe order oI LIe Lerms.
q
MuPAD oIIers LIe sysLem IuncLIon diff Ior dIIIerenLIuLIng expressIons:
diff(f x} diff(f y}
4 x
3
+ 12 x
2
+ 12 x + 4, 2 y
Here, we Iuve compuLed boLI LIe derIvuLIve wILI respecL Lo x und Lo y. You muy
obLuIn IIgIer derIvuLIves eILIer by nesLed cuIIs oI diff, or by u sIngIe cuII:
diff(diff(diff(f x} x} x} = diff(f x x x}
24 x + 24 = 24 x + 24
q
nLernuIIy, symboIIc sums ure ordered uccordIng Lo cerLuIn ruIes LIuL enubIe LIe sysLem Lo uccess
LIe Lerms IusLer. OI course, sucI u reorderIng oI LIe InpuL Iuppens onIy Ior commuLuLIve operuLIons sucI
us, e.g., uddILIon or muILIpIIcuLIon, wIere cIungIng LIe order oI LIe operunds yIeIds u muLIemuLIcuIIy
equIvuIenL objecL.
-11
2 Firs| 5|eps in NuPAD

AILernuLIveIy, you cun use LIe dIIIerenLIuI operuLor , wIIcI mups u IuncLIon Lo ILs
derIvuLIve:
sin sin(x}
cos, cos(x)
TIe symboI Ior LIe derIvuLIve Is u sIorL Iorm oI LIe dIIIerenLIuI operuLor 0. TIe
cuII 0(funclion} reLurns LIe derIvuLIve:
0(sin} 0(sin}(x}
cos, cos(x)
NoLe: MuPAD uses u muLIemuLIcuIIy sLrIcL noLuLIon Ior LIe dIIIerenLIuI operuLor: 0
(or, equIvuIenLIy, LIe operuLor) dIIIerenLIuLes IuncLIons, wIIIe diff dIIIerenLIuLes
expressIons. n LIe exumpIe, LIe mups LIe (nume oI LIe) IuncLIon Lo LIe (nume
oI LIe) IuncLIon represenLIng LIe derIvuLIve. You oILen IInd u sIoppy noLuLIon sucI
us, e.g., (x +x
2
)

Ior LIe derIvuLIve oI LIe IuncLIon F : x x +x


2
. TIIs noLuLIon
conIuses LIe mup F und LIe Imuge poInL f = F(x) uL u poInL x. MuPAD Ius u
sLrIcL dIsLIncLIon beLween LIe junction F und LIe expression f = F(x), wIIcI ure
reuIIzed us dIIIerenL duLu Lypes. TIe mup correspondIng Lo f cun be deIIned by
F .= x -> x + x^Z.
TIen
diff(f x} = F(x}
2 x + 1 = 2 x + 1
ure equIvuIenL wuys oI obLuInIng LIe derIvuLIve us expressIons. TIe cuII
f.=x+x^Z f does noL muke sense In MuPAD.
You cun compuLe InLegruIs by usIng inl. TIe IoIIowIng commund compuLes u
deIInILe InLegruI on LIe reuI InLervuI beLween 0 und 1:
inl(f x = 0..1}
y
2
+
26
5
-1
5ymbolic Compu|o|ion
TIe nexL commund deLermInes un IndeIInILe InLegruI und reLurns un expressIon
conLuInIng LIe InLegruLIon vurIubIe x und u symboIIc purumeLer y:
inl(f x}
x
5
5
+x
4
+ 2 x
3
+ 2 x
2
+xy
2
NoLe LIuL inl reLurns u specIuI unLIderIvuLIve, noL u generuI one (wILI uddILIve
consLunL).
I you Lry Lo compuLe LIe IndeIInILe InLegruI oI un expressIon und IL cunnoL be
represenLed by eIemenLury IuncLIons, LIen inl reLurns LIe cuII symboIIcuIIy:
inlegroi .= inl(1/(exp(x^Z} + 1} x}
_
1
e
x
2
+ 1
dx
NeverLIeIess, LIIs objecL Ius muLIemuLIcuI properLIes. TIe dIIIerenLIuLor
recognIzes LIuL ILs derIvuLIve Is LIe InLegrund:
diff(inlegroi x}
1
e
x
2
+ 1
DeIInILe InLegruIs muy uIso be reLurned symboIIcuIIy by inl:
inl(1/(exp(x^Z} + 1} x = 0..1}
_
1
0
1
e
x
2
+ 1
dx
TIe correspondIng muLIemuLIcuI objecL Is u reuI number, und LIe ouLpuL Is un
exucL represenLuLIon oI LIIs number, wIIcI MuPADwus unubIe Lo sImpIIIy IurLIer.
As usuuI, you cun obLuIn u IIouLIng-poInL upproxImuLIon by uppIyIng fiool:
fiool(x}
0.41946648
As uIreudy noLed, LIe symboI x Is un ubbrevIuLIon Ior LIe prevIousIy compuLed
expressIon (CIupLer 1.z).
MuPAD knows LIe mosL ImporLunL muLIemuLIcuI IuncLIons sucI us LIe squure
-1
2 Firs| 5|eps in NuPAD

rooL sqrl, LIe exponenLIuI IuncLIon exp, LIe LrIgonomeLrIc IuncLIons sin, cos, lon,
LIe IyperboIIc IuncLIons sinh, cosh, lonh, LIe correspondIng Inverse IuncLIons in,
orcsin, orccos, orclon, orcsinh, orccosh, orclonh, us weII us u vurIeLy oI oLIer
specIuI IuncLIons sucI us, e.g., LIe gummu IuncLIon, LIe error IuncLIon erf, BesseI
IuncLIons (besseiT, besseiJ, .), eLc. (SecLIon SpecIuI MuLIemuLIcuI uncLIons
oI LIe MuPAD QuIck ReIerence gIves u survey.) n purLIcuIur, MuPAD knows LIe
ruIes oI munIpuIuLIon Ior LIese IuncLIons (e.g., LIe uddILIon LIeorems Ior LIe
LrIgonomeLrIc IuncLIons) und uppIIes LIem. L cun compuLe IIouLIng-poInL
upproxImuLIons sucI us, e.g., fiool(exp(1}}=Z.71..., und knows specIuI
vuIues (e.g., sin(PT}=0).
I you cuII LIese IuncLIons, LIey oILen reLurn LIemseIves symboIIcuIIy, sInce LIIs Is
LIe mosL sImpIe exucL represenLuLIon oI LIe correspondIng vuIue:
sqrl(Z} exp(1} sin(x + y}

2, e, sIn(x +y)
or muny users, LIe muIn IeuLure oI LIe sysLem Is Lo sImpIIIy or LrunsIorm sucI
expressIons usIng LIe ruIes Ior compuLuLIon. or exumpIe, LIe sysLem IuncLIon
expond expunds IuncLIons sucI us exp, sin, eLc. by meuns oI LIe uddILIon
LIeorems II LIeIr urgumenL Is u symboIIc sum:
expond(exp(x + y}} expond(sin(x + y}}
expond(lon(x + 3*PT/Z}}
e
x
e
y
, cos(x) sIn(y) +cos(y) sIn(x) ,
1
Lun(x)
GeneruIIy speukIng, one oI LIe muIn Lusks oI u compuLer uIgebru sysLem Is Lo
munIpuIuLe und Lo sImpIIIy expressIons. BesIdes expond, MuPAD provIdes LIe
IuncLIons coiiecl, combine, foclor, normoi, porlfroc, rodsimp, reWrile,
simpiify, und Simpiify Ior munIpuIuLIon. TIey ure presenLed In greuLer deLuII In
CIupLer q. We brIeIIy menLIon some oI LIem In wIuL IoIIows.
TIe IuncLIon normoi IInds u common denomInuLor Ior ruLIonuI expressIons:
f .= x/(1 + x} - Z/(1 - x}. g .= normoi(f}
x
2
+x + 2
x
2
1
-1q
5ymbolic Compu|o|ion
Moreover, normoi uuLomuLIcuIIy cunceIs common IucLors In LIe numeruLor und
LIe denomInuLor:
normoi(x^Z/(x + y} - y^Z/(x + y}}
x y
ConverseIy, porlfroc (sIorL Ior purLIuI IrucLIon) decomposes u ruLIonuI
expressIon InLo u sum oI ruLIonuI Lerms wILI sImpIe denomInuLors:
porlfroc(g x}
2
x 1

1
x + 1
+ 1
TIe IuncLIons simpiify und Simpiify ure unIversuI sImpIIIIers und Lry Lo IInd u
represenLuLIon LIuL Is us sImpIe us possIbIe:
simpiify((exp(x} - 1}/(exp(x/Z} + 1}}
e
x
2
1
You muy conLroI LIe sImpIIIIcuLIon by suppIyIng simpiify or Simpiify wILI
uddILIonuI urgumenLs (see LIe onIIne documenLuLIon Ior deLuIIs).
TIe IuncLIon rodsimp sImpIIIIes urILImeLIcuI expressIons conLuInIng rudIcuIs
(rooLs):
f .= sqrl(4 + Z*sqrl(3}}. f = rodsimp(f}

2
_

3 + 2 =

3 + 1
Here, we Iuve generuLed un equuLIon, wIIcI Is u genuIne MuPAD objecL.
AnoLIer ImporLunL IuncLIon Is foclor, wIIcI decomposes un expressIon InLo u
producL oI sImpIer ones:
foclor(x^3 + 3*x^Z + 3*x + 1}
foclor(Z*x*y - Z*x - Z*y + x^Z + y^Z}
foclor(x^Z/(x + y} - z^Z/(x + y}}
(x + 1)
3
, (x +y 2) (x +y) ,
(x z) (x +z)
(x +y)
-1g
2 Firs| 5|eps in NuPAD

TIe IuncLIon iimil does wIuL ILs nume suggesLs. or exumpIe, LIe IuncLIon
sIn(x)/x Ius u removubIe poIe uL x = 0. Ls IImIL Ior x 0 Is 1:
iimil(sin(x}/x x = 0}
1
n u MuPAD sessIon, you cun deIIne IuncLIons oI your own In severuI wuys. A
sImpIe und InLuILIve meLIod Is Lo use LIe urrow operuLor -> (LIe mInus symboI
IoIIowed by LIe greuLer LIun symboI):
F .= x -> (x^Z}. F(x} F(y} F(o + b} F(x}
x
2
, y
2
, (a +b)
2
, 2 x
n CIupLer 1;, we dIscuss MuPAD progrummIng IeuLures und descrIbe Iow Lo
ImpIemenL more compIex uIgorILIms us MuPAD procedures.
You cun uIso use LIe grupIIcs IucIIILIes Lo vIsuuIIze muLIemuLIcuI objecLs
ImmedIuLeIy. TIe reIevunL MuPAD IuncLIons Ior generuLIng grupIIcs ure LIe piol
commund und LIe rouLInes Irom LIe grupIIcs IIbrury piol. Here, we presenL
sImpIe cuIIs onIy, pIeuse consuIL CIupLer 11 Ior In-depLI InIormuLIon:
piol(sin(x^Z} x = -Z..5}
-16
5ymbolic Compu|o|ion
piol(sin(x^Z + y^Z} x = 0..PT y = 0..PT #30}
SoIvIng equuLIons or sysLems oI equuLIons Is cerLuInIy un ImporLunL Lusk Ior u
compuLer uIgebru sysLem. TIIs Is done vIu soive:
equolions .= {x + y = o x - o*y = b].
unknoWns .= {x y].
soive(equolions unknoWns TgnoreSpecioiCoses}
__
x =
a
2
+b
a + 1
, y =
a b
a + 1
__
Here, we Iuve generuLed u seL oI Lwo equuLIons und u seL oI unknowns wIIcI we
wIsI Lo soIve Ior. soive reLurns LIe resuIL In Lerms oI sImpIIIIed equuLIons, Irom
wIIcI you cun reud oII LIe soIuLIon. n LIe ubove exumpIe, LIere ure Lwo more
symboIIc purumeLers a und b. TIIs Is wIy we Iuve LoId soive wIIcI oI LIe symboIs
IL sIouId express In Lerms oI LIe oLIers. TIe opLIon TgnoreSpecioiCoses LeIIs
MuPAD Lo Ignore LIe possIbIIILy LIuL o couId be 1, wIere LIe ubove soIuLIon
wouId be IncorrecL. WILIouL LIIs opLIon, MuPAD reLurns u compIeLe soIuLIon wILI
LIree bruncIes:
-1,
2 Firs| 5|eps in NuPAD

soive(equolions unknoWns}
_

_
__
x =
a
2
+b
a+1
, y =
ab
a+1
__
II a = 1
{[x = z 1, y = z]} II a = 1 b = 1
II a = 1 b = 1
n LIe IoIIowIng exumpIe, we Iuve onIy one equuLIon In one unknown. MuPAD
uuLomuLIcuIIy recognIzes LIe unknown und soIves Ior IL:
soive(x^Z - Z*x + Z = 0}
{[x = 1 I] , [x = 1 + I]}
I we suppIy LIe unknown x Lo soIve Ior, LIe IormuL oI LIe ouLpuL cIunges:
soive(x^Z - Z*x + Z = 0 x}
{1 I, 1 + I}
TIe resuIL Is u seL conLuInIng LIe Lwo (compIex) soIuLIons oI LIe quudruLIc
equuLIon. You IInd u deLuIIed descrIpLIon oI soive In CIupLer 8.
TIe IuncLIons sum und producl IundIe symboIIc sums und producLs. or exumpIe,
LIe weII-known sum 1 + 2 + +n Is:
sum(i i = 1..n}
n (n + 1)
2
TIe producL 1 2 n Is known us IucLorIuI n!:
producl(i^3 i = 1..n}
n!
3
-1S
5ymbolic Compu|o|ion
TIere exIsL severuI duLu sLrucLures Ior vecLors und muLrIces. n prIncIpIe, you muy
use urruys (SecLIon q.q) Lo represenL sucI objecLs. However, IL Is Iur more InLuILIve
Lo work wILI LIe duLu Lype muLrIx. You cun generuLe muLrIces by usIng LIe
sysLem IuncLIon molrix:
A .= molrix(__1 Z] _o 4]]}
_
1 2
a 4
_
MuLrIx objecLs consLrucLed LIIs wuy Iuve LIe convenIenL properLy LIuL LIe busIc
urILImeLIc operuLIons +, *, eLc. ure specIuIIzed (overIouded) uccordIng Lo LIe
upproprIuLe muLIemuLIcuI conLexL. or exumpIe, you muy use + or * Lo udd or
muILIpIy muLrIces, respecLIveIy (II LIe dImensIons muLcI):
B .= molrix(__y 3] _z 5]]}.
A B A + B A*B
_
1 2
a 4
_
,
_
y 3
z 5
_
,
_
y + 1 5
a +z 9
_
,
_
y + 2 z 13
4 z +a y 3 a + 20
_
TIe power A^(-1}, equIvuIenL Lo 1/A, denoLes LIe Inverse oI LIe muLrIx:
A^(-1}
_

2
a2
1
a2
a
2 a4

1
2 a4
_
TIe IuncLIon iinoig..del, Irom LIe MuPAD iinoig IIbrury Ior IIneur uIgebru
(SecLIon q.1), compuLes LIe deLermInunL:
iinoig..del(A}
4 2 a
CoIumn vecLors oI dImensIon n cun be InLerpreLed us n 1 muLrIces:
b .= molrix(_1 x]}
_
1
x
_
-1q
2 Firs| 5|eps in NuPAD

You cun comIorLubIy deLermIne LIe soIuLIon A


1

b oI LIe sysLem oI IIneur


equuLIons Ax =

b, wILI LIe ubove coeIIIcIenL muLrIx A und LIe prevIousIy deIIned

b
on LIe rIgIL-Iund sIde:
soiulionveclor .= A^(-1}*b
_
x
a2

2
a2
a
2 a4

x
2 a4
_
Now you cun uppIy LIe IuncLIon normoi Lo eucI componenL oI LIe vecLor by meuns
oI LIe sysLem IuncLIon mop, LIus sImpIIIyIng LIe represenLuLIon:
mop(x normoi}
_
x2
a2
ax
2 a4
_
To verIIy LIe compuLuLIon, you muy muILIpIy LIe soIuLIon vecLor by LIe muLrIx A:
A * x
_
x2
a2
+
2 (ax)
2 a4
4 (ax)
2 a4
+
a (x2)
a2
_
AILer sImpIIIIcuLIon, you cun cIeck LIuL LIe resuIL equuIs b:
mop(x normoi}
_
1
x
_
SecLIon q.1 provIdes more InIormuLIon on IundIIng muLrIces und vecLors.
Ixercise .: CompuLe un expunded Iorm oI LIe expressIon (x
2
+y)
5
.
Ixercise .q: Use MuPAD Lo cIeck LIuL
x
2
1
x + 1
= x 1 IoIds.
Ixercise .g: GeneruLe u pIoL oI LIe IuncLIon 1/ sIn(x) Ior 1 x 10 .
-o
5ymbolic Compu|o|ion
Ixercise .6: ObLuIn deLuIIed InIormuLIon ubouL LIe IuncLIon iimil. Use
MuPAD Lo verIIy LIe IoIIowIng IImILs:
IIm
x0
sIn(x)
x
= 1 , IIm
x0
1 cos(x)
x
= 0 , IIm
x0+
In(x) = ,
IIm
x0
x
sIn(x)
= 1 , IIm
x
_
1 +
1
x
_
x
= e , IIm
x
In(x)
e
x
= 0 ,
IIm
x0+
x
In(x)
= , IIm
x
_
1 +

x
_
x
= e

, IIm
x0
2
1 +e
1/x
= 0 .
TIe IImIL IIm
x0
e
coL(x)
does noL exIsL. How does MuPAD reucL?
Ixercise .,: ObLuIn deLuIIed InIormuLIon ubouL LIe IuncLIon sum. TIe cuII
sum(f(k}k=o..b} compuLes u closed jorm oI u IInILe or InIInILe sum, II possIbIe.
Use MuPAD Lo verIIy LIe IoIIowIng IdenLILy:
n

k=1
(k
2
+k + 1) =
n(n
2
+ 3 n + 5)
3
.
DeLermIne LIe vuIues oI LIe IoIIowIng serIes:

k=0
2 k 3
(k + 1) (k + 2) (k + 3)
,

k=2
k
(k 1)
2
(k + 1)
2
.
Ixercise .S: CompuLe 2 (A+B), A B, und (AB)
1
Ior LIe IoIIowIng
muLrIces:
A =
_
_
1 2 3
4 5 6
7 8 0
_
_
, B =
_
_
1 1 0
0 0 1
0 1 0
_
_
.
Corve Sketching
n LIe IoIIowIng sumpIe sessIon, we use some oI LIe sysLem IuncLIons Irom LIe
prevIous secLIon Lo skeLcI und dIscuss LIe curve gIven by LIe ruLIonuI IuncLIon
f : x
(x 1)
2
x 2
+a
-1
2 Firs| 5|eps in NuPAD

wILI u purumeLer a. IrsL, we deLermIne some cIurucLerIsLIcs oI LIIs IuncLIon:


dIsconLInuILIes, exLremuI vuIues, und beIuvIor Ior Iurge x. We ussume LIuL a Is u
reuI number.
ossume(o in R}.
f .= x -> (x - 1}^Z/(x - Z} + o.
singuiorilies .= disconl(f(x} x}
{2}
TIe IuncLIon disconl deLermInes LIe dIsconLInuILIes oI LIe IuncLIon f wILI
respecL Lo LIe vurIubIe x. L reLurns u seL oI sucI poInLs. TIus, LIe ubove f Is
deIIned und conLInuous Ior uII x = 2. ObvIousIy, x = 2 Is u poIe. ndeed, MuPAD

IInds LIe IImIL wIen you upproucI LIIs poInL Irom LIe IeIL or Irom LIe rIgIL,
respecLIveIy:
iimil(f(x} x = Z Lefl} iimil(f(x} x = Z Righl}
,
You IInd LIe rooLs oI f by soIvIng LIe equuLIon f(x) = 0:
rools .= soive(f(x} = 0 x}
_
1

a
2
+ 4 a
2

a
2
,

a
2
+ 4 a
2

a
2
+ 1
_
DependIng on a, eILIer boLI or none oI LIe Lwo rooLs ure reuI. Now, we wunL Lo
IInd LIe IocuI exLremu oI f. To LIIs end, we deLermIne LIe rooLs oI LIe IIrsL
derIvuLIve f

:
f(x}
2 x 2
x 2

(x 1)
2
(x 2)
2
exlremo .= soive(f(x} = 0 x}
{1, 3}
TIese ure LIe cundIduLes Ior IocuI exLremu. However, some oI LIem mIgIL be
suddIe poInLs. I LIe second derIvuLIve f

does noL vunIsI uL LIese poInLs, LIen


boLI ure reuIIy exLremu. We cIeck:
-
5ymbolic Compu|o|ion
f(1} f(3}
2, 2
Our resuILs ImpIy LIuL f Ius LIe IoIIowIng properLIes: Ior uny cIoIce oI LIe
purumeLer a, LIere Is u IocuI muxImum uL x = 1, u poIe uL x = 2, und u IocuI
mInImum uL x = 3. TIe correspondIng vuIues oI f uL LIese poInLs ure
moxvoiue .= f(1} minvoiue .= f(3}
a
a + 4
f Lends Lo Ior x :
iimil(f(x} x = -infinily} iimil(f(x} x = infinily}
,
We cun specIIy LIe beIuvIor oI f more precIseIy Ior Iurge vuIues oI x. L
usympLoLIcuIIy upproucIes LIe IIneur IuncLIon x x +a:
series(f(x} x = infinily}
x +a +
1
x
+
2
x
2
+
4
x
3
+
8
x
4
+O
_
1
x
5
_
Here we Iuve empIoyed LIe IuncLIon series Lo compuLe un usympLoLIc expunsIon
oI f (SecLIon q.1). We cun eusIIy cIeck our resuILs vIsuuIIy by pIoLLIng LIe grupI
oI f Ior severuI vuIues oI a:
F .= f(x} 1 o = -4. C .= f(x} 1 o = 0. | .= f(x} 1 o = 4.
F C |
(x 1)
2
x 2
4,
(x 1)
2
x 2
,
(x 1)
2
x 2
+ 4
TIe operuLor 1 (CIupLer 6) evuIuuLes un expressIon uL some poInL: In LIe exumpIe,
we Iuve subsLILuLed LIe concreLe vuIues 4, 0 und 4, respecLIveIy, Ior a. We now
cun pIoL LIe LIree IuncLIons LogeLIer In one pIcLure:
-
2 Firs| 5|eps in NuPAD

piol(F C | x = -1..4}
Ilementury Nomber Theory
MuPAD

provIdes u IoL oI eIemenLury number LIeoreLIc IuncLIons, Ior exumpIe:


isprime(n} LesLs wIeLIer n N Is u prIme number,
ilhprime(n} reLurns LIe n-LI prIme number,
nexlprime(n} IInds LIe IeusL prIme number n,
prevprime(n} IInds LIe IurgesL prIme number n,
ifoclor(n} compuLes LIe prIme IucLorIzuLIon oI n.
TIese rouLInes ure quILe IusL. However, sInce LIey empIoy probubIIIsLIc prImuIILy
LesLs, LIey muy reLurn wrong resuILs wILI very smuII probubIIILy.

nsLeud oI
isprime, you cun use LIe (sIower) IuncLIon numiib..proveprime us un error-Iree
prImuIILy LesL.

n prucLIce, you need noL worry ubouL LIIs becuuse LIe cIunces oI u wrong unswer ure negIIgIbIe:
LIe probubIIILy oI u Iurdwure IuIIure Is mucI IIgIer LIun LIe probubIIILy LIuL LIe rundomIzed LesL reLurns
LIe wrong unswer on correcLIy workIng Iurdwure.
-q
5ymbolic Compu|o|ion
eL us generuLe u IIsL oI uII prImes up Lo 10 000. Here Is one oI muny wuys Lo do
LIIs:
primes .= seiecl(_S 1..10000] isprime}
_Z 3 5 7 11 13 17 ... 9949 9967 9973]
IrsL, we Iuve generuLed LIe sequence oI uII posILIve InLegers up Lo 10 000 by
meuns oI LIe sequence generuLor S (SecLIon q.). TIe squure bruckeLs _] converL
LIIs Lo u MuPAD IIsL. TIen seiecl (SecLIon q.6) eIImInuLes uII LIose IIsL eIemenLs
Ior wIIcI LIe IuncLIon isprime, suppIIed us second urgumenL, reLurns FALSE. TIe
number oI LIese prImes equuIs LIe number oI IIsL eIemenLs, wIIcI we cun obLuIn
vIu nops (number oI operunds, SecLIon q.1):
nops(primes}
1229
AILernuLIveIy, we muy generuLe LIe sume prIme IIsL by
primes .= _ilhprime(i} S i = 1..1ZZ9].
Here we Iuve used LIe IucL LIuL we uIreudy know LIe number oI prImes up Lo
10 000. AnoLIer possIbIIILy Is Lo generuLe u Iurge IIsL oI prImes und dIscurd LIe
ones greuLer LIun 10 000:
primes .= seiecl(_ilhprime(i} S i=1..5000]
x -> (x<=10000}}.
Here, LIe objecL x ->(x<=10000} represenLs LIe IuncLIon LIuL mups eucI x Lo LIe
InequuIILy x<=10000. TIe seiecl commund LIen keeps onIy LIose IIsL eIemenLs
Ior wIIcI LIe InequuIILy evuIuuLes Lo TRuE.
n LIe nexL exumpIe, we use u repeol Ioop (CIupLer 1) Lo generuLe LIe IIsL oI
prImes. WILI LIe IeIp oI LIe concuLenuLIon operuLor . (SecLIon q.6), we
successIveIy uppend prImes i Lo u IIsL unLII nexlprime(i+1}, LIe nexL prIme greuLer
LIun i, exceeds 10 000. We sLurL wILI LIe empLy IIsL und LIe IIrsL prIme i = 2:
primes .= _]. i .= Z.
repeol
primes .= primes . _i]
i .= nexlprime(i + 1}
unlii i > 10000 endrepeol.
-g
2 Firs| 5|eps in NuPAD

Now, we consIder GoIdbucI`s Iumous conjecLure:


Every even InLeger greuLer LIun 2 Is LIe sum oI Lwo prImes.
We wunL Lo verIIy LIIs conjecLure Ior uII even numbers up Lo 10 000. IrsL, we
generuLe LIe IIsL oI even InLegers _46.10000]:
iisl .= _Z*i S i = Z..5000].
nops(iisl}
4999
Now, we seIecL LIose numbers Irom LIe IIsL LIuL cunnoL be wrILLen In LIe Iorm
prIme + z. TIIs Is done by LesLIng Ior eucI i In LIe IIsL wIeLIer i 2 Is u prIme:
iisl .= seiecl(iisl i -> (nol isprime(i - Z}}}.
nops(iisl}
4998
TIe onIy InLeger LIuL Ius been eIImInuLed Is 4 (sInce Ior uII oLIer even posILIve
InLegers i 2 Is even und greuLer LIun 2, und Ience noL prIme). Now we dIscurd uII
numbers oI LIe Iorm prIme + :
iisl .= seiecl(iisl i -> (nol isprime(i - 3}}}.
nops(iisl}
3770
TIe remuInIng 3770 InLegers ure neILIer oI LIe Iorm prIme + z nor oI LIe Iorm
prIme + . We now conLInue LIIs procedure by meuns oI u Whiie Ioop
(CIupLer 1). n LIe Ioop, j successIveIy runs LIrougI uII prImes > 3, und LIe
numbers oI LIe Iorm prIme + j ure eIImInuLed. A prinl commund (SecLIon 1z.1)
ouLpuLs LIe number oI remuInIng InLegers In eucI sLep. TIe Ioop ends us soon us
LIe IIsL Is empLy:
g .= 3.
-6
5ymbolic Compu|o|ion
Whiie iisl <> _] do
g .= nexlprime(g + 1}.
iisl .= seiecl(iisl i -> (nol isprime(i - g}}}.
prinl(g nops(iisl}}.
endWhiie.
5 Z747
7 19Z6
11 1400
...
163 1
167 1
173 0
TIus we Iuve conIIrmed LIuL GoIdbucI`s conjecLure IoIds Lrue Ior uII even
posILIve InLegers up Lo 10 000. We Iuve even sIown LIuL uII LIose numbers cun be
wrILLen us u sum oI u prIme Iess or equuI Lo 173 und unoLIer prIme.
n LIe nexL exumpIe, we generuLe u IIsL oI dIsLunces beLween Lwo successIve prImes
up Lo 500:
primes .= seiecl(_S 1..500] isprime}.
dislonces .= _primes_i] - primes_i - 1]
S i = Z..nops(primes}]
_1 Z Z 4 Z 4 Z 4 6 Z 6 4 Z 4 6 6 Z
6 4 Z 6 4 6 4 Z 4 Z 4 14 4 6 Z
10 Z 6 6 4 6 6 Z 10 Z 4 Z 1Z 1Z 4
Z 4 6 Z 10 6 6 6 Z 6 4 Z 10 14 4 Z
4 14 6 10 Z 4 6 6 6 4 6 4 10
Z 10 Z 6 4 6 4 Z 4 1Z 4 ]
TIe Indexed cuII primes_i] reLurns LIe iLI eIemenL In LIe IIsL.
-,
2 Firs| 5|eps in NuPAD

TIe IuncLIon zip (SecLIon q.6) provIdes un uILernuLIve meLIod. TIe cuII
zip(obf} combInes Lwo IIsLs a = [a
1
, a
2
, . . . ] und b = [b
1
, b
2
, . . . ]
componenLwIse by meuns oI LIe IuncLIon f: LIe resuILIng IIsL Is
[f(a
1
, b
1
), f(a
2
, b
2
), . . . ]
und Ius us muny eIemenLs us LIe sIorLer oI LIe Lwo IIsLs. n our exumpIe, we uppIy
LIIs Lo LIe prIme IIsL a = [a
1
, . . . , a
n
], LIe sIIILed prIme IIsL b = [a
2
, . . . , a
n
], und
LIe IuncLIon (x, y) y x. We IIrsL generuLe u sIIILed copy oI LIe prIme IIsL by
deIeLIng LIe IIrsL eIemenL, LIus sIorLenIng LIe IIsL:
b .= primes. deiele b_1].
TIe IoIIowIng commund reLurns LIe sume resuIL us ubove:
dislonces .= zip(primes b (x y} -> (y - x}}.
We Iuve presenLed unoLIer useIuI IuncLIon In SecLIon z., LIe rouLIne ifoclor Ior
IucLorIng un InLeger InLo prImes. TIe cuII ifoclor(n} reLurns un objecL oI LIe
sume Lype us foclor: IL Is u specIuI duLu Lype cuIIed Foclored. ObjecLs oI LIIs Lype
ure prInLed on LIe screen In u Iorm LIuL Is eusIIy reudubIe:
ifoclor(-1Z345679}
3
2
3607 3803
nLernuIIy, LIe prIme IucLors und LIe exponenLs ure sLored In Iorm oI u IIsL, und
you cun exLrucL LIem by usIng op or by un Indexed uccess. ConsuIL LIe IeIp puges
oI ifoclor und Foclored Ior deLuIIs. TIe InLernuI IIsL Ius LIe IormuL
[s, p
1
, e
1
, . . . , p
k
, e
k
]
wILI prImes p
1
, . . . , p
k
, LIeIr exponenLs e
1
, . . . , e
k
, und LIe sIgn s = 1, sucI LIuL
n = s p
e
1
1
p
e
2
2
p
e
k
k
:
op(x}
1, 3, 2, 3607, 1, 3803, 1
-S
5ymbolic Compu|o|ion
We now empIoy LIe IuncLIon ifoclor Lo IInd ouL Iow muny InLegers beLween 2
und 10 000 ure dIvIsIbIe by exucLIy Lwo dIsLIncL prIme numbers. We noLe LIuL LIe
objecL reLurned by ifoclor(n} Ius 2 m+ 1 eIemenLs In ILs IIsL represenLuLIon,
wIere m Is LIe number oI dIsLIncL prIme dIvIsors oI n. TIus, LIe IuncLIon
m .= n -> (nops(ifoclor(n}} - 1}/Z.
reLurns LIe number oI dIsLIncL prIme IucLors. We consLrucL LIe IIsL oI vuIues m(k)
Ior k = 2, . . . , 10000:
iisl .= _m(k} S k = Z..10000].
TIe IoIIowIng for Ioop (SecLIon 1) dIspIuys LIe number oI InLegers wILI precIseIy
i = 1, 2, . . . , 6 dIsLIncL prIme dIvIsors:
for i from 1 lo 6 do
prinl(i nops(seiecl(iisl x -> (x = i}}}}
endfor.
1 1Z0
Z 4097
3 3695
4 94
5 33
6 0
TIus LIere ure 1280 InLegers wILI exucLIy one prIme dIvIsor In LIe scunned
InLervuI,
6
4097 InLegers wILI precIseIy Lwo dIsLIncL prIme IucLors, und so on. L Is
eusy Lo see wIy LIe InLervuI conLuIns no InLeger wILI sIx or more prIme dIvIsors:
LIe smuIIesL sucI number 2 3 5 7 11 13 = 30 030 exceeds 10 000.
TIe numiib IIbrury comprIses vurIous number LIeoreLIc IuncLIons. Among oLIers,
IL conLuIns LIe rouLIne numiib..numprimedivisors, equIvuIenL Lo LIe ubove m, Ior
compuLIng LIe number oI prIme dIvIsors. We reIer Lo CIupLer Ior u descrIpLIon
oI LIe MuPAD IIbrurIes.
6
We Iuve uIreudy seen LIuL LIe InLervuI conLuIns 1229 prIme numbers. Cun you expIuIn LIe dII-
Ierence?
-q
2 Firs| 5|eps in NuPAD

Ixercise .q: PrImes oI LIe Iorm 2


n
1 uIwuys Iuve produced purLIcuIur
InLeresL.
u) PrImes oI LIe Iorm 2
p
1, wIere p Is u prIme, ure cuIIed Mersenne primes.
Ind uII Mersenne prImes Ior 1 < p 1000.
b) or u posILIve InLeger n, LIe n-th Iermct number Is 2
(2
n
)
+ 1. ReIuLe
ermuL`s conjecLure LIuL uII LIose numbers ure prImes.
-o
3
The MoPA

Libruries
MosL oI MuPAD

`s muLIemuLIcuI knowIedge Is orgunIzed In IIbrurIes. SucI u


IIbrury comprIses u coIIecLIon oI IuncLIons Ior soIvIng probIems In u purLIcuIur
ureu, sucI us IIneur uIgebru, number LIeory, numerIcuI unuIysIs, eLc. Ibrury
IuncLIons ure wrILLen In LIe MuPAD progrummIng Iunguuge. You cun use LIem In
LIe sume wuy us kerneI IuncLIons, wILIouL knowIng unyLIIng ubouL LIe
progrummIng Iunguuge.
SecLIon IbrurIes und ModuIes oI LIe MuPAD QuIck ReIerence conLuIns u survey
oI uII IIbrurIes. AILernuLIveIy, LIe IeIp vIewer conLuIns u IIsL oI IIbrurIes (und
LIIrd-purLy puckuges InsLuIIed) In ILs conLenLs pune on LIe IeIL.
TIe IIbrurIes ure deveIoped conLInuousIy, und IuLure versIons oI MuPAD wIII
provIde uddILIonuI IuncLIonuIILy.
n LIIs cIupLer, we do noL uddress LIe muLIemuLIcuI IuncLIonuIILy oI IIbrurIes buL
ruLIer dIscuss LIeIr generuI use.
3 The NuPAD

Iibrories
lalermuIiea kbeuI u FurIitulur librury
You cun obLuIn InIormuLIon und IeIp Ior IIbrurIes by cuIIIng LIe IuncLIons info
und heip. TIe IuncLIon info gIves u IIsL oI uII IuncLIons InsLuIIed In LIe IIbrury.
TIe numiib IIbrury Is u coIIecLIon oI number LIeoreLIc IuncLIons:
info(numiib}
Librory numiib. lhe pockoge for eiemenlory
number lheory
-- Tnlerfoce.
numiib..Lombdo numiib..0mego
numiib..conlfroc numiib..cornocchio
numiib..decimoi numiib..divisors
numiib..ecm numiib..foclorCoussTnl
numiib..fibonocci numiib..fromAscii
...
TIe communds heip or ? suppIy u more deLuIIed descrIpLIon oI LIe IIbrury.
TIe IuncLIon numiib..decimoi oI LIe numiib IIbrury compuLes LIe decImuI
expunsIon oI u ruLIonuI number:
1
numiib..decimoi(1Z3/7}
17, [5, 7, 1, 4, 2, 8]
As Ior oLIer sysLem IuncLIons, you wIII see InIormuLIon wIen IoverIng your mouse
poInLer over LIe nume oI u IIbrury IuncLIon und you muy requesL InIormuLIon on
LIe IuncLIon by meuns oI heip or ?:
?numiib..decimoi
1
TIe resuIL Is Lo be InLerpreLed us: 123/7 = 17.571428 = 17.571428 571428 . . .
-
Inlormo|ion Abou| o Por|iculor Iibrory
You cun Iuve u Iook uL LIe ImpIemenLuLIon oI u IIbrury IuncLIon by usIng expose:
expose(numiib..decimoi}
proc(o}
nome numiib..decimoi
iocoi p q s i i
begin
if nol lesllype(o Type..Wumeric} lhen
...
endproc
-
3 The NuPAD

Iibrories
xperIiag libruries
n LIe prevIous secLIon, you Iuve seen LIuL LIe cuIIIng synLux Ior u IIbrury IuncLIon
Is iibrory..funclion, wIere iibrory und funclion ure LIe numes oI LIe IIbrury
und LIe IuncLIon, respecLIveIy. or exumpIe, LIe IIbrury numeric Ior numerIcuI
compuLuLIons conLuIns LIe IuncLIon numeric..fsoive. L ImpIemenLs u modIIIed
versIon oI LIe weII-known NewLon meLIod Ior numerIcuI rooL IIndIng. n LIe
IoIIowIng exumpIe, we upproxImuLe u rooL oI LIe sIne IuncLIon In LIe InLervuI [2, 4]:
numeric..fsoive(sin(x} x = Z..4}
[x = 3.141592654]
TIe IuncLIon use
z
mukes IuncLIons oI u IIbrury gIobuIIy known, so LIuL you cun
use LIem wILIouL specIIyIng LIe IIbrury nume:
use(numeric fsoive}. fsoive(sin(x} x = Z..4}
[x = 3.141592654]
I you uIreudy Iuve ussIgned u vuIue Lo LIe nume oI LIe IuncLIon Lo be exporLed,
use reLurns u wurnIng und LIe IuncLIon Is noL exporLed. n LIe IoIIowIng, LIe
numerIcuI InLegruLor numeric..quodrolure cunnoL be exporLed Lo LIe nume
quodrolure, becuuse LIIs IdenLIIIer Ius u vuIue:
quodrolure .= 1. use(numeric quodrolure}
norning. quodrolure oireody hos o voiue nol exporled.
AILer deIeLIon oI LIe vuIue, LIe nume oI LIe IuncLIon Is uvuIIubIe und LIe
correspondIng IIbrury IuncLIon cun be exporLed successIuIIy. One cun exporL
severuI IuncLIons uL once:
deiele quodrolure.
use(numeric reoirools quodrolure}.
Now you cun use reoirools (Lo IInd cll reuI rooLs oI un expressIon In un InLervuI)
und quodrolure (Ior numerIcuI InLegruLIon) dIrecLIy. PIeuse reIer Lo LIe
correspondIng IeIp puges Ior LIe meunIng oI LIe InpuL purumeLers und LIe
reLurned ouLpuL. PIeuse noLe LIuL neILIer LooILIps nor LIe heip commund wIII
z
TIIs IuncLIon used Lo be cuIIed exporl, buL LIuL nume Is more upproprIuLeIy used Ior LIe IIbrury
exporLIng duLu In IormuLs Ior oLIer progrums.
-q
Epor|ing Iibrories
reucL Lo exporLed numes. You wIII need Lo use LIe IuII nume (or LIe seurcI
IuncLIonuIILy oI LIe IeIp browser) In LIese cuses.
reoirools(x^4 + x^3 - 6*x^Z + 11*x - 6
x = -10..10 0.001}
[[3.623046875, 3.62109375] , [0.8217773438, 0.822265625]]
quodrolure(exp(x} + 1 x = 0..1}
2.718281828
I you cuII use wILI onIy one urgumenL, numeIy LIe nume oI LIe IIbrury, LIen uII
IuncLIons In LIuL IIbrury ure exporLed. I LIere ure nume conIIIcLs wILI uIreudy
exIsLIng IdenLIIIers, LIen use Issues wurnIngs:
eigenvoiues .= 1. use(numeric}
Tnfo. numeric..quodrolure oireody is exporled.
Tnfo. numeric..reoirools oireody is exporled.
norning. indels oireody hos o voiue nol exporled.
Tnfo. numeric..fsoive oireody is exporled.
norning. rolionoiize oireody hos o voiue nol
exporled.
norning. iinsoive oireody hos o voiue nol exporled.
norning. sum oireody hos o voiue nol exporled.
norning. inl oireody hos o voiue nol exporled.
norning. soive oireody hos o voiue nol exporled.
norning. sorl oireody hos o voiue nol exporled.
norning. eigenvoiues oireody hos o voiue nol
exporled.
AILer deIeLIng LIe vuIue oI LIe IdenLIIIer eigenvoiues, LIe IIbrury IuncLIon wILI LIe
sume nume cun be exporLed successIuIIy:
deiele eigenvoiues. use(numeric eigenvoiues}.
However, LIe oLIer nume conIIIcLs inl, soive eLc. cunnoL be resoIved. TIe
ImporLunL symboIIc sysLem IuncLIons inl, soive eLc. sIouId noL be repIuced by
LIeIr numerIcuI counLerpurLs numeric..inl, numeric..soive eLc.
-g
3 The NuPAD

Iibrories
he $Iuadurd librury
TIe sLundurd IIbrury Is LIe mosL ImporLunL MuPAD

IIbrury. L conLuIns LIe mosL


IrequenLIy used IuncLIons sucI us diff, simpiify, eLc. (or un even more
resLrIcLed seIecLIon oI IrequenLIy used communds, cIeck LIe commund bur uL LIe
rIgIL-Iund sIde oI LIe noLebook InLerIuce und LIe MuPAD source code edILor.)
TIe IuncLIons oI LIe sLundurd IIbrury do noL Iuve u preIIx sepuruLed wILI .., us
oLIer IuncLIons do (unIess exporLed). n LIIs respecL, LIere Is no noLubIe
dIIIerence beLween LIe MuPAD kerneI IuncLIons, wIIcI ure wrILLen In LIe C++
progrummIng Iunguuge, und LIe oLIer IuncLIons Irom LIe sLundurd IIbrury, wIIcI
ure ImpIemenLed In LIe MuPAD progrummIng Iunguuge.
You obLuIn more InIormuLIon ubouL LIe uvuIIubIe IuncLIons oI LIe sLundurd IIbrury
by nuvIguLIng Lo LIe reIevunL secLIon In LIe IeIp sysLem, wIIcI Is LIe IIrsL
reIerence secLIon. TIe MuPAD QuIck ReIerence IIsLs uII IuncLIons oI LIe sLundurd
IIbrury In MuPAD versIon .
Muny oI LIese IuncLIons ure ImpIemenLed us IuncLIon envIronmenLs
(SecLIon 1;.1z). You cun vIew LIe source code vIu expose(nome}:
expose(exp}
proc(x}
nome exp
iocoi y iny c
oplion no0ebug
begin
if orgs(0} = 0 lhen
error("expecling one orgumenl"}
eise
if x..dom..exp <> FATL lhen
relurn(x..dom..exp(orgs(}}}
eise
if orgs(0} <> 1 lhen
error("expecling one orgumenl"}
endif
endif
endif
...
endproc
-6
4
MoPA

Objects
n CIupLer z, we InLroduced MuPAD

objecLs sucI us numbers, symboIIc


expressIons, mups, or muLrIces. Now, we dIscuss LIese objecLs more
sysLemuLIcuIIy.
TIe objecLs senL Lo LIe kerneI Ior evuIuuLIon cun be oI vurIous Iorms: urILImeLIc
expressIons wILI numbers sucI us 1+(1+T}/3, urILImeLIc expressIons wILI
symboIIc objecLs sucI us x+(y+T}/3, IIsLs, seLs, equuLIons, InequuIILIes, mups,
urruys, ubsLrucL muLIemuLIcuI objecLs, und more. Every MuPAD objecL beIongs Lo
some duLu Lype, cuIIed LIe domcin tpe. L corresponds Lo u cerLuIn InLernuI
represenLuLIon oI LIe objecL. n wIuL IoIIows, we dIscuss LIe IoIIowIng
IundumenLuI domuIn Lypes. As u convenLIon, LIe numes oI domuIns provIded by
LIe MuPAD kerneI consIsL oI cupILuI IeLLers, sucI us 00MTWT, 00MRAT eLc., wIIIe
domuIns ImpIemenLed In LIe MuPAD Iunguuge sucI us Series..Puiseux or
0om..Molrix(R} InvoIve smuII IeLLers:

domuIn Lype meunIng


00MTWT InLegers, e.g., -310^5
00MRAT ruLIonuI numbers, e.g., 7/11
00MFL0AT IIouLIng-poInL numbers, e.g., 0.1Z3
00MC0MPLEX compIex numbers, e.g., 1+Z/3*T
00MTWTERvAL IIouLIng-poInL InLervuIs, e.g., Z.1...3.Z
00MT0EWT symboIIc IdenLIIIers, e.g., xyf
00MEXPR symboIIc expressIons, e.g., x+y
Series..Puiseux symboIIc serIes expunsIons, e.g.,
1+x+x^Z+0(x^3}
00MLTST IIsLs, e.g., _1Z3]
00MSET seLs, e.g., {1Z3]
00MARRAY urruys
4 NuPAD

Cb[ec|s

domuIn Lype meunIng


00MTABLE LubIes
00MB00L BooIeun vuIues: TRuE, FALSE, uWKW0nW
00MSTRTWC sLrIngs, e.g., "T om o slring"
0om..Molrix(R} muLrIces und vecLors over LIe rIng R
00MP0LY poIynomIuIs, e.g., poiy(x^Z+x+1_x]}
00MPR0C IuncLIons und procedures
Moreover, you cun deIIne your own duLu Lypes, buL we do noL dIscuss LIIs Iere.
TIe sysLem IuncLIon domlype reLurns LIe domuIn Lype oI u MuPAD objecL.
n LIe IoIIowIng secLIon, we IIrsL presenL LIe ImporLunL operund IuncLIon op,
wIIcI enubIes you Lo decompose u MuPAD objecL InLo ILs buIIdIng bIocks. TIe
IoIIowIng secLIons dIscuss LIe ubove duLu Lypes und some oI LIe muIn sysLem
IuncLIons Ior IundIIng LIem.
q-
Cperonds: |he Func|ions op ond nops
0peruads: Ihe luatIieas op uad nops
L Is oILen necessury Lo decompose u MuPAD

objecL InLo ILs componenLs In order


Lo process LIem IndIvIduuIIy. TIe buIIdIng bIocks oI un objecL ure cuIIed opercnds.
TIe sysLem IuncLIons Ior uccessIng LIem ure op und nops (sIorL Ior: number oI
operunds):

nops(obgecl} : LIe number oI operunds,


op(obgecli} : LIe i-LI operund, 0 i nops(obgecl},
op(obgecli..g} : LIe sequence oI operunds i LIrougI j,
wIere 0 i j nops(obgecl},
op(obgecl} : LIe sequence op(obgecl1}, op(obgeclZ}, ...
oI uII operunds.
TIe meunIng oI un operund depends on LIe duLu Lype oI LIe objecL. We dIscuss LIIs
Ior eucI duLu Lype In deLuII In LIe IoIIowIng secLIons. or exumpIe, LIe operunds oI
u ruLIonuI number ure LIe numeruLor und LIe denomInuLor, LIe operunds oI u IIsL
or seL ure LIe eIemenLs, und LIe operunds oI u IuncLIon cuII ure LIe urgumenLs.
However, LIere ure uIso objecLs wIere LIe decomposILIon InLo operunds Is Iess
InLuILIve, sucI us serIes expunsIons us generuLed by LIe sysLem IuncLIons loyior
or series (SecLIon q.1). Here Is un exumpIe wILI u IIsL (SecLIon q.6):
iisl .= _o b c d sin(x}]. nops(iisl}
5
op(iisl Z}
b
op(iisl 3..5}
c, d, sIn(x)
op(iisl}
a, b, c, d, sIn(x)
By repeuLedIy cuIIIng LIe op IuncLIon, you cun decompose urbILrury MuPAD
expressIons InLo uLomIc ones. n LIIs modeI, u MuPAD uLom Is un expressIon
q-
4 NuPAD

Cb[ec|s
LIuL cunnoL be IurLIer decomposed by op, sucI LIuL op(olom}=olom IoIds.
1
TIIs
Is essenLIuIIy LIe cuse Ior InLegers, IIouLIng-poInL numbers, IdenLIIIers LIuL Iuve
noL been ussIgned u vuIue, und Ior sLrIngs:
op(-Z} op(0.1Z34} op(o} op("T om o lexl"}
2, 0.1234, a, um u LexL
n LIe IoIIowIng exumpIe, u nesLed IIsL Is decomposed compIeLeIy InLo ILs uLoms
o11o1ZoZ1xZ:
iisl .= __o11 o1Z] _oZ1 x^Z]]
TIe operunds und suboperunds ure:

op(iisl 1} : _o11 o1Z]


op(iisl Z} : _oZ1 x^Z]
op(op(iisl 1} 1} : o11
op(op(iisl 1} Z} : o1Z
op(op(iisl Z} 1} : oZ1
op(op(iisl Z} Z} : x^Z
op(op(op(iisl Z} Z} 1} : x
op(op(op(iisl Z} Z} Z} : Z
1
TIIs modeI Is u good upproxImuLIon Lo MuPAD`s InLernuI mode oI operuLIon, buL LIere ure some
excepLIons. or exumpIe, you cun decompose ruLIonuI numbers vIu op, buL LIe kerneI regurds LIem us
uLoms. On LIe oLIer Iund, uILIougI sLrIngs ure IndecomposubIe wILI respecL Lo op, IL Is sLIII possIbIe Lo
uccess LIe cIurucLers oI u sLrIng IndIvIduuIIy (SecLIon q.11).
q-q
Cperonds: |he Func|ions op ond nops
nsLeud oI LIe unnoyIng nesLed cuIIs oI op, you muy uIso use LIe IoIIowIng sIorL
Iorm Lo uccess subexpressIons:

op(iisl _1]} : _o11 o1Z]


op(iisl _Z]} : _oZ1 x^Z]
op(iisl _1 1]} : o11
op(iisl _1 Z]} : o1Z
op(iisl _Z 1]} : oZ1
op(iisl _Z Z]} : x^Z
op(iisl _Z Z 1]} : x
op(iisl _Z Z Z]} : Z
Ixercise q.1: DeLermIne LIe operunds oI LIe power o^b, LIe equuLIon o=b, und
LIe symboIIc IuncLIon cuII f(ob}.
Ixercise q.: TIe IoIIowIng cuII oI soive (CIupLer 8) reLurns u seL:
sel .= soive({x + sin(3}*y = exp(o}
y - sin(3}*y = exp(-o}] {xy]}
__
x =
e
a
sIn(3) e
a
+
sIn(3)
e
a
sIn(3) 1
, y =
1
e
a
(sIn(3) 1)
__
ExLrucL LIe vuIue oI LIe soIuLIon Ior y und ussIgn IL Lo LIe IdenLIIIer y.
q-g
4 NuPAD

Cb[ec|s
umbers
We Iuve demonsLruLed In SecLIon z. Iow Lo work wILI numbers. TIere ure
vurIous duLu Lypes Ior numbers:
domlype(-10} domlype(Z/3} domlype(0.1Z34}
domlype(0.1 + Z*T}
DOM_NT, DOM_RAT, DOM_OAT, DOM_COMPEX
A ruLIonuI number Is u compound objecL: LIe buIIdIng bIocks ure LIe numeruLor
und LIe denomInuLor. SImIIurIy, u compIex number consIsLs oI LIe reuI und LIe
ImugInury purL. You cun use LIe operund IuncLIon op Irom LIe prevIous secLIon Lo
uccess LIese componenLs:
op(111/ZZ3 1} op(111/ZZ3 Z}
111, 223
op(100 + Z00*T 1} op(100 + Z00*T Z}
100, 200
AILernuLIveIy, you cun use LIe sysLem IuncLIons numer, denom, Re, und Tm:
numer(111/ZZ3} denom(111/ZZ3}
Re(100 + Z00*T} Tm(100 + Z00*T}
111, 223, 100, 200
BesIdes LIe common urILImeLIc operuLIons +, -, *, und /, LIere ure LIe urILImeLIc
operuLors div und mod Ior dIvIsIon oI un InLeger x by u non-zero InLeger p wILI
remuInder. I x = k p +r IoIds wILI InLegers k und 0 r < |p|, LIen x div p
reLurns LIe InLegruI quoLIenL k und x mod p reLurns LIe remuInder r:
Z5 div 4 Z5 mod 4
6, 1
TubIe q.z gIves u compIIuLIon oI LIe muIn MuPAD IuncLIons und operuLors Ior
IundIIng numbers. We reIer Lo LIe IeIp sysLem (I.e., ?obs, ?ceii eLc.) Ior u
deLuIIed descrIpLIon oI LIese IuncLIons. We sLress LIuL wIIIe expressIons sucI us

2 muLIemuLIcuIIy represenL numbers, MuPAD LreuLs LIem us symboIIc


expressIons (SecLIon q.q):
q-6
Numbers

+ - * / ^ : busIc urILImeLIc operuLIons


obs : ubsoIuLe vuIue
ceii : roundIng up
div : quoLIenL moduIo
focl : IucLorIuI
fiool : upproxImuLIon by IIouLIng-poInL numbers
fioor : roundIng down
froc : IrucLIonuI purL
ifoclor, foclor : prIme IucLorIzuLIon
isprime : prImuIILy LesL
mod : remuInder moduIo
round : roundIng Lo neuresL
sign : sIgn
sqrl : squure rooL
lrunc : InLegruI purL
TubIe q.z: MuPAD

IuncLIons und operuLors Ior numbers


domlype(sqrl(Z}}
DOM_EXPR
Ixercise q.: WIuL Is LIe dIIIerence beLween 1/3 + 1/3 + 1/3 und
1.0/3 + 1/3 + 1/3 In MuPAD?
Ixercise q.q: CompuLe LIe decImuI expunsIons oI
(

)
und e
1
3

163
wILI u
precIsIon oI 10 und 100 dIgILs, respecLIveIy. WIuL Is LIe 234-LI dIgIL uILer LIe
decImuI poInL oI ?
Ixercise q.g: AILer you execuLe x.=10^50/3.0, onIy LIe IIrsL 0TCTTS decImuI
dIgILs oI x ure guurunLeed Lo be correcL.
u) TruncuLIng LIe IrucLIonuI purL vIu lrunc Is LIereIore quesLIonubIe. WIuL
does MuPAD do?
b) WIuL Is reLurned Ior x uILer IncreusIng 0TCTTS?
q-,
4 NuPAD

Cb[ec|s
ldeaIihers
Identijiers ure numes sucI us x or f LIuL muy represenL vurIubIes und unknowns.
TIey muy consIsL oI urbILrury combInuLIons oI IeLLers, dIgILs, LIe IusI murk #,
und LIe underscore , wILI LIe onIy excepLIon LIuL LIe IIrsL symboI musL noL be u
dIgIL. denLIIIers sLurLIng wILI u IusI murk cun never Iuve vuIues or properLIes.
MuPAD

dIsLInguIsIes uppercuse und Iowercuse IeLLers. ExumpIes oI udmIssIbIe


IdenLIIIers ure x, xZ3, und lheMuPA0syslem, wIIIe MuPAD wouId noL uccepL
1Zx, p-Z, und x>y us IdenLIIIers. MuPAD uIso uccepLs uny sequence oI cIurucLers
sLurLIng und endIng wILI u 'buckLIck` ` us un IdenLIIIer, so `x>y` Is, In IucL, un
IdenLIIIer. We wIII noL use sucI IdenLIIIers In LIIs LuLorIuI.
denLIIIers LIuL Iuve noL been ussIgned u vuIue evuIuuLe Lo LIeIr nume. n MuPAD,
LIey represenL symboIIc objecLs sucI us unknowns In equuLIons. TIeIr domuIn
Lype Is 00MT0EWT:
domlype(x}
DOM_DENT
denLIIIers cun conLuIn specIuI cIurucLers, sucI us un . We recommend usIng LIe
Symboi IIbrury Ior generuLIng LIese. UsIng , ^, S, und {], you cun uIso creuLe
IdenLIIIers wILI super- und subscrIpLs, us In a
1
1
. We recommend usIng LIe Symboi
IIbrury Ior generuLIng LIese, Loo.
You cun ussIgn un urbILrury objecL Lo un IdenLIIIer by meuns oI LIe cssinment
operctor .=. AILerwurds, LIIs objecL Is LIe tclue oI LIe IdenLIIIer. or exumpIe,
uILer LIe commund
x .= 1 + T.
LIe IdenLIIIer x Ius LIe vuIue 1+T, wIIcI Is u compIex number oI domuIn Lype
00MC0MPLEX. You sIouId be cureIuI Lo dIsLInguIsI beLween un IdenLIIIer, ILs vuIue,
und ILs evuIuuLIon. We reIer Lo LIe ImporLunL CIupLer , wIere MuPAD`s
evuIuuLIon sLruLegy Is descrIbed.
I un IdenLIIIer uIreudy Ius been ussIgned u vuIue, unoLIer ussIgnmenL overwrILes
LIe prevIous vuIue. TIe sLuLemenL y.=x does noL ussIgn LIe IdenLIIIer x Lo LIe
IdenLIIIer y, buL LIe currenL vuIue (LIe evuIuuLIon) oI x:
q-S
Iden|ihers
x .= 1. y .= x. x y
1, 1
I LIe vuIue oI x Is cIunged IuLer on, LIIs does noL uIIecL y:
x .= Z. x y
2, 1
However, II x Is u symboIIc IdenLIIIer, wIIcI evuIuuLes Lo ILseII, LIe new IdenLIIIer y
reIers Lo LIIs symboI:
deiele x. y .= x. x y x .= Z. x y
x, x
2, 2
Here we Iuve deIeLed LIe vuIue oI LIe IdenLIIIer x by meuns oI LIe IuncLIon deiele.
AILer deIeLIon, x Is uguIn u symboIIc IdenLIIIer wILIouL u vuIue.
TIe ussIgnmenL operuLor .= Is u sIorL Iorm oI LIe sysLem IuncLIon ossign, wIIcI
muy uIso be cuIIed dIrecLIy:
ossign(x voiue}. x
vuIue
TIIs IuncLIon reLurns ILs second urgumenL, numeIy LIe rIgIL-Iund sIde oI un
ussIgnmenL. TIIs expIuIns LIe screen ouLpuL uILer un ussIgnmenL:
y .= Z*x
2 vuIue
You cun work wILI LIe reLurned vuIue ImmedIuLeIy. or exumpIe, LIe IoIIowIng
consLrucLIon Is uIIowed (LIe ussIgnmenL musL be puL In purenLIeses):
y .= cos((x .= 0}}. x y
0, 1
Here LIe vuIue 0 Is ussIgned Lo LIe IdenLIIIer x. TIe reLurn vuIue oI LIe ussIgnmenL,
I.e., 0, Is Ied dIrecLIy us urgumenL Lo LIe cosIne IuncLIon, und LIe resuIL cos(0) = 1
Is ussIgned Lo y. TIus, we Iuve sImuILuneousIy ussIgned vuIues Lo boLI x und y.
q-q
4 NuPAD

Cb[ec|s
AnoLIer ussIgnmenL IuncLIon Is ossign. Ls InpuL ure seLs or IIsLs oI equuLIons,
wIIcI ure LrunsIormed InLo ussIgnmenLs:
deiele x y. ossign({x = 0 y = 1]}. x y
0, 1
TIIs IuncLIon Is purLIcuIurIy useIuI In connecLIon wILI soive (SecLIon 8), wIIcI
reLurns soIuLIons us u seL conLuInIng IIsLs oI equuLIons oI LIe Iorm
idenlifier=voiue wILIouL ussIgnIng LIese vuIues.
TIere exIsL muny IdenLIIIers wILI predeIIned vuIues. TIey represenL muLIemuLIcuI
IuncLIons (sucI us sin, exp, or sqrl), muLIemuLIcuI consLunLs (sucI us PT), or
MuPAD uIgorILIms (sucI us diff, inl, or iimil). I you Lry Lo cIunge LIe vuIue oI
sucI u predeIIned IdenLIIIer, MuPAD Issues u wurnIng or un error messuge:
sin .= 1
Error. Tdenlifier sin is prolecled _ossign]
You cun proLecL your own IdenLIIIers uguInsL overwrILIng vIu LIe commund
prolecl(idenlifier}. TIe wrILe proLecLIon oI boLI your own und oI sysLem
IdenLIIIers cun be removed by unprolecl(idenlifier}. However, we sLrongIy
recommend noL Lo overwrILe predeIIned IdenLIIIers, sInce LIey ure used by muny
sysLem IuncLIons wIIcI wouId reLurn unpredIcLubIe resuILs uILer u redeIInILIon.
denLIIIers sLurLIng wILI u IusI murk (#) ure uIwuys proLecLed und cunnoL be
unproLecLed. TIe commund onomes(Aii} IIsLs uII currenLIy deIIned IdenLIIIers.
You cun use LIe concuLenuLIon operuLor . Lo generuLe numes oI IdenLIIIers
dynumIcuIIy. I x und i ure IdenLIIIers, LIen x.i generuLes u new IdenLIIIer by
concuLenuLIng LIe etcluctions (see CIupLer ) oI x und i:
x .= z. i .= Z. x.i
zz
x.i .= voiue. zZ
vuIue
n LIe IoIIowIng exumpIe, we use u for Ioop (CIupLer 1) Lo ussIgn vuIues Lo LIe
IdenLIIIers x1...x1000:
deiele x.
for i from 1 lo 1000 do x.i .= i^Z endfor.
q-1o
Iden|ihers
Due Lo possIbIe sIde eIIecLs or conIIIcLs wILI uIreudy exIsLIng IdenLIIIers, we
sLrongIy recommend Lo use LIIs concepL onIy InLerucLIveIy und noL wILIIn MuPAD
procedures.
TIe IuncLIon genidenl generuLes u new IdenLIIIer LIuL Ius noL been used beIore In
LIe currenL MuPAD sessIon:
X3 .= (XZ .= (X1 .= 0}}. genidenl(}
Xq
You muy use sLrIngs encIosed In quoLuLIon murks " (SecLIon q.11) Lo generuLe
IdenLIIIers dynumIcuIIy:
o .= emoii. b .= "4you". o.b
emuIIqyou
Even II LIe sLrIng conLuIns bIunks or operuLor symboIs, u vuIId IdenLIIIer Is
generuLed, wIIcI MuPAD dIspIuys usIng LIe buckLIck noLuLIon menLIoned ubove:
o .= emoii. b .= "4you + x". o.b
emuIIqyou +x
SLrIngs ure noL IdenLIIIers und cunnoL be ussIgned u vuIue:
"slring" .= 1
Error. Tnvoiid iefl-hond side in ossignmenl _iine 1 coi 10]
Ixercise q.6: WIIcI oI LIe IoIIowIng numes x, xZ, Zx, xl, diff, exp,
coulion!-!, x-y, Jock&Jiii, ovoiididenlifier, #1 ure vuIId IdenLIIIers?WIIcI
oI LIem cun be ussIgned vuIues?
Ixercise q.,: Reud LIe IeIp puge Ior soive. SoIve LIe sysLem oI equuLIons
x
1
+x
2
= 1, x
2
+x
3
= 1, . . . , x
19
+x
20
= 1, x
20
=
In LIe unknowns x
1
, x
2
, . . . , x
20
. Reud LIe IeIp puge Ior ossign und ussIgn LIe
vuIues oI LIe soIuLIon Lo LIe unknowns.
q-11
4 NuPAD

Cb[ec|s
$ymbelit xpressieas
We suy LIuL un objecL conLuInIng symboIIc Lerms sucI us LIe equuLIon
0.3 + sIn(3) +
f(x, y)
5
= 0
Is un expression. ExpressIons oI domuIn Lype 00MEXPR ure probubIy LIe mosL
generuI duLu Lype In MuPAD

. ExpressIons ure buIIL oI uLomIc componenLs, us uII


MuPAD objecLs, und ure composed by meuns oI operctors. TIIs comprIses bInury
operuLors, sucI us LIe busIc urILImeLIc operuLIons +-*/^, und IuncLIon cuIIs
sucI us sin(}f(}, eLc.
Operutors
MuPAD

LIrougIouL uses IuncLIons Lo combIne or munIpuIuLe objecLs.


z
L wouId
be IILLIe InLuILIve, Iowever, Lo use IuncLIon cuIIs everywIere,

suy, pius(ob} Ior


LIe uddILIon a +b. or LIuL reuson, u vurIeLy oI ImporLunL operuLIons Is
ImpIemenLed In sucI u wuy LIuL you cun use LIe IumIIIur muLIemuLIcuI noLuLIon
(operuLor noLuLIon) Ior InpuL. AIso LIe ouLpuL Is gIven In sucI u Iorm. n LIe
IoIIowIng, we IIsL LIe operuLors Ior buIIdIng more compIex MuPAD expressIons
Irom uLoms.
TIe operuLors +-*/ Ior LIe busIc urILImeLIc operuLIons und ^ Ior
exponenLIuLIon ure vuIId Ior symboIIc expressIons us weII:
o + b + c o - b -o o*b*c o/b o^b
a +b +c, a b, a, a b c,
a
b
, a
b
You muy InpuL LIese operuLors In LIe IumIIIur muLIemuLIcuI wuy, buL InLernuIIy
LIey ure IuncLIon cuIIs:
z
RemurkubIy, LIe MuPAD kerneI LreuLs noL onIy genuIne IuncLIon cuIIs, sucI us sin(0.Z}, ussIgn-
menLs, or urILImeLIcuI operuLIons In u IuncLIonuI wuy, buL uIso Ioops (CIupLer 1) und cuse dIsLIncLIons
(CIupLer 16).

SP progrummers muy dIsugree.


q-1
5ymbolic Epressions
pius(obc} sublrocl(ob} negole(o}
muil(obc} divide(ob} poWer(ob}
a +b +c, a b, a, a b c,
a
b
, a
b
TIe sume IoIds Ior LIe IucLorIuI oI u nonneguLIve InLeger. You muy InpuL IL In LIe
muLIemuLIcuI noLuLIon n!. nLernuIIy IL Is converLed Lo u cuII oI LIe IuncLIon focl:
n! = focl(n} focl(10}
n! = n!, 3628800
TIe urILImeLIc operuLors div und mod
q
were presenLed In CIupLer q.z. TIey muy
uIso be used In u symboIIc conLexL, buL LIen reLurn onIy symboIIc resuILs:
x div 4 Z5 mod p
x dIv 4, 25 mod p
SeveruI MuPAD objecLs sepuruLed by commus Iorm u sequence:
sequence .= o b c + d
a, b, c +d
TIe operuLor S Is un ImporLunL LooI Lo generuLe sucI sequences:
i^Z S i = Z..7 x^i S i = 1..5
4, 9, 16, 25, 36, 49
x, x
2
, x
3
, x
4
, x
5
EquuLIons und InequuIILIes ure vuIId MuPAD objecLs. TIey ure generuLed by LIe
equuIILy sIgn = und by <>, respecLIveIy:
equolion .= x + y = Z inequoiily .= x <> y
x +y = 2
x = y
q
TIe objecL x mod p Is converLed Lo LIe IuncLIon cuII mod(xp}. TIe IuncLIon mod cun be redeIIned,
e.g., mod.=modp or mod.=mods. TIe beIuvIor oI modp und mods Is documenLed on LIe correspondIng
IeIp puges. A redeIInILIon oI mod uIso redeIInes LIe operuLor mod.
q-1
4 NuPAD

Cb[ec|s
TIe operuLors <, <=, >, und >= compure LIe mugnILudes oI LIeIr urgumenLs. TIe
correspondIng expressIons represenL condILIons:
condilion .= i <= Z
i 2
n u concreLe conLexL, LIey usuuIIy cun be evuIuuLed Lo one oI LIe LruLI (BooIeun)
vuIues TRuE or FALSE. TypIcuIIy, LIey ure used In if sLuLemenLs or us LermInuLIon
condILIons In Ioops. You muy combIne BooIeun expressIons vIu LIe IogIcuI
operuLors ond und or, or neguLe LIem vIu nol:
condilion3 .= condilion1 ond (nol condilionZ}
condILIon1 condILIonz
You cun deIIne mups (IuncLIons) In severuI wuys In MuPAD. TIe sImpIesL meLIod
Is Lo use LIe crrou operctor -> (LIe mInus symboI IoIIowed by LIe greuLer LIun
symboI):
f .= x -> x^Z
x x
2
AILer deIInIng u IuncLIon In LIIs wuy, you muy cuII IL IIke u sysLem IuncLIon:
f(4} f(x + 1} f(y}
16, (x + 1)
2
, y
2
I you wIsI Lo deIIne u IuncLIon LIuL IIrsL LreuLs LIe rIgIL-Iund sIde us u commund
Lo be perIormed, use LIe double crrou operctor -->:
g1 .= x -> inl(f(x} x}
gZ .= x --> inl(f(x} x}
x
_
f(x) dx
x
x
3
3
q-1q
5ymbolic Epressions
TIe composILIon oI IuncLIons Is deIIned by meuns oI LIe composition operctor e:
c .= oeb. c(x}
a(b(x))
TIe iterction operctor ee denoLes ILeruLed composILIon oI u IuncLIon wILI ILseII:
f .= gee4. f(x}
g(g(g(g(x))))
Some sysLem IuncLIons, sucI us deIInILe InLegruLIon vIu inl or LIe S operuLor,
requIre u rcne. You generuLe u runge by meuns oI LIe operuLor ..:
ronge .= 0..1 inl(x x = ronge}
0..1
1
2
Runges sIouId noL be conIused wILI IIouLIng-poInL InLervuIs oI domuIn Lype
00MTWTERvAL, wIIcI muy be creuLed vIu LIe operuLor ... or LIe IuncLIon huii:
PT ... Z0/3 huii(PT Z0/3}
3.141592653 . . . 6.666666667, 3.141592653 . . . 6.666666667
TIIs duLu Lype Is expIuIned In SecLIon q.18.
MuPAD LreuLs uny expressIon oI LIe Iorm idenlifier(orgumenl} us u IuncLIon
cuII:
deiele f.
expression .= sin(x} + f(x y} + inl(g(x} x = 0..1}
sIn(x) +f(x, y) +
_
1
0
g(x) dx
TubIe q. IIsLs uII operuLors presenLed ubove LogeLIer wILI LIeIr equIvuIenL
IuncLIonuI Iorm. You muy use eILIer Iorm Lo InpuL expressIons:
Z/14 = divide(Z 14}
1
7
=
1
7
q-1g
4 NuPAD

Cb[ec|s

operuLor
sysLem
IuncLIon meunIng exumpIe
+ pius uddILIon SuM.= o+b
- sublrocl subLrucLIon 0ifference.= o-b
* muil muILIpIIcuLIon Producl.= o*b
/ divide dIvIsIon uolienl.= o/b
^ poWer exponenLIuLIon PoWer.= o^b
div div quoLIenL uolienl.= o div p
moduIo p
mod mod remuInder Remoinder.= o mod p
moduIo p
! focl IucLorIuI n!
S seqgen sequence Sequence.= i^ZSi=3..5
generuLIon
exprseq sequence Seq.= Seq1SeqZ
concuLenuLIon
union union seL unIon S.= Sel1 union SelZ
inlersecl inlersecl seL InLersecLIon S.= Sel1 inlersecl SelZ
minus minus seL dIIIerence S.= Sel1 minus SelZ
= equoi equuLIon Equolion.= x+y=Z
<> unequoi InequuIILy Condilion.= x<>y
< iess compurIson Condilion.=o<b
> compurIson Condilion.= o>b
<= ieequoi compurIson Condilion.= o<=b
>= compurIson Condilion.= o>=b
nol nol neguLIon CondilionZ.=nol Condilion1
ond ond IogIcuI 'und` Condilion.= o<b ond b<c
or or IogIcuI 'or` Condilion.= o<b or b<c
-> muppIng Squore.= x -> x^Z
0 dIIIerenLIuI f(x}
operuLor
e fconcol composILIon h.= feg
ee fnesl ILeruLIon g.= fee3
. concol concuLenuLIon WeWWome.= Wome1.WomeZ
.. ronge runge Ronge.= o..b
... inlervoi InLervuI Tv.= Z.1...3.5
nome(} IuncLIon cuII sin(1}f(x}resel(}
TubIe q.: TIe muIn operuLors Ior generuLIng MuPAD

expressIons
q-16
5ymbolic Epressions
_i S i = 3..5] = _seqgen(i i 3..5}]
[3, 4, 5] = [3, 4, 5]
o < b = iess(o b}
(a < b) = (a < b)
(feg}(x} = fconcol(f g}(x}
f(g(x)) = f(g(x))
We remurk LIuL some oI LIe sysLem IuncLIons sucI us pius, muil, union, or
concol uccepL urbILrurIIy muny urgumenLs, wIIIe LIe correspondIng operuLors
ure onIy bInury:
pius(o b u v} concol(o b u v} union(}
a +b +u +v, ubuv,
L Is oILen useIuI Lo know und Lo use LIe IuncLIonuI Iorm oI LIe operuLors. or
exumpIe, IL Is very eIIIcIenL Lo Iorm Ionger sums by uppIyIng pius Lo muny
urgumenLs. You muy generuLe LIe urgumenL sequence quIckIy by meuns oI LIe
sequence generuLor S:
pius(1/i! S i = 0..100}. fiool(x}
2.718281828
TIe IuncLIon mop Is u useIuI LooI. L uppIIes u IuncLIon Lo uII operunds oI u MuPAD
objecL. or exumpIe:
pius(1/i! S i = 0..100}. fiool(x}
[IuncLIon(x1, y, z) , IuncLIon(xz, y, z) , IuncLIon(x, y, z)]
I you wunL Lo uppIy operuLors vIu mop, use LIeIr IuncLIonuI equIvuIenL:
mop(_x1 xZ x3] poWer 5} mop(_f g] fnesl 5}
_
x1
5
, xz
5
, x
5

, [f f f f f, g g g g g]
or LIe mosL common operuLors, numeIy +, -, *, /, ^, =, <>, <, >, <=, >=, ==>, und
<=>, LIe correspondIng IuncLIons cun be uccessed In LIe Iorm `+`, `-`, `*` eLc.:
q-1,
4 NuPAD

Cb[ec|s
mop(_1 Z 3 4] `*` 3} mop(_1 Z 3 4] `^` Z}
[3, 6, 9, 12] , [1, 4, 9, 16]
NoLe LIuL `-` Is neguLIon, noL subLrucLIon.
Some operuLIons ure InvuIId becuuse LIey do noL muke sense muLIemuLIcuIIy:
3 ond x
Error. Tiiegoi operond _ond]
TIe sysLem IuncLIon ond recognIzes LIuL LIe urgumenL 3 cunnoL represenL u
BooIeun vuIue und Issues un error messuge. However, MuPAD uccepLs u symboIIc
expressIon sucI us o ond b wILI symboIIc IdenLIIIers ob. As soon us o und b geL
BooIeun vuIues, LIe expressIon cun be evuIuuLed Lo u BooIeun vuIue us weII:
c .= o ond b. o .= TRuE. b .= TRuE. c
TRUE
TIe operuLors Iuve dIIIerenL priorities, Ior exumpIe:

o.focl(3} meuns o.(focl(3}} und reLurns o6,


o.6^Z meuns (o.6}^Z und reLurns o6^Z,
o*b^c meuns o*(b^c},
o+b*c meuns o+(b*c},
o+b mod c meuns (o+b} mod c,
o=b mod c meuns o=(b mod c},
obS3 meuns o(bS3} und reLurns obbb.
I we denoLe LIe reIuLIon Is oI Iower prIorILy LIun by , LIen we Iuve:
, S = mod + ^ . IuncLIon cuII.
You IInd u compIeLe IIsL oI LIe operuLors und LIeIr prIorILIes In SecLIon OperuLors
oI LIe MuPAD QuIck ReIerence. PurenLIeses cun uIwuys be used Lo enIorce un
evuIuuLIon order LIuL dIIIers Irom LIe sLundurd prIorILy oI LIe operuLors:
1 + 1 mod Z 1 + (1 mod Z}
0, 2
q-1S
5ymbolic Epressions
i .= Z. x.i^Z x.(i^Z}
xz
2
, xq
u v S 3 (u v} S 3
u, v, v, v
u, v, u, v, u, v
Ixpression Trees
A useIuI modeI Ior represenLIng u MuPAD

expressIon Is LIe expression tree. L


reIIecLs LIe InLernuI represenLuLIon. TIe operuLors or LIeIr correspondIng
IuncLIons, respecLIveIy, ure LIe verLIces, und LIe urgumenLs ure subLrees. TIe
operuLor oI IowesL prIorILy Is uL LIe rooL. Here ure some exumpIes:
o + b*c + d*e*sin(f}^g
+
o *
b c
*
d e ^
sin
f
g
inl(exp(x^4} x=0..1}
inl
exp
^
x 4
=
x ..
0 1
q-1q
4 NuPAD

Cb[ec|s
TIe dIIIerence o-b Is InLernuIIy represenLed us o+b*(-1}:
+
o *
b -1
SImIIurIy, u quoLIenL o/b Ius LIe InLernuI represenLuLIon o*b^(-1}:
*
o ^
b -1
TIe Ieuves oI un expressIon Lree ure MuPAD uLoms.
TIe IuncLIon prog..exprlree uIIows Lo dIspIuy expressIon Lrees. OperuLors ure
repIuced by LIe numes oI LIe correspondIng sysLem IuncLIons:
prog..exprlree(o/b}.
muil
1
+-- o
1
`-- poWer
1
+-- b
1
`-- -1
Ixercise q.S: SkeLcI LIe expressIon Lree oI o^b-sin(o/b}.
Ixercise q.q: DeLermIne LIe operunds oI Z/3, x/3, 1+Z*T, und x+Z*T. ExpIuIn
LIe dIIIerences LIuL you observe.
q-o
5ymbolic Epressions
Operunds
You cun decompose expressIons sysLemuLIcuIIy by meuns oI LIe operund IuncLIons
op und nops, wIIcI were uIreudy presenLed In SecLIon q.1. TIe operunds oI un
expressIon correspond Lo LIe subLrees beIow LIe rooL In LIe expressIon Lree.
expression .= o + b + c + sin(x}. nops(expression}
4
op(expression}
a, b, c, sIn(x)
AddILIonuIIy, expressIons oI domuIn Lype 00MEXPR Iuve u oLI operund, wIIcI Is
uccessIbIe vIu op(0}. L corresponds Lo LIe rooL oI LIe expressIon Lree und LeIIs
you wIIcI IuncLIon Is used Lo buIId LIe expressIon:
op(o + b*c 0} op(o*b^c 0} op(o^(b*c} 0}
op(f(sin(x}}0}
_pIus, _muIL, _power, f
sequence .= o b c. op(sequence 0}
_exprseq
I LIe expressIon Is u symboIIc IuncLIon cuII, op(0} reLurns LIe IdenLIIIer oI LIuL
IuncLIon:
op(sin(1} 0} op(f(x} 0} op(diff(y(x} x} 0}
op(inl(exp(x^4} x} 0}
sIn, f, dIII, InL
You muy regurd LIe oLI operund oI un expressIon us u muLIemuLIcuI Lype. or
exumpIe, un uIgorILIm Ior dIIIerenLIuLIon oI urbILrury expressIons musL IInd ouL
wIeLIer LIe expressIon Is u sum, u producL, or u IuncLIon cuII. To LIIs end, IL muy
Iook uL LIe oLI operund Lo decIde wIeLIer IIneurILy, LIe producL ruIe, or LIe cIuIn
ruIe oI dIIIerenLIuLIon uppIIes.
q-1
4 NuPAD

Cb[ec|s
As un exumpIe, we decompose LIe expressIon
expression .= o + b + sin(x} + c^Z.
wILI LIe expressIon Lree
+
o b sin
x
^
c Z
sysLemuLIcuIIy by meuns oI LIe op IuncLIon:
op(expression 0..nops(expression}}
_pIus, a, b, sIn(x) , c
2
We cun puL LIese expressIons LogeLIer uguIn In LIe IoIIowIng Iorm:
rool .= op(expression 0}. operonds .= op(expression}.
rool(operonds}
c
2
+a +b +sIn(x)
NoLe LIuL LIe ouLpuL order vIsIbIe on LIe screen Is dIIIerenL Irom LIe InLernuI
order uccessIbIe by op. You cun uccess LIe buIIdIng bIocks oI un expressIon In
ouLpuL order wILI LIe Index operuLor _], us In LIe IoIIowIng:
expression_1] expression_4]
c
2
, sIn(x)
n LIe IoIIowIng exumpIe, we decompose un expressIon compIeLeIy InLo ILs uLoms
(compure wILI SecLIon q.1):
expression .= sin(x + cos(o*b}}.
q-
5ymbolic Epressions
TIe operunds und subexpressIons ure:

op(expression 0} : sin
op(expression 1} : x+cos(o*b}
op(expression _1 0]} : pius
op(expression _1 1]} : x
op(expression _1 Z]} : cos(o*b}
op(expression _1 Z 0]} : cos
op(expression _1 Z 1]} : o*b
op(expression _1 Z 1 0]} : muil
op(expression _1 Z 1 1]} : o
op(expression _1 Z 1 Z]} : b
Ixercise q.1o: SkeLcI LIe expressIon Lree oI LIe IoIIowIng BooIeun expressIon:
condilion .= (nol o} ond (b or c}.
How cun you use op Lo pIck LIe symboIIc IdenLIIIers o, b, und c ouL oI LIe objecL
condilion?
q-
4 NuPAD

Cb[ec|s
$equeates
Sequences Iorm un ImporLunL MuPAD

duLu sLrucLure. IsLs und seLs ure buIIL


Irom sequences. As dIscussed In SecLIon q.q, u sequence Is u serIes oI MuPAD
objecLs sepuruLed by commus.
sequence1 .= o b c sequenceZ .= c d e
a, b, c
c, d, e
You muy uIso use LIe commu Lo concuLenuLe sequences:
sequence3 .= sequence1 sequenceZ
a, b, c, c, d, e
Sequences ure MuPAD expressIons oI domuIn Lype 00MEXPR.
I m und n ure InLegers, LIe cuII obgecl(i}Si=m..n generuLes LIe sequence
object(m), object(m+ 1), . . . , object(n) :
i^Z S i = Z..7 x^i S i = 1..5
4, 9, 16, 25, 36, 49, x, x
2
, x
3
, x
4
, x
5
TIe operuLor S Is cuIIed LIe sequence enerctor. TIe equIvuIenL IuncLIonuI Iorm Is
seqgen(obgecl(i}im..n}
seqgen(i^Z i Z..7} seqgen(x^i i 1..5}
4, 9, 16, 25, 36, 49, x, x
2
, x
3
, x
4
, x
5
UsuuIIy, you wIII preIer LIe operuLor noLuLIon. TIe IuncLIonuI Iorm Is useIuI In
connecLIon wILI mop, zip or sImIIur IuncLIons.
You muy use S In LIe IoIIowIng wuy Lo generuLe u sequence oI successIve InLegers:
S Z3..30
23, 24, 25, 26, 27, 28, 29, 30
q-q
5equences
TIe commund obgeclSn reLurns u sequence oI n IdenLIcuI objecLs:
x^Z S 10
x
2
, x
2
, x
2
, x
2
, x
2
, x
2
, x
2
, x
2
, x
2
, x
2
You cun uIso use LIe sequence generuLor In connecLIon wILI LIe keyword in. (TIe
IuncLIonuI equIvuIenL In LIIs cuse In seqin.) TIe Ioop vurIubIe LIen runs LIrougI
uII operunds oI LIe sLuLed objecL:
f(x} S x in _o b c d]
f(a) , f(b) , f(c) , f(d)
f(x} S x in o + b + c + d + sin(sqrl(Z}}
f(a) , f(b) , f(c) , f(d) , f
_
sIn
_

2
__
L muy be LempLIng Lo ubuse LIe S operuLor Ior Ioops, us In LIese communds:
(x.i .= sin(i} y.i .= x.i} S i=1..4.
or reudubIIILy, memory consumpLIon und LIereIore speed, we recommend
uguInsL LIIs usuge. TIe ussIgnmenLs ubove sIouId use u Ioop InsLeud (cI.
CIupLer 1):
for i from 1 lo 4 do
x.i .= sin(i}
y.i .= x.i
endfor.
As u sImpIe uppIIcuLIon oI sequences, we now consIder LIe MuPAD dIIIerenLIuLor
diff. TIe cuII diff(f(x}x} reLurns LIe derIvuLIve oI f wILI respecL Lo x. HIgIer
derIvuLIves ure gIven by diff(f(x}xx}, diff(f(x}xxx} eLc. TIus, LIe
10-LI derIvuLIve oI f(x) = sIn(x
2
) cun be compuLed convenIenLIy by meuns oI LIe
sequence generuLor:
diff(sin(x^Z} x S 10}
Z 4 Z
30Z40 cos(x } - 403Z00 x cos(x } +
Z Z Z
Z3040 x cos(x } - 30Z400 x sin(x } +
6 Z 10 Z
161Z0 x sin(x } - 10Z4 x sin(x }
q-g
4 NuPAD

Cb[ec|s
TIe voId objecL (SecLIon q.1q) muy be regurded us un empLy sequence. You muy
generuLe IL by cuIIIng nuii(} or exprseq(}. TIe sysLem uuLomuLIcuIIy eIImInuLes
LIIs objecL Irom sequences:
Seq .= nuii(}. Seq .= Seq o b nuii(} c
a, b, c
Some sysLem IuncLIons sucI us LIe prinl commund Ior screen ouLpuL
(SecLIon 1z.1) reLurn LIe nuii(} objecL:
sequence .= o b prinl(|eiio} c
|eiio
a, b, c
You cun uccess LIe i-LI enLry oI u sequence by sequence_i]. RedeIInILIons oI LIe
Iorm sequence_i].=neWvoiue ure uIso possIbIe:
F .= o b c. F_Z]
b
F_Z] .= neWvoiue. F
a, newvuIue, c
AILernuLIveIy, you muy use LIe operund IuncLIon op (SecLIon q.1) Lo uccess
subsequences:

F .= o b c d e. op(F Z} op(F Z..4}


b
b, c, d

NoLe LIuL, In LIIs exumpIe, LIe IdenLIIIer F oI LIe sequence Is provIded us urgumenL Lo op. TIe op
IuncLIon regurds u dIrecL cuII oI LIe Iormop(obcdeZ} us un (InvuIId) cuII wILI sIx urgumenLs und
Issues un error messuge. You muy use purenLIeses Lo uvoId LIIs error: op((obcde}Z}.
q-6
5equences
You muy use deiele Lo deIeLe enLrIes Irom u sequence, LIus sIorLenIng LIe
sequence:
F deiele F_Z]. F deiele F_3]. F
a, b, c, d, e
a, c, d, e
a, c, e
TIe muIn usuge oI MuPAD sequences Is LIe generuLIon oI IIsLs und seLs und
suppIyIng urgumenLs Lo IuncLIon cuIIs. or exumpIe, LIe IuncLIons mox und min
cun compuLe LIe muxImum und mInImum, respecLIveIy, oI urbILrurIIy muny
urgumenLs:
Seq .= 1 Z -1 3 0. mox(Seq} min(Seq}
3, 1
Ixercise q.11: AssIgn LIe vuIues x
1
= 1, x
2
= 2, . . . , x
100
= 100 Lo LIe IdenLIIIers
x
1
, x
2
, . . . , x
100
.
Ixercise q.1: GeneruLe LIe sequence
x
1
, x
2
, x
2
. .
2
, x
3
, x
3
, x
3
. .
3
, . . . , x
10
, x
10
, . . . , x
10
. .
10
.
Ixercise q.1: Use u sImpIe commund Lo generuLe LIe doubIe sum
10

i=1
i

j=1
1
i +j
.
HInL: LIe IuncLIon pius uccepLs urbILrurIIy muny urgumenLs. GeneruLe u suILubIe
urgumenL sequence.
q-,
4 NuPAD

Cb[ec|s
lisIs
A IIsL Is un ordered sequence oI urbILrury MuPAD

objecLs encIosed In squure


bruckeLs:
iisl .= _o 5 sin(x}^Z + 4 _o b c] heiio
3/4 3.907]
_
a, 5, sIn(x)
2
+ 4, [a, b, c] , IeIIo,
3
4
, 3.9087
_
A IIsL muy conLuIn IIsLs us eIemenLs. L muy uIso be empLy:
iisl .= _]
[]
TIe possIbIIILy Lo generuLe sequences vIu S Is IeIpIuI Ior consLrucLIng IIsLs:
sequence .= i S i = 1..10. iisl .= _sequence]
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
iisl .= _x^i S i = 0..1Z]
_
1, x, x
2
, x
3
, x
4
, x
5
, x
6
, x
7
, x
8
, x
9
, x
10
, x
11
, x
12

A IIsL muy occur on LIe IeIL Iund sIde oI un ussIgnmenL. TIIs muy be used Lo
ussIgn vuIues Lo severuI IdenLIIIers sImuILuneousIy:
_A B C] .= _o b c]. A + B^C
a +b
c
A useIuI properLy oI LIIs consLrucLIon Is LIuL uII LIe ussIgnmenLs ure perIormed uL
LIe sume LIme, so you cun swup vuIues:
o .= 1. b.= Z. o b
1, 2
_o b] .= _b o]. o b
2, 1
q-S
Iis|s
TIe IuncLIon nops reLurns LIe number oI eIemenLs oI u IIsL. You cun uccess LIe
eIemenLs oI u IIsL by meuns oI Indexed uccess: iisl_i] reLurns LIe i-LI IIsL
eIemenL, und iisl_i..g] reLurns LIe sub-IIsL sLurLIng uL LIe i-LI und exLendIng up
Lo und IncIudIng LIe j-LI eIemenL. NeguLIve vuIues Ior i und j ure counLed Irom
LIe end:
iisl .= _o b c d e f]. iisl_1] iisl_3..-Z]
2, [c, d, e]
As wILI uImosL uny MuPAD objecL, you cun uIso uccess LIe eIemenLs oI u IIsL wILI
LIe op IuncLIon: op(iisl} reLurns LIe sequence oI eIemenLs, I.e., LIe sequence
LIuL Ius been used Lo consLrucL LIe IIsL by encIosIng IL In squure bruckeLs _]. TIe
cuII op(iisli} reLurns LIe i-LI IIsL eIemenL, und op(iisli..g} exLrucLs LIe
sequence oI LIe i-LI up Lo LIe j-LI IIsL eIemenL:
deiele o b c. iisl .= _o b sin(x} c]. op(iisl}
a, b, sIn(x) , c
op(iisl Z..3}
b, sIn(x)
You muy cIunge u IIsL eIemenL by un Indexed ussIgnmenL:
iisl .= _o b c]. iisl_1] .= neWvoiue. iisl
[newvuIue, b, c]
WrILIng Lo u subIIsL muy cIunge LIe IengLI oI LIe IIsL:
iisl_Z..3] .= _defg]. iisl
[newvuIue, d, e, f, g]
AILernuLIveIy, LIe commund subsop(iisli=neWvoiue} (CIupLer 6) reLurns u
copy wILI LIe i-LI operund redeIIned:
iisl .= _o b c]. iislZ .= subsop(iisl 1 = neWvoiue}
[newvuIue, b, c]
q-q
4 NuPAD

Cb[ec|s
Cuotion: I L Is un IdenLIIIer wILIouL u vuIue, LIen LIe Indexed ussIgnmenL
L_index] .= voiue.
generuLes u LubIe (SecLIon q.8) und noL u IIsL:
deiele L. L_1] .= o. L
1 a
You cun remove eIemenLs Irom u IIsL by usIng deiele. TIIs sIorLens LIe IIsL:
iisl .= _o b c]. deiele iisl_1]. iisl
[b, c]
TIe IuncLIon conloins cIecks wIeLIer u MuPAD objecL beIongs Lo u IIsL. L
reLurns LIe Index oI (LIe IIrsL occurrence oI) LIe eIemenL In LIe IIsL. I LIe IIsL does
noL conLuIn LIe eIemenL, LIen conloins reLurns LIe InLeger 0:
conloins(_x + 1 o x + 1] x + 1}
1
conloins(_sin(o} b c] o}
0
TIe IuncLIon oppend udds eIemenLs Lo LIe LuII oI u IIsL:
iisl .= _o b c]. oppend(iisl 3 4 5}
[a, b, c, 3, 4, 5]
TIe doL operuLor . concuLenuLes IIsLs:
iisl1 .= _1 Z 3]. iislZ .= _4 5 6].
iisl1.iislZ iislZ.iisl1
[1, 2, 3, 4, 5, 6] , [4, 5, 6, 1, 2, 3]
TIe correspondIng sysLem IuncLIon Is concol und uccepLs urbILrurIIy muny
urgumenLs. You cun use IL Lo combIne muny IIsLs:
concol(iisl1 S 5}
[1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3]
q-o
Iis|s
A IIsL cun be sorLed by meuns oI LIe IuncLIon sorl. TIIs urrunges numerIcuI vuIues
uccordIng Lo LIeIr mugnILude, sLrIngs (SecLIon q.11) ure sorLed IexIcogrupIIcuIIy:
sorl(_-1.Z3 4 3 Z 1/Z]}
_
1.23,
1
2
, 2, 3, 4
_
sorl(_"A" "b" "o" "c" "C" "c" "B" "o1" "obc"]}
[A, B, C, u, u1, ubc, b, c, c]
sorl(_"x1000Z" "x10011" "x10003"]}
[x1oooz, x1ooo, x1oo11]
NoLe LIuL LIe IexIcogrupIIcuI order onIy uppIIes Lo sLrIngs generuLed wILI ".
Numes oI IdenLIIIers ure sorLed uccordIng Lo dIIIerenL (InLernuI) ruIes, wIIcI onIy
reduce Lo IexIcogrupIIc order Ior sIorL IdenLIIIers (und muy cIunge In IuLure
reIeuses):
deiele A B C o b c o1 obc.
sorl(_A b o c C c B o1 obc]}
[A, B, C, a, u1, ubc, b, c, c]
sorl(_x1000Z x10011 x10003]}
[x1oooz, x1oo11, x1ooo]
MuPAD regurds IIsLs oI IuncLIon numes us IIsL-vuIued IuncLIons:
_sin cos f](x}
[sIn(x) , cos(x) , f(x)]
TIe IuncLIon mop uppIIes u IuncLIon Lo uII eIemenLs oI u IIsL:
mop(_x 1 0 PT 0.3] sin}
[sIn(x) , sIn(1) , 0, 0, 0.2955202067]
q-1
4 NuPAD

Cb[ec|s
I LIe IuncLIon Ius more LIun one urgumenL, LIen mop subsLILuLes LIe IIsL eIemenLs
Ior LIe IIrsL urgumenL und Lukes LIe remuInIng urgumenLs Irom ILs own urgumenL
IIsL:
mop(_o b c] f y z}
[f(a, y, z) , f(b, y, z) , f(c, y, z)]
TIIs mop consLrucLIon Is u powerIuI LooI Ior IundIIng IIsLs us weII us oLIer MuPAD
objecLs. n LIe IoIIowIng exumpIe, we Iuve u nesLed IIsL L. We wunL Lo exLrucL LIe
IIrsL eIemenLs oI LIe subIIsLs usIng op(1}. TIIs Is eusIIy done usIng mop:
L .= __o1 b1] _oZ bZ] _o3 b3]]. mop(L op 1}
[u1, uz, u]
TIe MuPAD IuncLIon seiecl enubIes you Lo exLrucL eIemenLs wILI u cerLuIn
properLy Irom u IIsL. To LIIs end, you need u IuncLIon LIuL cIecks wIeLIer un
objecL Ius LIIs properLy und reLurns TRuE or FALSE. or exumpIe, LIe cuII
hos(obgecl1obgeclZ} reLurns TRuE II obgeclZ Is un operund or suboperund oI
obgecl1, und FALSE oLIerwIse:
hos(1 + sin(1 + x} x} hos(1 + sin(1 + x} y}
TRUE, ASE
Now,
seiecl(_o + Z x y z sin(o}] hos o}
[a + 2, sIn(a)]
exLrucLs uII LIose IIsL eIemenLs Ior wIIcI hos(o} reLurns TRuE, I.e., LIose wIIcI
conLuIn LIe IdenLIIIer o.
TIe IuncLIon spiil dIvIdes u IIsL InLo LIree IIsLs, us IoIIows. TIe IIrsL IIsL conLuIns
uII eIemenLs wILI u cerLuIn properLy, LIe second IIsL coIIecLs uII LIose eIemenLs
wILIouL LIe properLy. I LIe LesL Ior LIe properLy reLurns LIe vuIue uWKW0nW Ior
some eIemenLs, LIen LIese ure puL InLo LIe LIIrd IIsL. OLIerwIse, LIe LIIrd IIsL Is
empLy:
spiil(_sin(x} x^Z y 11] hos x}
__
sIn(x) , x
2

, [y, 11] , []

q-
Iis|s
TIe MuPAD IuncLIon zip combInes eIemenLs oI Lwo IIsLs puIrwIse InLo u new IIsL:
L1 .= _o b c]. LZ .= _d e f].
zip(L1 LZ pius} zip(L1 LZ muil}
zip(L1 LZ poWer}
[a +d, b +e, c +f] , [a d, b e, c f] ,
_
a
d
, b
e
, c
f

TIe LIIrd urgumenL oI zip musL be u IuncLIon LIuL Lukes Lwo urgumenLs. TIIs
IuncLIon Is LIen uppIIed Lo LIe puIrs oI IIsL eIemenLs. n LIe ubove exumpIe, we
Iuve used LIe MuPAD IuncLIons pius, muil, und poWer Ior uddILIon,
muILIpIIcuLIon, und exponenLIuLIon, respecLIveIy. I LIe Lwo InpuL IIsLs Iuve
dIIIerenL IengLIs, LIen LIe beIuvIor oI zip depends on LIe opLIonuI IourLI
urgumenL. I LIIs Is noL presenL, LIen LIe IengLI oI LIe resuILIng IIsL Is LIe
mInImum oI LIe IengLIs oI LIe Lwo InpuL IIsLs. OLIerwIse, II you suppIy un
uddILIonuI IourLI urgumenL, LIen zip repIuces LIe mIssIng IIsL enLrIes by LIIs
urgumenL:
L1 .= _o b c 1 Z]. LZ .= _d e f].
zip(L1 LZ pius}
[a +d, b +e, c +f]
zip(L1 LZ pius heiio}
[a +d, b +e, c +f, IeIIo + 1, IeIIo + 2]
TubIe q.q gIves u summury oI uII IIsL operuLIons LIuL we Iuve dIscussed.
Ixercise q.1q: GeneruLe Lwo IIsLs wILI LIe eIemenLs a, b, c, d und 1, 2, 3, 4,
respecLIveIy. ConcuLenuLe LIe IIsLs. MuILIpIy LIe IIsLs puIrwIse.
Ixercise q.1g: MuILIpIy uII enLrIes oI LIe IIsL _1xZ] by 2. Suppose you ure
gIven u IIsL, wIose eIemenLs ure IIsLs oI numbers or expressIons, sucI us
__1xZ]_PT]_Z/31]], Iow cun you muILIpIy uII enLrIes by 2?
q-
4 NuPAD

Cb[ec|s

. or concol : concuLenuLIng IIsLs


oppend : uppendIng eIemenLs
conloins(iislx} : does iisl conLuIn LIe eIemenL x?
iisl_i] : uccessIng LIe i-LI eIemenL
mop : uppIyIng u IuncLIon
nops : IengLI
op : uccessIng eIemenLs
seiecl : seIecL uccordIng Lo properLIes
sorl : sorLIng
spiil : spIIL uccordIng Lo properLIes
subsop : repIucIng eIemenLs
deiele : deIeLIng eIemenLs
zip : combInIng Lwo IIsLs
TubIe q.q: MuPAD

IuncLIons und operuLors Ior IIsLs


Ixercise q.16: eL X = [x
1
, . . . , x
n
] und Y = [y
1
, . . . , y
n
] be Lwo IIsLs oI LIe sume
IengLI. Ind u sImpIe meLIod Lo compuLe
LIeIr Inner producL (X us row vecLor und Y us coIumn vecLor)
x
1
y
1
+ +x
n
y
n
,
LIeIr muLrIx producL (X us coIumn vecLor und Y us row vecLor)
[ [x
1
y
1
, x
1
y
2
, . . . , x
1
y
n
], [x
2
y
1
, x
2
y
2
, . . . , x
2
y
n
],
. . . , [x
n
y
1
, x
n
y
2
, . . . , x
n
y
n
]] .
You cun ucIIeve LIIs by usIng zip, pius, mop und upproprIuLe IuncLIons
(SecLIon q.1z) wILIIn u sIngIe commund IIne In eucI cuse. oops (CIupLer 1) ure
noL requIred.
Ixercise q.1,: n number LIeory, one Is oILen InLeresLed In LIe densILy oI prIme
numbers In sequences oI LIe Iorm f(1), f(2), . . . , wIere f Is u poIynomIuI. or
eucI vuIue oI m = 0, 1, . . . , 41, IInd ouL Iow muny oI LIe InLegers n
2
+n +m wILI
n = 1, 2, . . . , 100 ure prImes.
q-q
Iis|s
Ixercise q.1S: n wIIcI orderIng wIII n cIIIdren be seIecLed Ior removuI by u
counLIng-ouL rIyme composed oI m words? or exumpIe, usIng LIe rIyme
eenIe-meenIe-mIney-moe-cuLcI u-LIger-by LIe-Loe
wILI 8 words, 12 cIIIdren ure counLed ouL In LIe order
8-q-1-11-1o-1z--;-6-z-q-. HInL: represenL LIe cIIIdren by u IIsL _1Z.]
und remove un eIemenL Irom LIIs IIsL uILer IL Is counLed ouL.
q-g
4 NuPAD

Cb[ec|s
$eIs
A set Is un unordered sequence oI urbILrury objecLs encIosed In curIy bruces. SeLs
ure oI domuIn Lype 00MSET:
{34 1 9 x -9 ]
{9, 1, 8, 34, 89, x}
The order oj the elements in c MuPAD

list seems to be rcndom. TIe MuPAD


kerneI sorLs LIe eIemenLs uccordIng Lo InLernuI prIncIpIes. You sIouId use seLs
onIy II LIe order oI LIe eIemenLs does noL muLLer. I you wunL Lo process u sequence
oI expressIons In u cerLuIn order, use IIsLs us dIscussed In LIe prevIous secLIon.
SeLs muy be empLy:
emplysel .= {]

A seL conLuIns eucI eIemenL onIy once, I.e., dupIIcuLe eIemenLs ure removed
uuLomuLIcuIIy:
sel .= {o 1 Z 3 4 o b 1 Z o]
{1, 2, 3, 4, a, b}
TIe IuncLIon nops deLermInes LIe number oI eIemenLs In u seL. As Ior sequences
und IIsLs, op exLrucLs eIemenLs Irom u seL:
op(sel}
a, 1, 2, 3, 4, b
op(sel Z..4}
1, 2, 3
Wurning: SInce eIemenLs oI u seL muy be reordered InLernuIIy, you sIouId cIeck
cureIuIIy wIeLIer IL mukes sense Lo uccess LIe i-LI eIemenL. or exumpIe,
subsop(seli=neWvoiue} (SecLIon 6) repIuces LIe i-LI eIemenL by u new vuIue.
However, you sIouId cIeck In udvunce (usIng op) LIuL LIe eIemenL LIuL you wunL
Lo repIuce reuIIy Is LIe i-LI eIemenL. EspecIuIIy noLe LIuL repIucIng un eIemenL oI u
seL oILen reorders oLIer enLrIes.
q-6
5e|s
TIe commund op(seli} reLurns LIe i-LI eIemenL oI sel In LIe InLernuI order,
wIIcI usuuIIy Is dIIIerenL Irom LIe i-LI eIemenL oI sel LIuL you see on LIe screen.
However, you cun uccess eIemenLs by usIng sel_i], wIere LIe reLurned eIemenLs
Is LIe i-LI eIemenL us prInLed on LIe screen.
TIe IuncLIons union, inlersecl, und minus Iorm LIe unIon, LIe InLersecLIon, und
LIe seL-LIeoreLIc dIIIerence, respecLIveIy, oI seLs:
M1 .= {1 Z 3 o b]. MZ .= {o b c 4 5].
M1 union MZ M1 inlersecl MZ M1 minus MZ MZ minus M1
{1, 2, 3, 4, 5, a, b, c} , {a, b} , {1, 2, 3} , {4, 5, c}
n purLIcuIur, you cun use minus Lo remove eIemenLs Irom u seL:
{1 Z 3 o b] minus {3 o]
{1, 2, b}
You cun uIso repIuce un eIemenL by u new vuIue wILIouL curIng ubouL LIe order oI
LIe eIemenLs:
sel .= {o b oidvoiue c d]
{a, b, c, d, oIdvuIue}
sel minus {oidvoiue] union {neWvoiue]
{a, b, c, d, newvuIue}
TIe IuncLIon conloins cIecks wIeLIer un eIemenL beIongs Lo u seL, und reLurns
eILIer TRuE or FALSE:
6
conloins({o b c] o} conloins({o b c + d] c}
TRUE, ASE
MuPAD regurds seLs oI IuncLIon numes us seL-vuIued IuncLIons:
{sin cos f](x}
{cos(x) , f(x) , sIn(x)}
6
NoLe LIe dIIIerence Lo LIe beIuvIor oI conloins Ior IIsLs: LIere LIe orderIng oI LIe eIemenLs Is
deLermIned wIen you generuLe LIe IIsL, und conloins reLurns LIe posILIon oI LIe eIemenL In LIe IIsL.
q-,
4 NuPAD

Cb[ec|s

conloins(Mx} : does M conLuIn LIe eIemenL x?


inlersecl : InLersecLIon
mop : uppIyIng u IuncLIon
minus : seL-LIeoreLIc dIIIerence
nops : number oI eIemenLs
op : uccessIng eIemenLs
seiecl : seIecL uccordIng Lo properLIes
spiil : spIIL uccordIng Lo properLIes
subsop : repIucIng eIemenLs
union : seL-LIeoreLIc unIon
TubIe q.: MuPAD

IuncLIons und operuLors Ior seLs


You cun uppIy u IuncLIon Lo uII eIemenLs oI u seL by meuns oI mop:
mop({x 1 0 PT 0.3] sin}
{0, 0.2955202067, sIn(1) , sIn(x)}
You cun use LIe IuncLIon seiecl Lo exLrucL eIemenLs wILI u cerLuIn properLy Irom
u seL. TIIs works us Ior IIsLs, buL LIe reLurned objecL Is u seL:
seiecl({{o x b] {o] {x 1]] conloins x}
{{1, x} , {a, b, x}}
SImIIurIy, you cun use LIe IuncLIon spiil Lo dIvIde u seL InLo LIree subseLs oI
eIemenLs wILI u cerLuIn properLy, eIemenLs wILIouL LIuL properLy, und eIemenLs
Ior wIIcI LIe sysLem cunnoL decIde LIIs und reLurns uWKW0nW. TIe resuIL Is u IIsL
comprIsIng LIese LIree seLs:
spiil({{o x b] {o] {x 1]] conloins x}
[{{1, x} , {a, b, x}} , {{a}} , ]
TubIe q. conLuIns u summury oI LIe seL operuLIons dIscussed so Iur.
MuPAD uIso provIdes LIe duLu sLrucLure 0om..TmogeSel Ior IundIIng InIInILe seLs;
see puge 8-q In CIupLer 8.
Ixercise q.1q: How cun you converL u IIsL Lo u seL und vIce versu?
q-S
5e|s
Ixercise q.o: GeneruLe LIe seLs A = {a, b, c}, B = {b, c, d}, und C = {b, c, e}.
CompuLe LIe unIon und LIe InLersecLIon oI LIe LIree seLs, us weII us LIe dIIIerence
A\ (B C).
Ixercise q.1: nsLeud oI LIe bInury operuLors inlersecl und union, you cun
uIso use LIe correspondIng MuPAD IuncLIons inlersecl und union Lo compuLe
unIons und InLersecLIons oI seLs. TIese IuncLIons uccepL urbILrurIIy muny
urgumenLs. Use sImpIe communds Lo compuLe LIe unIon und LIe InLersecLIon oI
uII seLs beIongIng Lo M:
M .= {{Z 3] {3 4] {3 7] {5 3] {1 Z 3 4]].
q-q
4 NuPAD

Cb[ec|s
ubles
A LubIe Is u MuPAD

objecL oI domuIn Lype 00MTABLE. L Is u coIIecLIon oI


equuLIons oI LIe Iorm index=voiue. BoLI IndIces und vuIues muy be urbILrury
MuPAD objecLs. You cun generuLe u LubIe by usIng LIe sysLem IuncLIon lobie
(expIIcIL generuLIon):
T .= lobie(o = b c = d}
a b
c d
You cun generuLe more enLrIes or cIunge exIsLIng ones by Indexed ussIgnmenLs
oI LIe Iorm Tobie_index].=voiue:
T_f(x}] .= sin(x}. T_1 Z] .= 5.
T_1 Z 3] .= {o b c]. T_o] .= B.
T
a B
c d
f(x) sIn(x)
1, 2 5
1, 2, 3 {a, b, c}
L Is noL necessury Lo InILIuIIze u LubIe vIu lobie. I T Is un IdenLIIIer LIuL does noL
Iuve u vuIue, or Ius u vuIue wIIcI does noL uIIow Indexed uccess (sucI us un
InLeger or u IuncLIon), LIen un Indexed ussIgnmenL oI LIe Iorm T_index].=voiue
uuLomuLIcuIIy Lurns T InLo u LubIe (ImpIIcIL generuLIon):
deiele T. T_o] .= b. T_b] .= c. T
a b
b c
q-qo
Tobles
A LubIe muy be empLy:
T .= lobie(}
You muy deIeLe LubIe enLrIes vIu deiele Tobie_index]:
T .= lobie(o = b c = d d = o*c}.
deiele T_o] T_c]. T
d a c
You cun uccess LubIe enLrIes In LIe Iorm Tobie_index]; LIIs reLurns LIe eIemenL
correspondIng Lo LIe Index. I LIere Is no enLry Ior LIe Index, LIen MuPAD reLurns
Tobie_index] symboIIcuIIy:
T .= lobie(o = b c = d d = o*c}.
T_o] T_b] T_c] T_d]
b, T
b
, d, a c
TIe cuII op(Tobie} reLurns uII enLrIes oI u LubIe, I.e., LIe sequence oI uII equuLIons
index=voiue:
op(lobie(o = A b = B c = C d = 0}}
a = A, b = B, c = C, d = D
NoLe LIuL LIe InLernuI order oI LIe LubIe enLrIes muy dIIIer boLI Irom LIe order In
wIIcI you Iuve generuLed LIe LubIe und Irom LIe order oI enLrIes prInLed on LIe
screen. L muy Iook quILe rundom:
op(lobie(o.i = i^Z S i = 1..17}}
o16 = Z56 o9 = 1 o1Z = 144 o6 = 36 o3 = 9
o15 = ZZ5 o11 = 1Z1 o = 64 o5 = Z5 oZ = 4
o14 = 196 o10 = 100 o17 = Z9 o7 = 49 o4 = 16
o13 = 169 o1 = 1
q-q1
4 NuPAD

Cb[ec|s
TIe IuncLIon mop uppIIes u gIven IuncLIon Lo LIe tclues (noL LIe indices) oI uII
LubIe enLrIes:
T .= lobie(1 = PT Z = 4 3 = exp(1}}. mop(T fiool}
1 3.141592654
2 4.0
3 2.718281828
TIe IuncLIon conloins cIecks wIeLIer u LubIe conLuIns u purLIcuIur index. L
Ignores LIe tclues:
T .= lobie(o = b}. conloins(T o} conloins(T b}
TRUE, ASE
You muy empIoy LIe IuncLIons seiecl und spiil Lo InspecL both indices cnd
tclues oI u LubIe und Lo exLrucL LIem uccordIng Lo cerLuIn properLIes. TIIs works
sImIIurIy us Ior IIsLs (SecLIon q.6) und Ior seLs (SecLIon q.;):
T .= lobie(1 = "number" 1.0 = "number" x = "symboi"}.
seiecl(T hos "symboi"}
x symboI
seiecl(T hos 1.0}
1.0 number
spiil(T hos "number"}
_
1 number
1.0 number
,
x symboI
,
_
TubIes ure purLIcuIurIy weII suILed Ior sLorIng Iurge umounLs oI duLu. ndexed
uccesses Lo inditiducl eIemenLs ure ImpIemenLed eIIIcIenLIy uIso Ior bIg LubIes:
u wrILe or reud does noL IIIe LIrougI LIe wIoIe duLu sLrucLure.
q-q
Tobles
Ixercise q.: GeneruLe u LubIe leiephone0ireclory wILI LIe IoIIowIng enLrIes:
ord 1815, Reugun 4711, BusI 1234, CIInLon 5678.
ook up ord`s number. How cun you IInd ouL wIose number Is 5678?
Ixercise q.: GIven u LubIe, Iow cun you generuLe u IIsL oI uII IndIces und u IIsL
oI uII vuIues, respecLIveIy?
Ixercise q.q: GeneruLe LIe LubIe lobie(1=1Z=Z.n=n} und LIe IIsL
_1Z.n] oI IengLI n = 100000. Add u new enLry Lo LIe LubIe und Lo LIe IIsL.
How Iong does LIIs Luke? HInL: LIe cuII lime((o.=b}} reLurns LIe execuLIon LIme
Ior un ussIgnmenL.
q-q
4 NuPAD

Cb[ec|s
krruys
Arruys, oI domuIn Lype 00MARRAY, muy be regurded us specIuI LubIes. You muy
LIInk oI LIem us u coIIecLIon oI equuLIons oI LIe Iorm index=voiue, buL In
conLrusL Lo LubIes, LIe IndIces musL be InLegers. A one-dImensIonuI urruy consIsLs
oI equuLIons oI LIe Iorm i=voiue. MuLIemuLIcuIIy, IL represenLs u vecLor wIose
i-LI componenL Is voiue. A Lwo-dImensIonuI urruy represenLs u muLrIx, wIose
(i, j)-LI componenL Is sLored In LIe Iorm (ig}=voiue. You muy generuLe urruys
oI urbILrury dImensIon, wILI enLrIes oI LIe Iorm (igk.}=voiue.
TIe sysLem IuncLIon orroy generuLes urruys. n ILs sImpIesL Iorm, you onIy specIIy
u sequence oI runges LIuL deLermIne LIe dImensIon und LIe sIze oI LIe urruy:
A .= orroy(0..1 1..3}
+- -+
1 ?_0 1] ?_0 Z] ?_0 3] 1
1 1
1 ?_1 1] ?_1 Z] ?_1 3] 1
+- -+
You cun see Iere LIuL LIe IIrsL runge 0..1 und LIe second runge 1..3 deLermIne
LIe urruy`s number oI rows und coIumns, respecLIveIy. TIe ouLpuL ?_01] sIgnuIs
LIuL LIe correspondIng Index Ius noL been ussIgned u vuIue, yeL. TIus, LIe ubove
commund Ius generuLed un empLy urruy. Now, you cun ussIgn vuIues Lo LIe
IndIces:
A_0 1] .= 1. A_0 Z] .= Z. A_0 3] .= 3.
A_1 3] .= |ELL0. A
_
1 2 3
A
1,1
A
1,2
HEO
_
You cun uIso InILIuIIze LIe compIeLe urruy dIrecLIy wIen generuLIng IL by orroy.
JusL suppIy LIe vuIues us u (nesLed) IIsL:
A .= orroy(1..Z 1..3 __1 Z 3] _4 5 6]]}
_
1 2 3
4 5 6
_
q-qq
Arroys
You cun uccess und modIIy urruy eIemenLs In LIe sume wuy us LubIe eIemenLs:
A_Z 3] .= A_Z 3] + 10. A
_
1 2 3
4 5 16
_
AguIn, you muy deIeLe un urruy eIemenL by usIng deiele:
deiele A_1 1] A_Z 3]. A A_Z 3]
_
A
1,1
2 3
4 5 A
2,3
_
, A
2,3
Arruys possess u 0-LI operund op(Arroy0} provIdIng InIormuLIon on LIe
dImensIon und LIe sIze oI LIe urruy. TIe cuII op(Arroy0} reLurns u sequence d,
a
1
.. b
1
, . . . , a
d
.. b
d
, wIere d Is LIe dImensIon (I.e., LIe number oI IndIces) und a
i
.. b
i
Is LIe vuIId runge Ior LIe i-LI Index:
vec .= orroy(1..3 _x y z]}. op(vec 0}
1, 1..3
Mol .= orroy(1..Z 1..3 __o b c] _d e f]]}.
op(Mol 0}
2, 1..2, 1..3
TIus, LIe dImensIon oI un mn muLrIx orroy(1..m1..n} muy be obLuIned us
m=op(Mol_0ZZ]}, n=op(Mol_03Z]}.
TIe InLernuI sLrucLure oI urruys dIIIers Irom LIe sLrucLure oI LubIes. TIe enLrIes
ure noL sLored In LIe Iorm oI equuLIons:
op(Mol}
a, b, c, d, e, f
q-qg
4 NuPAD

Cb[ec|s
TIe LubIe Lype Is more IIexIbIe LIun LIe urruy Lype: LubIes udmIL urbILrury IndIces,
und LIeIr sIze muy grow dynumIcuIIy. Arruys ure InLended Ior sLorIng vecLors und
muLrIces oI u IIxed sIze. WIen you enLer un Indexed cuII, LIe sysLem cIecks
wIeLIer LIe IndIces ure wILIIn LIe specIIIed runges. or exumpIe:
Mol_4 7]
Error. Tiiegoi orgumenl _orroy]
You muy uppIy u IuncLIon Lo uII urruy componenLs vIu mop. or exumpIe, Iere Is
LIe sImpIesL wuy Lo converL uII urruy enLrIes Lo IIouLIng-poInL numbers:
A .= orroy(1..Z _PT 1/7]}. mop(A fiool}
_
3.141592654 0.1428571429
_
Wurning: I M Is un IdenLIIIer wILIouL u vuIue, LIen un Indexed ussIgnmenL oI LIe
Iorm M_indexindex...].=voiue generuLes u LubIe und noL un urruy oI Lype
00MARRAY (SecLIon q.8):
M_1 1] .= o. M
1, 1 a
AddILIonuIIy, MuPAD provIdes LIe more powerIuI duLu sLrucLures oI domuIn Lype
0om..Molrix Ior IundIIng vecLors und muLrIces. TIese ure dIscussed In
SecLIon q.1. SucI objecLs ure very convenIenL Lo use: you cun muILIpIy Lwo
muLrIces or u muLrIx und u vecLor by meuns oI LIe usuuI muILIpIIcuLIon symboI *.
SImIIurIy, you cun udd muLrIces oI equuI dImensIon vIu +. To ucIIeve LIe sume
IuncLIonuIILy wILI urruys, you Iuve Lo wrILe your own procedures. We reIer Lo LIe
exumpIes MolrixProducl und MolrixMuil In SecLIons 1;.q und 1;., respecLIveIy.
Ixercise q.g: GeneruLe u so-cuIIed HIIberL muLrIx H oI dImensIon 20 20 wILI
enLrIes H
ij
= 1/(i +j 1).
q-q6
ooleon Epressions
8eeleua xpressieas
MuPAD

ImpIemenLs LIree IogIcuI (BooIeun) vuIues: TRuE, FALSE, und uWKW0nW:


domlype(TRuE} domlype(FALSE} domlype(uWKW0nW}
DOM_BOO, DOM_BOO, DOM_BOO
TIe operuLors ond, or, und nol operuLe on BooIeun vuIues:
TRuE ond FALSE nol (TRuE or FALSE} TRuE ond uWKW0nW
TRuE or uWKW0nW
ASE, ASE, UNKNOWN, TRUE
TIe IuncLIons correspondIng Lo LIese operuLors ure ond, or, und nol,
respecLIveIy.
TIe IuncLIon booi evuIuuLes equuLIons, InequuIILIes, or compurIsons vIu >, >=, < ,
<=, Lo TRuE or FALSE:
booi(1 = Z} booi(1 <> Z}
booi(1 <= Z} or nol booi(1 > Z}
ASE, TRUE, TRUE
NoLe LIuL booi cun onIy compure reuI numbers suIIIcIenLIy dIsLIncL Irom one
unoLIer. EspecIuIIy exucL symboIIc represenLuLIons oI LIe sume number cunnoL be
compured wILI booi:
booi(3 <= PT}
TRUE
booi(sqrl(Z}*sqrl(3} <= sqrl(6}}
Error. Conl evoiuole lo booieon _ieequoi]
booi(14539Z67/47316765Z <= PT}
Error. Conl evoiuole lo booieon _ieequoi]
TypIcuIIy, you wIII use BooIeun consLrucLs In bruncIIng condILIons oI if
InsLrucLIons (CIupLer 16) or In LermInuLIon condILIons oI repeol Ioops (CIupLer
1). n LIe IoIIowIng exumpIe, we LesL LIe InLegers 1, 2, 3 Ior prImuIILy. TIe sysLem
IuncLIon isprime (Is LIe urgumenL u prIme number?) reLurns TRuE or FALSE. TIe
repeol Ioop sLops us soon us LIe LermInuLIon condILIon i = 3 evuIuuLes Lo TRuE:
q-q,
4 NuPAD

Cb[ec|s
i .= 0.
repeol
i .= i + 1
if isprime(i}
lhen prinl(i "is o prime"}
eise prinl(i "is no prime"}
endif
unlii i = 3 endrepeol
1 "is no prime"
Z "is o prime"
3 "is o prime"
Here we Iuve used sLrIngs encIosed In " Ior LIe screen ouLpuL. TIey ure dIscussed
In deLuII In SecLIon q.11. NoLe LIuL IL Is noL necessury Lo use LIe IuncLIon booi In
bruncIIng or LermInuLIon condILIons In order Lo evuIuuLe LIe condILIon Lo TRuE or
FALSE.
Ixercise q.6: eL denoLe LIe IogIcuI und, IeL denoLe LIe IogIcuI or, IeL
denoLe IogIcuI neguLIon. To wIIcI BooIeun vuIue does
TRUE (ASE (ASE ASE))
evuIuuLe?
Ixercise q.,: eL L1LZ be Lwo MuPAD IIsLs oI equuI IengLI. How cun you IInd
ouL wIeLIer L1_i]<LZ_i] IoIds Lrue Ior uII IIsL eIemenLs?
q-qS
5|rings
$Iriags
Strins ure pIeces oI LexL, wIIcI muy be used Ior IormuLLed screen ouLpuL. A sLrIng
Is u sequence oI urbILrury symboIs encIosed In sLrIng deIImILers ". Ls domuIn
Lype Is 00MSTRTWC.
slring1 .= "use * for muilipiicolion"
slringZ .= " "
slring3 .= "use ^ for exponenliolion."
Use Ior muILIpIIcuLIon
,
use ` Ior exponenLIuLIon.
TIe concuLenuLIon operuLor . combInes sLrIngs:
slring4 .= slring1.slringZ.slring3
Use Ior muILIpIIcuLIon, use ` Ior exponenLIuLIon.
TIe doL operuLor Is u sIorL Iorm oI LIe MuPAD

IuncLIon concol, wIIcI


concuLenuLes (urbILrurIIy muny) sLrIngs:
concol("This is " "o slring" "."}
TIIs Is u sLrIng.
TIe Index operuLor _] exLrucLs LIe cIurucLers Irom u sLrIng:
slring4_1] slring4_Z] slring4_3]
slring4_4] slring4_5]
U, s, e, ,
WIen usIng u runge us Index, subsLrIngs ure reLurned; neguLIve IndIces counL Irom
LIe end oI LIe sLrIng:
slring4_19..Z1] slring4_-15..-]
cuL, exponenL
You muy use LIe commund prinl Lo ouLpuL InLermedIuLe resuILs In Ioops or
procedures on LIe screen (SecLIon 1z.1). By deIuuIL, LIIs IuncLIon prInLs sLrIngs
q-qq
4 NuPAD

Cb[ec|s
wILI LIe encIosIng doubIe quoLes. You muy cIunge LIIs beIuvIor by usIng LIe
opLIon unquoled:
prinl(slring4}
"use * for muilipiicolion use ^ for exponenliolion."
prinl(unquoled slring4}
use * for muilipiicolion use ^ for exponenliolion.
SLrIngs ure noL vuIId IdenLIIIers In MuPAD, so you cunnoL ussIgn vuIues Lo LIem:
"nome" .= sin(x}
Error. Tnvoiid iefl-hond side in ossignmenl _iine 1 coi ]
AIso, urILImeLIc wILI sLrIngs Is noL uIIowed:
1 + "x"
Error. Tiiegoi operond _pius]
However, you muy use sLrIngs In equuLIons:
"derivolive of sin(x}" = cos(x}
derIvuLIve oI sIn(x) = cos(x)
TIe IuncLIon exprZlexl converLs u MuPAD objecL Lo u sLrIng. You cun empIoy LIIs
IuncLIon Lo cusLomIze prInL communds:
i .= 7.
prinl(unquoled exprZlexl(i}." is o prime."}
7 is o prime.
o .= sin(x}.
prinl(unquoled "The derivolive of " . exprZlexl(o} .
" is " . exprZlexl(diff(o x}}. "."}
The derivolive of sin(x} is cos(x}.
TIe documenLuLIon oI prinl conLuIns more udvunced exumpIes oI user-deIIned
ouLpuL, see ?prinl.
You IInd numerous oLIer useIuI IuncLIons Ior IundIIng sLrIngs In LIe sLundurd
IIbrury (SecLIon MunIpuIuLIon oI SLrIngs oI LIe MuPAD QuIck ReIerence) und In
LIe sLrIng IIbrury (?slringiib).
q-go
5|rings
Ixercise q.S: TIe commund onomes(Aii} reLurns u seL oI uII IdenLIIIers LIuL
Iuve u vuIue In LIe currenL sessIon. GeneruLe u lexicorcphiccll ordered IIsL oI
LIese IdenLIIIers.
Ixercise q.q: How cun you obLuIn LIe mIrror Imuge oI u sLrIng? HInL: LIe
IuncLIon ienglh reLurns LIe number oI symboIs In u sLrIng.
q-g1
4 NuPAD

Cb[ec|s
luatIieas
TIe urrow operuLors -> (u mInus sIgn IoIIowed by u greuLer LIun sIgn) und -->
(Lwo mInus sIgns IoIIowed by u greuLer LIun sIgn) generuLe sImpIe objecLs LIuL
represenL muLIemuLIcuI IuncLIons:
f .= (x y} -> x^Z + y^Z
(x, y) x
2
+y
2
TIe IuncLIon f cun now be cuIIed IIke uny sysLem IuncLIon. L Lukes Lwo urbILrury
InpuL purumeLers (or urgumenLs) und reLurns LIe sum oI LIeIr squures:
f(o b + 1}
(b + 1)
2
+a
2
n LIe IoIIowIng exumpIe, LIe reLurn vuIue oI LIe IuncLIon Is generuLed by un if
sLuLemenL:
obsvoiue .= x -> if x >= 0 lhen x eise -x endif.
obsvoiue(-Z.3}
2.3
As dIscussed In SecLIon q.q, LIe operuLor e generuLes LIe composILIon
h : x f(g(x)) oI Lwo IuncLIons f und g:
f .= x -> 1/(1 + x}. g .= x -> sin(x^Z}.
h .= feg. h(o}
1
sIn(a
2
) + 1
You cun deIIne u repeuLed composILIon f(f(f())) oI u IuncLIon wILI ILseII by usIng
LIe ILeruLIon operuLor ee:
fff .= fee3. fff(o}
1
1
1
a+1
+1
+ 1
q-g
Func|ions
OI course, LIese consLrucLIons uIso work Ior sysLem IuncLIons. or exumpIe, LIe
IuncLIon obseRe compuLes LIe ubsoIuLe vuIue oI LIe reuI purL oI u compIex
number:
f .= obseRe. f(-Z + 3*T}
2
n symboIIc compuLuLIons, you oILen Iuve LIe cIoIce Lo represenL u muLIemuLIcuI
IuncLIon eILIer us u mcp orgumenls voiue or us un expression:
Mop .= x -> Z*x*cos(x^Z}.
Expression .= Z*x*cos(x^Z}.
inl(Mop(x} x} inl(Expression x}
sIn
_
x
2
_
, sIn
_
x
2
_
I you Lry Lo converL un expressIon InLo u IuncLIon by meuns oI LIe -> operuLor,
you wIII IInd LIuL IL does noL quILe work:
h .= x -> Expression.
h(1}
2 x cos
_
x
2
_
nsLeud, use LIe Iong urrow operuLor -->, wIIcI evuIuuLes LIe rIgIL Iund sIde
expressIon, us expIuIned In CIupLer und reLurns u IuncLIon, wIIcI you cun
munIpuIuLe IurLIer:
h .= x --> Expression
x 2 x cos
_
x
2
_
h
x 2 cos
_
x
2
_
4 x
2
sIn
_
x
2
_
ndeed, h Is LIe IuncLIonuI equIvuIenL oI diff(Expressionx}:
h(x} = diff(Expression x}
2 cos
_
x
2
_
4 x
2
sIn
_
x
2
_
= 2 cos
_
x
2
_
4 x
2
sIn
_
x
2
_
q-g
4 NuPAD

Cb[ec|s
MuPAD cun represenL mups by meuns oI junctioncl expressions: IuncLIons ure
consLrucLed Irom sImpIe IuncLIons (sucI us sin, cos, exp, in, id) by meuns oI
operuLors (sucI us LIe composILIon operuLor e or LIe urILImeLIc operuLors +, *,
eLc.). NoLe LIuL LIe urILImeLIc operuLors generuLe IuncLIons LIuL ure deIIned
pointuise, wIIcI Is muLIemuLIcuIIy sound. or exumpIe, f +g represenLs LIe mup
x f(x) +g(x), f g represenLs LIe mup x f(x) g(x), eLc.:
deiele f g.
o .= f + g. b .= f*g. c .= f/g.
o(x} b(x} c(x}
f(x) +g(x) , f(x) g(x) ,
f(x)
g(x)
You ure uIIowed Lo Iuve numerIcuI vuIues In IuncLIonuI expressIons. MuPAD
regurds LIem us consLunL IuncLIons wIIcI uIwuys reLurn LIe purLIcuIur vuIue:
1(x} 0.1(x y z} PT(x}
1, 0.1,
o .= f + 1. b .= f*3/4. c .= f + 0.1. d .= f + sqrl(Z}.
o(x} b(x} c(x} d(x}
f(x) + 1,
3 f(x)
4
, f(x) + 0.1, f(x) +

2
L Is uIso possIbIe Lo use IuncLIons wILIouL ussIgnIng LIem Lo un IdenLIIIer und Lo
puss LIem us urgumenLs Lo oLIer IuncLIons. We Iuve used LIIs possIbIIILy beIore,
so Ior recupILuIuLIon, we jusL gIve unoLIer sImpIe exumpIe:
mop(_1 Z 3 4] i -> i^Z}
[1, 4, 9, 16]
TIe operuLor -> Is useIuI Ior deIInIng IuncLIons wIose reLurn vuIue cun be
obLuIned by sImpIe operuLIons. uncLIons ImpIemenLIng more compIex
uIgorILIms usuuIIy requIre muny communds und uuxIIIury vurIubIes Lo sLore
InLermedIuLe resuILs. n prIncIpIe, you cun deIIne sucI IuncLIons vIu -> us weII.
However, LIIs Ius LIe druwbuck LIuL you oILen use lobcl tcricbles. nsLeud, we
recommend Lo deIIne u procedure vIu proc(} begin ... endproc. TIIs concepL
oI LIe MuPAD progrummIng Iunguuge Is mucI more IIexIbIe und Is dIscussed In
q-gq
Func|ions
more deLuII In CIupLer 1;.
Ixercise q.o: DeIIne LIe IuncLIons f(x) = x
2
und g(x) =

x. CompuLe
f(f(g(2)) und f(f(. . . f
. .
100 LImes
(x) . . . )) .
Ixercise q.1: DeIIne u IuncLIon LIuL reverses LIe order oI LIe eIemenLs In u IIsL.
Ixercise q.: TIe Chebshet polnomicls ure deIIned recursIveIy by LIe
IoIIowIng IormuIue:
T
0
(x) = 1 , T
1
(x) = x , T
k
(x) = 2 xT
k1
(x) T
k2
(x) .
CompuLe LIe vuIues oI T
2
(x), . . . , T
5
(x) Ior x = 1/3, x = 0.33, und Ior u symboIIcuI
vuIue x.
q-gg
4 NuPAD

Cb[ec|s
$eries xpuasieas
ExpressIons sucI us 1/(1-x} udmIL serIes expunsIons Ior symboIIc purumeLers.
TIIs purLIcuIurIy sImpIe exumpIe Is LIe sum oI LIe geomeLrIc serIes:
1
1 x
= 1 +x +x
2
+x
3
+
TIe IuncLIon loyior compuLes LIe IeudIng Lerms oI sucI serIes:
l .= loyior(1/(1 - x} x = 0 9}
1 +x +x
2
+x
3
+x
4
+x
5
+x
6
+x
7
+x
8
+O
_
x
9
_
TIIs Is LIe TuyIor serIes expunsIon oI LIe expressIon uround LIe poInL x = 0, us
requesLed by LIe second urgumenL. MuPAD

Ius LruncuLed LIe InIInILe serIes


beIore LIe Lerm x
9
und Ius coIIecLed LIe LuII In LIe bIg OI Lerm O(x
9
) (uIso
cuIIed LIe unduu symboI). TIe (opLIonuI) LIIrd urgumenL oI loyior conLroIs
LIe LruncuLIon. I IL Is noL presenL, LIen MuPAD uses LIe vuIue oI LIe envIronmenL
vurIubIe 0R0ER InsLeud, wIose deIuuIL vuIue Is 6:
l .= loyior(1/(1 - x} x = 0}
1 +x +x
2
+x
3
+x
4
+x
5
+O
_
x
6
_
TIe resuILIng serIes Iooks IIke un ordInury sum wILI un uddILIonuI 0(} Lerm.
nLernuIIy, Iowever, IL Is represenLed by u specIuI duLu sLrucLure oI domuIn Lype
Series..Puiseux
domlype(l}
SerIes::PuIseux
TIe bIg-OI Lerm ILseII Is u duLu sLrucLure on ILs own, oI domuIn Lype 0 und wILI
specIuI ruIes oI munIpuIuLIon:
Z*0(x^Z} + 0(x^3} x^Z*0(x^10} 0(x^5}*0(x^Z0}
diff(0(x^3} x}
O
_
x
2
_
, O
_
x
12
_
, O
_
x
25
_
, O
_
x
2
_
TIe orderIng oI LIe Lerms In u TuyIor serIes Is IIxed: powers wILI smuIIer
exponenLs precede LIose wILI IIgIer exponenLs. TIIs Is In conLrusL Lo LIe orderIng
In ordInury sums, wIere IIgI exponenLs precede smuII exponenLs:
q-g6
5eries Eponsions
S .= expr(l}
x
5
+x
4
+x
3
+x
2
+x + 1
Here we Iuve used LIe sysLem IuncLIon expr Lo converL LIe serIes Lo un expressIon
oI domuIn Lype 00MEXPR. As you cun see In LIe ouLpuL, LIe 0(} Lerm Ius been cuL
oII.
TIe op commund ucLs on serIes In u non-obvIous wuy und sIouId noL be used:
op(l}
0, 1, 0, 6, [1, 1, 1, 1, 1, 1] , x = 0, UndIrecLed
TIereIore, LIe IuncLIon coeff Is provIded Lo exLrucL LIe coeIIIcIenLs. TIIs Is more
InLuILIve LIun op. TIe cuII coeff(li} reLurns LIe coeIIIcIenL oI x
i
:
l .= loyior(cos(x^Z} x Z0}
1
x
4
2
+
x
8
24

x
12
720
+
x
16
40320
+O
_
x
20
_
coeff(l 0} coeff(l 1} coeff(l 1Z} coeff(l Z5}
1, 0,
1
720
, A
n LIe prevIous exumpIe, we Iuve suppIIed x us second urgumenL Lo specIIy LIe
poInL oI expunsIon. TIIs Is equIvuIenL Lo x=0.
TIe usuuI urILImeLIc operuLIons uIso work Ior serIes:
o .= loyior(cos(x} x 3}. b .= loyior(sin(x} x 4}.
o b
1
x
2
2
+O
_
x
4
_
, x
x
3
6
+O
_
x
5
_
o + b Z*o*b o^Z
1 +x
x
2
2

x
3
6
+O
_
x
4
_
, 2 x
4 x
3
3
+O
_
x
5
_
, 1 x
2
+O
_
x
4
_
q-g,
4 NuPAD

Cb[ec|s
BoLI LIe composILIon operuLor e und LIe ILeruLIon operuLor ee uppIy Lo serIes us
weII:
o .= loyior(sin(x} x Z0}.
b .= loyior(orcsin(x} x Z0}. oeb
x +O
_
x
21
_
I you Lry Lo compuLe LIe TuyIor serIes oI u IuncLIon LIuL does noL Iuve one, LIen
loyior uborLs wILI un error. TIe IuncLIon series cun compuLe more generuI
expunsIons (uurenL serIes, PuIseux serIes):
loyior(cos(x}/x x = 0 10}
Error. 1/x*cos(x} does nol hove o Toyior series `
exponsion lry series _loyior]
series(cos(x}/x x = 0 10}
1
x

x
2
+
x
3
24

x
5
720
+
x
7
40320
+O
_
x
9
_
You cun generuLe serIes expunsIons In Lerms oI neguLIve powers by expundIng
uround LIe poInL infinily:
series((x^Z + 1}/(x + 1} x = infinily}
x 1 +
2
x

2
x
2
+
2
x
3

2
x
4
+O
_
1
x
5
_
TIIs Is un exumpIe Ior un usympLoLIc expunsIon, wIIcI upproxImuLes LIe
beIuvIor oI u IuncLIon Ior Iurge vuIues oI LIe urgumenL. n sImpIe cuses, series
reLurns un expunsIon In Lerms oI neguLIve powers oI x, buL oLIer IuncLIons muy
Lurn up us weII:
series((exp(x} - exp(-x}}/(exp(x} + exp(-x}}
x = infinily}
1
2
e
2 x
+
2
e
4 x

2
e
6 x
+
2
e
8 x

2
e
10 x
+O
_
e
12 x
_
q-gS
5eries Eponsions
Ixercise q.: TIe order p oI u rooL x oI u IuncLIon f Is LIe muxImuI number oI
derIvuLIves LIuL vunIsI uL LIe poInL x:
f(x) = f

(x) = = f
(p1)
(x) = 0 , f
(p)
(x) = 0 .
WIuL Is LIe order oI LIe rooL x = 0 oI f(x) = Lun(sIn(x)) sIn(Lun(x))?
Ixercise q.q: BesIdes LIe urILImeLIcuI operuLors, some oLIer sysLem IuncLIons
sucI us diff or inl work dIrecLIy Ior serIes. Compure LIe resuIL oI
loyior(diff(1/(1-x}x}x} und LIe derIvuLIve oI loyior(1/(1-x}x}.
MuLIemuLIcuIIy, boLI serIes ure IdenLIcuI. Cun you expIuIn LIe dIIIerence In
MuPAD?
Ixercise q.g: TIe IuncLIon f(x) =

x + 1

x 1 Lends Lo zero Ior Iurge x,


I.e., IIm
x
f(x) = 0. SIow LIuL LIe upproxImuLIon f(x) 1/

x Is vuIId Ior Iurge


vuIues oI x. Ind beLLer usympLoLIc upproxImuLIons oI f.
Ixercise q.6: CompuLe LIe IIrsL LIree Lerms In LIe serIes expunsIon oI LIe
IuncLIon f.=sin(x+x^3} uround x=0. Reud LIe IeIp puge Ior LIe MuPAD
IuncLIon reverl. Use LIIs IuncLIon Lo compuLe LIe IeudIng Lerms oI LIe serIes
expunsIon oI LIe Inverse IuncLIon f
1
(wIIcI Is weII-deIIned In u cerLuIn
neIgIborIood oI x = 0).
q-gq
4 NuPAD

Cb[ec|s
klgebruit $IrutIures: lields, kiags, eIt.
TIe MuPAD

kerneI provIdes domuIn Lypes Ior LIe busIc duLu sLrucLures sucI us
numbers, seLs, LubIes, eLc. n uddILIon, you cun deIIne your own duLu sLrucLures In
LIe MuPAD Iunguuge und work wILI LIem symboIIcuIIy. We do noL dIscuss LIe
consLrucLIon oI sucI new domuIns In LIIs eIemenLury InLroducLIon, buL
demonsLruLe some specIuI IIbrury domuIns provIded by LIe sysLem.
BesIdes LIe kerneI domuIns, LIe 0om IIbrury conLuIns u vurIeLy oI predeIIned
domuIns LIuL were ImpIemenLed by LIe MuPAD deveIopers. or un overvIew, see
LIe reIerence documenLuLIon. n LIIs secLIon, we presenL some purLIcuIurIy useIuI
domuIns represenLIng compIex muLIemuLIcuI objecLs sucI us IIeIds, rIngs, eLc.
SecLIon q.1 dIscusses u duLu Lype Ior muLrIces, wIIcI Is weII-suILed Ior probIems
In IIneur uIgebru.
TIe muIn purL oI u domuIn Is ILs constructor, wIIcI generuLes objecLs oI LIe
domuIn. EucI sucI objecL knows ILs domuIn, wIIcI Ius methods uLLucIed Lo IL.
TIey represenL LIe muLIemuLIcuI operuLIons Ior LIese objecLs.
Here Is u IIsL oI some oI LIe weII-known muLIemuLIcuI sLrucLures ImpIemenLed In
LIe 0om IIbrury:
LIe rIng oI InLegers Z : 0om..Tnleger,
LIe IIeId oI ruLIonuI numbers Q : 0om..Rolionoi,
LIe IIeId oI reuI numbers R : 0om..Reoi or 0om..Fiool,
;
LIe IIeId oI compIex numbers C : 0om..Compiex,
LIe rIng oI InLegers moduIo n: 0om..TnlegerMod(n}.
We consIder LIe resIdue cIuss rIng oI InLegers moduIo n. Ls eIemenLs ure LIe
InLegers 0, 1, . . . , n 1, und uddILIon und muILIpIIcuLIon ure deIIned moduIo n.
TIIs works by uddIng or muILIpIyIng In Z, dIvIdIng LIe resuIL by n, und LukIng LIe
remuInder oI LIIs dIvIsIon In {0, 1, . . . , n 1}:
;
0om..Reoi Is Ior symboIIc represenLuLIons oI reuI numbers, wIIIe 0om..Fiool represenLs LIem us
IIouLIng-poInL numbers.
q-6o
Algebroic 5|ruc|ures: Fields, kings, e|c.
3*5 mod 7
1
n LIIs exumpIe, we Iuve used LIe duLu Lypes oI LIe MuPAD kerneI: LIe operuLor *
muILIpIIes LIe InLegers 3 und 5 In LIe usuuI wuy Lo geL 15, und LIe operuLor mod
compuLes LIe decomposILIon 15 = 2 7 + 1 und reLurns 1 us remuInder moduIo 7.
AILernuLIveIy, you muy LeII MuPAD LIuL you wunL Lo compuLe In Z
7
= Z/7 Z by
usIng LIe InpuL synLux 0om..TnlegerMod(7}. TIe IuLLer objecL ucLs us u
consLrucLor Ior eIemenLs oI LIe resIdue cIuss rIng
8
moduIo 7:
conslruclor .= 0om..TnlegerMod(7}.
x .= conslruclor(3} y .= conslruclor(5}
3 mod7
5 mod7
As you cun see Irom LIe screen ouLpuL, LIe IdenLIIIers x und y do noL Iuve LIe
InLegers 3 und 5, respecLIveIy, us vuIues. nsLeud, LIe numbers ure eIemenLs oI LIe
resIdue cIuss rIng oI InLegers moduIo 7:
domlype(x} domlype(y}
Z
7
, Z
7
Now, you cun use LIe usuuI urILImeLIc operuLIons, und MuPAD uuLomuLIcuIIy uses
LIe compuLuLIon ruIes oI LIe resIdue cIuss rIng:
x*y x^1Z3*y^17 - x + y
1 mod7, 6 mod7
TIe rIng 0om..TnlegerMod(7} even Ius u IIeId sLrucLure, so LIuL you cun dIvIde by
uII rIng eIemenLs excepL 0 mod 7:
8
I you wunL Lo execuLe onIy u smuII number oI moduIo operuLIons, IL Is oILen preIerubIe Lo use
LIe operuLor mod, wIIcI Is ImpIemenLed In LIe MuPAD kerneI und quILe IusL. TIIs upproucI muy
requIre some uddILIonuI undersLundIng Iow LIe sysLem IuncLIons work. or exumpIe, LIe compu-
LuLIon oI 17^Z9999 mod 7 Lukes quILe u Iong LIme, sInce MuPAD IIrsL compuLes LIe very bIg num-
ber 17
29999
und LIen reduces LIe resuIL moduIo 7. n LIIs cuse, LIe compuLuLIon x^Z9999, wIere
x.=0om..TnlegerMod(7}(17}, Is mucI IusLer sInce LIe InLernuI moduIur urILImeLIc uvoIds sucI bIg
numbers. AILernuLIveIy, LIe cuII poWermod(17Z99997} uses LIe sysLem IuncLIon poWermod Lo com-
puLe LIe resuIL quIckIy wILIouL empIoyIng 0om..TnlegerMod(7}.
q-61
4 NuPAD

Cb[ec|s
x/y
2 mod7
A more ubsLrucL exumpIe Is LIe IIeId exLensIon
K = Q[

2 ] = {p +q

2 ; p, q Q } .
You muy deIIne LIIs IIeId vIu
K .= 0om..AigebroicExlension(0om..Rolionoi
SqrlZ^Z = Z SqrlZ}.
Here LIe IdenLIIIer SqrlZ ( =

2), deIIned by ILs uIgebruIc properLy SqrlZ^Z=Z, Is


used Lo exLend LIe ruLIonuI numbers 0om..Rolionoi. Now, you cun compuLe In
LIIs IIeId:
x .= K(1/Z + Z*SqrlZ}. y .= K(1 + Z/3*SqrlZ}.
x^Z*y + y^4
677 SqrLz
54
+
5845
324
TIe domuIn 0om..ExpressionFieid(normoiizerzerolesl} represenLs LIe
IIeId oI (symboIIc) MuPAD expressIons. TIe consLrucLor Is purumeLrIzed by Lwo
IuncLIons normoiizer und zerolesl, wIIcI muy be cIosen by LIe user.
TIe IuncLIon zerolesl Is cuIIed InLernuIIy by uII uIgorILIms LIuL wunL Lo decIde
wIeLIer u domuIn objecL Is muLIemuLIcuIIy 0. TypIcuIIy, you wIII use LIe sysLem
IuncLIon iszero, wIIcI recognIzes noL onIy LIe InLeger 0 us zero, buL uIso oLIer
objecLs sucI us LIe IIouLIng-poInL number 0.0 or LIe poIynomIuI poiy(0_x]}
(SecLIon q.16).
TIe Lusk oI LIe IuncLIon normoiizer Is Lo generuLe u normuI Iorm Ior MuPAD
objecLs oI Lype 0om..ExpressionFieid(}. OperuLIons on sucI objecLs wIII use
LIIs IuncLIon Lo sImpIIIy LIe resuIL beIore reLurnIng IL. or exumpIe, II you suppIy
LIe IdenLILy IuncLIon id Ior LIe normoiizer urgumenL, LIen operuLIons on objecLs
oI LIIs domuIn work IIke Ior LIe usuuI MuPAD expressIons wILIouL uddILIonuI
normuIIzuLIon:
conslruclor .= 0om..ExpressionFieid(id iszero}.
x .= conslruclor(o/(o + b}^Z}.
y .= conslruclor(b/(o + b}^Z}.
q-6
Algebroic 5|ruc|ures: Fields, kings, e|c.
x + y
a
(a +b)
2
+
b
(a +b)
2
I you suppIy LIe sysLem IuncLIon normoi InsLeud, LIe resuIL Is sImpIIIIed
uuLomuLIcuIIy (SecLIon q.1):
conslruclor .= 0om..ExpressionFieid(normoi iszero}.
x .= conslruclor(o/(o + b}^Z}.
y .= conslruclor(b/(o + b}^Z}.
x + y
1
a +b
We noLe LIuL LIe purpose oI sucI MuPAD domuIns Is noL necessurIIy LIe dIrecL
generuLIon oI duLu sLrucLures or LIe compuLuLIon wILI LIe correspondIng objecLs.
ndeed, some consLrucLors sImpIy reLurn objecLs oI LIe underIyIng kerneI
domuIns, II sucI domuIns exIsL:
domlype(0om..Tnleger(Z}}
domlype(0om..Rolionoi(Z/3}}
domlype(0om..Fiool(PT}}
domlype(0om..ExpressionFieid(id iszero}(o + b}}
DOM_NT, DOM_RAT, DOM_OAT, DOM_EXPR
n LIese cuses, LIere Is no ImmedIuLe beneIIL In usIng sucI u consLrucLor; you muy
us weII compuLe dIrecLIy wILI LIe correspondIng kerneI objecLs. TIe muIn
uppIIcuLIon oI sucI specIuI duLu sLrucLures Is LIe consLrucLIon oI more compIex
muLIemuLIcuI sLrucLures. A sImpIe exumpIe Is LIe generuLIon oI muLrIces
(SecLIon q.1) or poIynomIuIs (SecLIon q.16) wILI enLrIes In u purLIcuIur rIng, sucI
LIuL muLrIx or poIynomIuI urILImeLIc, respecLIveIy, Is perIormed uccordIng Lo LIe
compuLuLIon ruIes oI LIe coeIIIcIenL rIng.
q-6
4 NuPAD

Cb[ec|s
etIers uad MuIrites
n SecLIon q.1q, we Iuve gIven exumpIes oI specIuI duLu Lypes (domuIns) Ior
deIInIng uIgebruIc sLrucLures sucI us rIngs, IIeIds, eLc. In MuPAD

. n LIIs secLIon,
we dIscuss Lwo IurLIer domuIns Ior generuLIon und convenIenL compuLuLIon wILI
vecLors und muLrIces: 0om..Molrix und 0om..SquoreMolrix. n prIncIpIe, you
muy use urruys Ior workIng wILI vecLors or muLrIces (SecLIon q.q). However, LIen
you Iuve Lo deIIne you own rouLInes Ior uddILIon, muILIpIIcuLIon, InversIon, or
deLermInunL compuLuLIon, usIng LIe MuPAD progrummIng Iunguuge (CIupLer 1;).
or LIe specIuI muLrIx Lype LIuL we presenL In wIuL IoIIows, sucI rouLInes exIsL
und ure uLLucIed Lo LIe muLrIces us meLIods. Moreover, you muy use LIe
IuncLIons oI LIe iinoig IIbrury (IIneur uIgebru, SecLIon q.1), wIIcI cun IundIe
muLrIces oI LIIs Lype.
eIinition oI Mutrices und Vectors
VecLors In MuPAD

ure regurded us specIuI muLrIces oI dImensIon 1 n or n 1,


respecLIveIy. TIe commund molrix muy be used Ior creuLIng muLrIces und vecLors
oI urbILrury dImensIon:
molrix(__ 1 Z 3 4 ]
_ o b c d ]
_sin(x} cos(x} exp(x} in(x}]]}
molrix(_x1 xZ x3 x4]}
_
_
_
1 2 3 4
a b c d
sIn(x) cos(x) e
x
In(x)
_
_
_,
_
_
_
_
_
_
x1
xz
x
xq
_
_
_
_
_
_
ArbILrury urILImeLIcuI expressIons muy be used us eIemenLs. AILIougI muLrIces
creuLed by molrix ure suILubIe Ior mosL uppIIcuLIons und wIII be LIe mosL wIdeIy
used muLrIx objecLs, MuPAD`s concepL Ior muLrIces Is more generuI. TypIcuIIy, u
specIIIc coeIIIcIenL rIng Ior LIe eIemenLs Is uLLucIed Lo u MuPAD muLrIx. n IucL,
LIe IuncLIon molrix Is jusL u consLrucLor wILI u sIorL nume Ior specIuI muLrIces oI
domuIn Lype 0om..Molrix(R}, wIere R=0om..ExpressionFieid(} represenLs
urbILrury MuPAD expressIons.
q-6q
Vec|ors ond No|rices
We expIuIn LIe generuI concepL. MuPAD provIdes LIe duLu Lype 0om..Molrix Ior
muLrIces oI urbILrury dImensIon mn. TIe Lype 0om..SquoreMolrix represenLs
squure muLrIces oI dImensIon n n. TIey beIong Lo LIe IIbrury 0om, wIIcI uIso
comprIses duLu Lypes Ior muLIemuLIcuI sLrucLures sucI us rIngs und IIeIds
(SecLIon q.1q). MuLrIces muy Iuve enLrIes Irom u seL LIuL musL be equIpped wILI u
rIng sLrucLure In LIe muLIemuLIcuI sense. or exumpIe, you muy use LIe
predeIIned rIngs und IIeIds sucI us 0om..Tnleger, 0om..TnlegerMod(n}, eLc. Irom
LIe 0om IIbrury.
TIe cuII 0om..Molrix(R} creuLes LIe consLrucLor Ior muLrIces oI urbILrury
dImensIon mn wILI coeIIIcIenLs In LIe rIng R. WIen you consLrucL sucI u
muLrIx, you ure requIred Lo ensure LIuL ILs enLrIes beIong Lo (or muy be converLed
Lo) LIIs rIng. You sIouId keep LIIs In mInd wIen LryIng Lo generuLe muLrIces wILI
enLrIes ouLsIde LIe coeIIIcIenL rIng In u compuLuLIon (Ior exumpIe, LIe Inverse oI
un InLeger muLrIx In generuI Ius non-InLegruI ruLIonuI enLrIes).
TIe IoIIowIng exumpIe yIeIds LIe consLrucLor Ior muLrIces wILI ruLIonuI number
enLrIes:
conslruclor .= 0om..Molrix(0om..Rolionoi}
Dom::MuLrIx(Q)
Now, you muy generuLe muLrIces oI urbILrury dImensIons. n LIe IoIIowIng
exumpIe, we generuLe u 2 3 muLrIx wILI uII enLrIes InILIuIIzed Lo 0:
A .= conslruclor(Z 3}
_
0 0 0
0 0 0
_
WIen generuLIng u muLrIx, you muy suppIy u IuncLIon f LIuL Lukes Lwo urgumenLs.
TIen LIe enLry In row i und coIumn j Is InILIuIIzed wILI f(i, j):
f .= (i g} -> (i*g}. A .= conslruclor(Z 3 f}
_
1 2 3
2 4 6
_
q-6g
4 NuPAD

Cb[ec|s
AILernuLIveIy, you cun InILIuIIze u muLrIx by specIIyIng u (nesLed) IIsL. EucI IIsL
eIemenL Is ILseII u IIsL und corresponds Lo one row oI LIe muLrIx. TIe IoIIowIng
commund generuLes LIe sume muLrIx us In LIe prevIous exumpIe:
conslruclor(Z 3 __1 Z 3] _Z 4 6]]}.
TIe purumeLers Ior LIe dImensIon ure opLIonuI Iere, sInce LIey ure uIso gIven by
LIe sLrucLure oI LIe IIsL. TIus,
conslruclor(__1 Z 3] _Z 4 6]]}.
uIso reLurns LIe sume muLrIx. An urruy oI domuIn Lype 00MARRAY (SecLIon q.q) Is
uIso vuIId Ior InILIuIIzIng u muLrIx:
Arroy .= orroy(1..Z 1..3 __1 Z 3] _Z 4 6]]}.
Mol .= conslruclor(Arroy}.
You muy deIIne coIumn und row vecLors us m1 und 1 n muLrIces, respecLIveIy.
PIuIn IIsLs cun be used Ior deIInIng coIumn or row vecLors:
coiumn .= conslruclor(3 1 _1 Z 3]}
_
_
_
1
2
3
_
_
_
roW .= conslruclor(1 3 _1 Z 3]}
_
1 2 3
_
I no dImensIons ure specIIIed, u pIuIn IIsL generuLes u coIumn vecLor:
coiumn .= conslruclor(_1 Z 3]}
_
_
_
1
2
3
_
_
_
q-66
Vec|ors ond No|rices
TIe enLrIes oI u muLrIx or u vecLor muy be uccessed In LIe Iorms molrix_ig],
roW_i], or coiumn_g]. SInce vecLors ure specIuI muLrIces, you muy uccess LIe
componenLs oI u vecLor uIso In LIe Iorm roW_1i] or coiumn_g1], respecLIveIy:
A_Z 3] roW_3] roW_1 3]
coiumn_Z] coiumn_Z 1]
6, 3, 3, 2, 2
SubmuLrIces ure generuLed us IoIIows:
Mol_1..Z 1..Z] roW_1..1 1..Z]
coiumn_1..Z 1..1]
_
1 2
2 4
_
,
_
1 2
_
,
_
1
2
_
You muy cIunge u muLrIx enLry by un Indexed ussIgnmenL:
Mol_Z 3] .= Z3. roW_Z] .= 5. coiumn_Z 1] .= 5.
Mol roW coiumn
_
1 2 3
2 4 23
_
,
_
1 5 3
_
,
_
_
_
1
5
3
_
_
_
You cun use Ioops (CIupLer 1) Lo cIunge uII componenLs oI u muLrIx:
m .= Z. n .= 3. Mol .= conslruclor(m n}.
for i from 1 lo m do
for g from 1 lo n do
Mol_i g] .= i*g
endfor
endfor.
You cun generuLe dIugonuI muLrIces by suppIyIng LIe opLIon 0iogonoi. n LIIs
cuse, LIe LIIrd urgumenL Lo LIe consLrucLor muy eILIer be u IIsL oI LIe dIugonuI
eIemenLs or u IuncLIon f sucI LIuL LIe i-LI dIugonuI eIemenL Is f(i):
conslruclor(Z Z _11 1Z] 0iogonoi}
_
11 0
0 12
_
q-6,
4 NuPAD

Cb[ec|s
n LIe nexL exumpIe, we generuLe un IdenLILy muLrIx by suppIyIng 1 us u IuncLIon
q
deIInIng LIe dIugonuI eIemenLs:
conslruclor(Z Z 1 0iogonoi}
_
1 0
0 1
_
AILernuLIveIy, IdenLILy muLrIces cun be generuLed by LIe "idenlily" meLIod oI LIe
consLrucLor:
conslruclor..idenlily(Z}
_
1 0
0 1
_
TIe consLrucLor consIdered so Iur reLurns muLrIces wILI ruLIonuI (I.e., reuI)
number enLrIes. TIus, LIe IoIIowIng uLLempL Lo generuLe u muLrIx wILI compIex
coeIIIcIenLs does noL work:
conslruclor(__1 Z 3] _Z 4 1 + T]]}
Error. unobie lo define molrix over 0om..Rolionoi `
_(0om..Molrix(0om..Rolionoi}}..neW]
You Iuve Lo cIoose u suILubIe coeIIIcIenL rIng Lo generuLe u muLrIx wILI LIe ubove
enLrIes. n LIe IoIIowIng exumpIe, we deIIne u new consLrucLor Ior muLrIces wILI
compIex number enLrIes:
conslruclor .= 0om..Molrix(0om..Compiex}.
conslruclor(__1 Z 3] _Z 4 1 + T]]}
_
1 2 3
2 4 1 + I
_
You muy generuLe muLrIces wIose enLrIes ure urbILrury MuPAD expressIons by
meuns oI LIe IIeId 0om..ExpressionFieid(idiszero} (see SecLIon q.1q). TIIs Is
LIe sLundurd coeIIIcIenL rIng Ior muLrIces. You muy uIwuys use LIIs rIng wIen LIe
coeIIIcIenLs und LIeIr properLIes ure IrreIevunL.
q
CI. puge q-q.
q-6S
Vec|ors ond No|rices
0om..Molrix(} wILI no urgumenL Is u consLrucLor Ior sucI muLrIces. As u
sIorLIund noLuLIon, LIIs muLrIx rIng Is uLLucIed Lo LIe IdenLIIIer molrix:
molrix
Dom::MuLrIx()
molrix(__1 x + y 1/x^Z] _sin(x} 0 cos(x}]
_x*PT 1 + T -x*PT]]}
_
_
_
1 x +y
1
x
2
sIn(x) 0 cos(x)
x 1 + I x
_
_
_
I you use 0om..ExpressionFieid(normoiiszero} us LIe coeIIIcIenL rIng, LIen
uII muLrIx enLrIes ure sImpIIIIed vIu LIe IuncLIon normoi, us descrIbed In
SecLIon q.1q. ArILImeLIcuI operuLIons wILI sucI muLrIces ure compuruLIveIy sIow,
sInce u cuII Lo normoi muy be quILe LIme consumIng. However, LIe resuILs ure In
generuI sImpIer LIun LIe (equIvuIenL) resuILs oI compuLuLIons wILI LIe sLundurd
coeIIIcIenL rIng 0om..ExpressionFieid(idiszero} used by 0om..Molrix(}.
TIe consLrucLor 0om..SquoreMolrix(nR} corresponds Lo LIe rIng oI
n-dImensIonuI squure muLrIces wILI coeIIIcIenL rIng R. I LIe urgumenL R Is
mIssIng, LIen MuPAD uuLomuLIcuIIy uses LIe coeIIIcIenL rIng oI uII MuPAD
expressIons. TIe IoIIowIng sLuLemenL yIeIds LIe consLrucLor Ior 2 2 muLrIces,
wIose enLrIes muy be urbILrury MuPAD expressIons:
conslruclor .= 0om..SquoreMolrix(Z}
Dom::SquureMuLrIx(2)
conslruclor(__0 y] _x^Z 1]]}
_
0 y
x
2
1
_
q-6q
4 NuPAD

Cb[ec|s
Compoting with Mutrices
You cun use LIe sLundurd urILImeLIcuI operuLors Ior doIng busIc urILImeLIc wILI
muLrIces:
A .= molrix(__1 Z] _3 4]]}.
B .= molrix(__o b] _c d]]}.
A + B A*B
A*B - B*A A^Z + B
_
a + 1 b + 2
c + 3 d + 4
_
,
_
a + 2 c b + 2 d
3 a + 4 c 3 b + 4 d
_
_
2 c 3 b 2 d 3 b 2 a
3 a + 3 c 3 d 3 b 2 c
_
,
_
a + 7 b + 10
c + 15 d + 22
_
MuILIpIIcuLIon oI u muLrIx und u number works componenLwIse (scuIur
muILIpIIcuLIon):
Z*B
_
2 a 2 b
2 c 2 d
_
TIe Inverse oI u muLrIx Is represenLed by 1/A or A^(-1}:
C .= A^(-1}
_
2 1
3
2

1
2
_
A sImpIe LesL sIows LIuL LIe compuLed Inverse Is correcL:
A*C C*A
_
1 0
0 1
_
,
_
1 0
0 1
_
q-,o
Vec|ors ond No|rices
An InversIon reLurns FATL wIen MuPAD Is unubIe Lo compuLe LIe resuIL. TIe
IoIIowIng muLrIx Is noL InverLIbIe:
C .= molrix(__1 1] _1 1]]}.
C^(-1}
A
TIe concuLenuLIon operuLor ., wIIcI combInes IIsLs (SecLIon q.6) or sLrIngs
(SecLIon q.11), Is overIouded Ior muLrIces. You cun use IL Lo combIne muLrIces
wILI LIe sume number oI rows:
A B A.B
_
1 2
3 4
_
,
_
a b
c d
_
,
_
1 2 a b
3 4 c d
_
BesIdes LIe urILImeLIc operuLors, oLIer sysLem IuncLIons ure uppIIcubIe Lo
muLrIces. Here Is u IIsL oI exumpIes:
congugole(A} repIuces uII componenLs by LIeIr compIex conjuguLes,
diff(Ax} dIIIerenLIuLes componenLwIse wILI respecL Lo x,
exp(A} compuLes e
A
=

i=0
1
i!
A
i
,
expond(A} uppIIes expond Lo uII componenLs oI A,
expr(A} converLs A Lo un urruy oI domuIn Lype 00MARRAY,
fiool(A} uppIIes fiool Lo uII componenLs oI A,
hos(Aexpression} cIecks wIeLIer un expressIon Is conLuIned In uL IeusL
one enLry oI A,
inl(Ax} InLegruLes componenLwIse wILI respecL Lo x,
iszero(A} cIecks wIeLIer uII componenLs oI A vunIsI,
mop(Afunclion} uppIIes LIe IuncLIon Lo uII componenLs,
q-,1
4 NuPAD

Cb[ec|s
norm(A} (IdenLIcuI wILI norm(ATnfinily}) compuLes LIe InIInILy norm,
1o
A1equolion uppIIes 1equolion Lo uII enLrIes oI A,
subs(Aequolion} uppIIes subs(equolion} Lo uII enLrIes oI A,
C.=zip(ABf} reLurns LIe muLrIx deIIned by C
ij
= f(A
ij
, B
ij
).
TIe IIneur uIgebru IIbrury iinoig und LIe numerIcs IIbrury numeric (SecLIon q.1)
comprIse muny oLIer IuncLIons Ior IundIIng muLrIces.
Ixercise q.,: GeneruLe LIe 15 15 HIIberL muLrIx H = (H
ij
) wILI
H
ij
= 1/(i +j 1). GeneruLe LIe vecLor

b = He, wIere e = (1, . . . , 1)


t
. CompuLe
LIe exucL soIuLIon vecLor x oI LIe sysLem oI equuLIons H x =

b (oI course, LIIs


sIouId yIeId x = e). ConverL uII enLrIes oI H Lo IIouLIng-poInL vuIues und soIve LIe
sysLem oI equuLIons uguIn. Compure LIe resuIL Lo LIe exucL soIuLIon. You wIII noLe
u drumuLIc dIIIerence, wIIcI Is cuused by numerIcuI roundIng errors. urger
HIIberL muLrIces cunnoL be InverLed wILI LIe sLundurd precIsIon oI common
numerIcuI soILwure!
Speciul Methods Ior Mutrices
A consLrucLor LIuL Ius been generuLed by meuns oI eILIer 0om..Molrix(} or
0om..SquoreMolrix(} conLuIns muny specIuI IuncLIons Ior LIe correspondIng
duLu Lype. I M.=0om..Molrix(ring} Is u consLrucLor und A.=M(} Is u muLrIx
generuLed wILI LIIs consLrucLor, us descrIbed In SecLIon q.1, LIen, umong muy
oLIers, LIe IoIIowIng meLIods ure uvuIIubIe:
M..coi(Ai} reLurns LIe i-LI coIumn oI A,
M..deiCoi(Ai} removes LIe i-LI coIumn Irom A,
M..deiRoW(Ai} removes LIe i-LI row Irom A,
M..moldim(A} reLurns LIe dImensIon _mn] oI LIe mn muLrIx A,
1o
norm(A1} reLurns LIe one-norm, norm(AFrobenius} yIeIds LIe robenIus norm
_

i,j
|A
ij
|
2
_
1/2
.
q-,
Vec|ors ond No|rices
M..rondom(} reLurns u muLrIx wILI rundom enLrIes,
M..roW(Ai} reLurns LIe i-LI row oI A,
M..sWopCoi(Aig} excIunges coIumns i und j,
M..sWopRoW(Aig} excIunges rows i und j,
M..lr(A} reLurns LIe Lruce

i
A
ii
oI A,
M..lronspose(A} reLurns LIe Lrunspose (A
ji
) oI A = (A
ij
).
M .= 0om..Molrix(}. A .= M(__x 1] _Z y]]}
_
x 1
2 y
_
M..coi(A 1} M..deiCoi(A 1} M..moldim(A}
_
x
2
_
,
_
1
y
_
, [2, 2]
M..sWopCoi(A 1 Z} M..lr(A} M..lronspose(A}
_
1 x
y 2
_
, x +y,
_
x 2
1 y
_
SInce LIe domuIn Is uLLucIed Lo LIe objecL A us A..dom, one cun uIso cuII LIe
domuIn meLIods vIu A..dom..melhod. or exumpIe:
A..dom..lr(A}
x +y
TIe documenLuLIon oI 0om..Molrix conLuIns u survey oI LIese meLIods.
q-,
4 NuPAD

Cb[ec|s
The Libruries iinoig und numeric
BesIdes sysLem IuncLIons operuLIng on muLrIces, LIe IIbrury
11
iinoig conLuIns u
vurIeLy oI oLIer IIneur uIgebru IuncLIons:
info(iinoig}
Librory iinoig. lhe iineor oigebro pockoge
-- Tnlerfoce.
iinoig..oddCoi iinoig..oddRoW
iinoig..odgoinl iinoig..ongie
iinoig..bosis iinoig..chormol
iinoig..chorpoiy iinoig..coi
iinoig..componion iinoig..concolMolrix
iinoig..crossProducl iinoig..curi
iinoig..deiCoi iinoig..deiRoW
iinoig..del iinoig..divergence
iinoig..eigenvoiues iinoig..eigenveclors
iinoig..exprZMolrix iinoig..foclorChoiesky
iinoig..foclorLu iinoig..foclorR
iinoig..frobeniusForm iinoig..goussEiim
iinoig..goussJordon iinoig..grod
iinoig..hermileForm iinoig..hessenberg
iinoig..hession iinoig..hiiberl
iinoig..inlBosis iinoig..inverseLu
iinoig..invhiiberl iinoig..invposcoi
iinoig..invvondermonde iinoig..is|ermileon
iinoig..isPos0ef iinoig..isunilory
iinoig..gocobion iinoig..gordonForm
iinoig..kroneckerProducl iinoig..iopiocion
iinoig..moldim iinoig..moliinsoive
iinoig..moliinsoiveLu iinoig..minpoiy
iinoig..muilCoi iinoig..muilRoW
iinoig..ncois iinoig..nonZeros
iinoig..normoiize iinoig..nroWs
iinoig..nuiispoce iinoig..ogCoordTob
iinoig..orlhog iinoig..poscoi
iinoig..permonenl iinoig..polenlioi
iinoig..pseudoTnverse iinoig..rondomMolrix
iinoig..ronk iinoig..roW
11
We reIer Lo CIupLer Ior u descrIpLIon oI generuI IIbrury orgunIzuLIon, exporLIng, eLc.
q-,q
Vec|ors ond No|rices
iinoig..scoiorProducl iinoig..selCoi
iinoig..selRoW iinoig..smilhForm
iinoig..slockMolrix iinoig..submolrix
iinoig..subslilule iinoig..sumBosis
iinoig..sWopCoi iinoig..sWopRoW
iinoig..syivesler iinoig..loepiilz
iinoig..loepiilzSoive iinoig..lr
iinoig..lronspose iinoig..vondermonde
iinoig..vondermondeSoive iinoig..vecdim
iinoig..veclor0f iinoig..veclorPolenlioi
iinoig..Wiedemonn
Some oI LIese IuncLIons, sucI us iinoig..coi or iinoig..deiCoi, sImpIy cuII LIe
InLernuI meLIods Ior muLrIces LIuL we Iuve descrIbed In SecLIon q.1, und Ience
do noL udd new IuncLIonuIILy. However, iinoig uIso conLuIns muny uddILIonuI
uIgorILIms. TIe commund ?iinoig yIeIds u sIorL descrIpLIon oI uII IuncLIons. You
cun IInd u deLuIIed descrIpLIon oI u IuncLIon on LIe correspondIng IeIp puge.
You muy use LIe IuII nume iibrory..funclion Lo cuII u IuncLIon:
A .= molrix(__o b] _c d]]}. iinoig..del(A}
a d b c
TIe cIurucLerIsLIc poIynomIuI deL(xI
n
A) oI LIIs muLrIx Is
iinoig..chorpoiy(A x}
x
2
+ (a d) x +a d b c
TIe eIgenvuIues ure
iinoig..eigenvoiues(A}
_
a
2
+
d
2

a
2
2 a d +d
2
+ 4 b c
2
,
a
2
+
d
2
+

a
2
2 a d +d
2
+ 4 b c
2
_
q-,g
4 NuPAD

Cb[ec|s
TIe numerIcs IIbrury numeric (see ?numeric) conLuIns muny IuncLIons Ior
numerIcuI compuLuLIons wILI muLrIces:

numeric..del : deLermInunL
numeric..expMolrix : exp(MuLrIx)
numeric..foclorChoiesky : CIoIesky IucLorIzuLIon
numeric..foclorLu : LU IucLorIzuLIon
numeric..foclorR : QR IucLorIzuLIon
numeric..fMolrix : IuncLIonuI cuIcuIus
numeric..inverse : InversIon
numeric..eigenvoiues : eIgenvuIues
numeric..eigenveclors : eIgenvuIues und -vecLors
numeric..singuiorvoiues : sInguIur vuIues
numeric..singuiorveclors : sInguIur vuIues und vecLors
PurLIuIIy, LIese rouLInes work Ior muLrIces wILI symboIIc enLrIes oI Lype
0om..ExpressionFieid und LIen ure more eIIIcIenL Ior Iurge muLrIces LIun LIe
iinoig IuncLIons. However, LIe IuLLer cun IundIe urbILrury coeIIIcIenL rIngs.
Ixercise q.S: Ind LIe vuIues oI a, b, c Ior wIIcI LIe muLrIx
_
_
1 a b
1 1 c
1 1 1
_
_
Is noL
InverLIbIe.
Ixercise q.q: ConsIder LIe IoIIowIng muLrIces:
A =
_
_
1 3 0
1 2 7
0 8 1
_
_
, B =
_
_
7 1
2 3
0 1
_
_
.
eL B
T
be LIe Lrunspose oI B. CompuLe LIe Inverse oI 2 A+BB
T
, boLI over LIe
ruLIonuI numbers und over LIe resIdue cIuss rIng moduIo 7.
q-,6
Vec|ors ond No|rices
Ixercise q.qo: GeneruLe LIe 3 3 muLrIx
A
ij
=
_
0 Ior i = j ,
1 Ior i = j .
CompuLe ILs deLermInunL, ILs cIurucLerIsLIc poIynomIuI, und ILs eIgenvuIues. or
eucI eIgenvuIue, compuLe u busIs oI LIe correspondIng eIgenspuce.
Spurse Mutrices
TIe InLernuI sLoruge oI muLrIces Is opLImIzed Ior spurse duLu, I.e., Ior muLrIces
consIsLIng IurgeIy oI zeroes, sInce sucI muLrIces uppeur oILen In prucLIce. Here ure
some remurks concernIng eIIIcIency wIen your muLrIces ure Iurge und spurse:
Use LIe sLundurd coeIIIcIenL rIng 0om..ExpressionFieid(} oI urbILrury
MuPAD

expressIons wIenever possIbIe. As dIscussed In LIe prevIous


secLIons, LIe consLrucLor 0om..Molrix(} creuLes muLrIces oI LIIs Lype. or
convenIence, LIIs consLrucLor Is uIso uvuIIubIe us LIe IuncLIon molrix.
ndexed reudIng und wrILIng Lo Iurge muLrIces Is somewIuL expensIve. I
possIbIe, one sIouId uvoId creuLIng Iurge empLy muLrIces oI LIe desIred
dImensIon by molrix(m n} und IIIIIng In LIe non-zero enLrIes by Indexed
ussIgnmenLs. One sIouId seL LIe enLrIes dIrecLIy wIen creuLIng LIe muLrIx.
IsLs oI equuLIons cun be used Lo specIIy LIe enLrIes wIen creuLIng u muLrIx. TIe
IoIIowIng muLrIx A oI dImensIon 1000 1000 consIsLs oI u dIugonuI bund und Lwo
uddILIonuI enLrIes In LIe upper rIgIL und LIe Iower IeIL corner. We dIspIuy some
enLrIes oI ILs 10-LI power:
n .= 1000.
A .= molrix(n n _(i i} = i S i = 1..n
(n 1} = 1 (1 n} = 1]}.
B .= A^10.
B_1 1] B_1 n]
1002010022050086122130089, 1001009015040066101119105055
q-,,
4 NuPAD

Cb[ec|s
n LIe IoIIowIng exumpIe, we generuLe u 100 100 LrI-dIugonuI ToepIILz muLrIx A
und soIve LIe equuLIon Ax = b, wIere b Is LIe coIumn vecLor (1, . . . , 1):
A .= molrix(100 100 _-1 Z -1] Bonded}.
b .= molrix(100 1 _1 S 100]}.
x .= (1/A}*b
_
_
_
_
_
_
50
99
. . .
50
_
_
_
_
_
_
Here we Iuve uppIIed LIe Inverse 1/A oI A Lo LIe rIgIL-Iund sIde oI LIe equuLIon.
NoLe, Iowever, LIuL InverLIng u spurse muLrIx Is noL u good Ideu becuuse LIe
Inverse oI u spurse muLrIx Is, In generuI, noL spurse. L Is mucI more eIIIcIenL Lo
use spurse muLrIx IucLorIzuLIon Lo compuLe LIe soIuLIon oI u spurse sysLem oI
IIneur equuLIons. We use LIe IIneur soIver numeric..moliinsoive wILI LIe opLIon
Symboiic Lo compuLe LIe soIuLIon oI u spurse sysLem represenLIng 1ooo equuLIons
Ior 1ooo unknowns. TIe numeric rouLIne empIoys spursILy In un opLImuI wuy:
A .= molrix(1000 1000 _-1 Z -1] Bonded}.
b .= molrix(1000 1 _1 S 1000]}.
_x kernei] .= numeric..moliinsoive(A b Symboiic}.
We dIspIuy onIy u Iew componenLs oI LIe soIuLIon vecLor:
x_1] x_Z] x_3] x_4] x_5] x_999] x_1000]
500, 999, 1497, 1994, 2490, 999, 500
An Applicution
We wunL Lo compuLe LIe symboIIc soIuLIon a(t), b(t) oI LIe sysLem oI second order
dIIIerenLIuI equuLIons
d
2
dt
2
a(t) = 2 c
d
dt
b(t) ,
d
2
dt
2
b(t) = 2 c
d
dt
a(t) + 3 c
2
b(t)
wILI un urbILrury consLunL c. WrILIng a

(t) =
d
dt
a(t), b

(t) =
d
dt
b(t), LIese equuLIons
muy be equIvuIenLIy wrILLen us u sysLem oI IIrsL order dIIIerenLIuI equuLIons In LIe
q-,S
Vec|ors ond No|rices
vurIubIes x(t) = (a(t), a

(t), b(t), b

(t)):
d
dt
x(t) = Ax(t), A =
_
_
_
_
0 1 0 0
0 0 0 2 c
0 0 0 1
0 2 c 3 c
2
0
_
_
_
_
.
TIe soIuLIon oI LIIs sysLem Is gIven by uppIyIng LIe exponenLIuI muLrIx e
tA
Lo LIe
InILIuI condILIon x(0):
x(t) = e
tA
x(0) .
deiele c l.
A .= molrix(__0 1 0 0 ]
_0 0 0 Z*c]
_0 0 0 1 ]
_0 -Z*c 3*c^Z 0 ]]}.
We use LIe IuncLIon exp Lo compuLe B = e
tA
:
B .= exp(l*A}
_
_
_
_
_
_
1 3 t +
e
c t I
2 I
c

e
c t I
2 I
c
e
c t I
3 I + 6 c t e
c t I
3 I
2
c

e
c t I
c

e
c t I
c
0 2 e
c t I
+ 2 e
c t I
3 6 c 3 c e
c t I
3 c e
c t I
e
c t I
I e
c t I
I
0
e
c t I
c
+
e
c t I
c

2
c
4
3 e
c t I
2

3 e
c t I
2
e
c t I
I
c 2

e
c t I
I
c 2
0 e
c t I
I + e
c t I
I
c e
c t I
3 I
2

c e
c t I
3 I
2
e
c t I
2
+
e
c t I
2
_
_
_
_
_
_
To sImpIIIy LIIs muLrIx, we use LIe IuncLIon Simpiify, wIIcI Ior muLrIces sImpIy
mups ILseII Lo LIe enLrIes:
B .= Simpiify(B}
_
_
_
_
_
_
1
4 sIn(c t)
c
3 t 6 c t 6 sIn(c t)
2 (cos(c t)1)
c
0 4 cos(c t) 3 6 c (cos(c t) 1) 2 sIn(c t)
0
2 (cos(c t)1)
c
4 3 cos(c t)
sIn(c t)
c
0 2 sIn(c t) 3 c sIn(c t) cos(c t)
_
_
_
_
_
_
q-,q
4 NuPAD

Cb[ec|s
We ussIgn u symboIIc InILIuI condILIon Lo LIe vecLor x
0
. TIe IoIIowIng cuII creuLes u
4 1 muLrIx Lo be InLerpreLed us u coIumn vecLor:
x0 .= molrix(_o0 o0 b0 b0]}
_
_
_
_
_
_
a
0
a

0
b
0
b

0
_
_
_
_
_
_
TIus, LIe desIred symboIIc soIuLIon oI LIe sysLem oI dIIIerenLIuI equuLIons Is
x .= l --> B*x0.
TIe soIuLIon IuncLIons a(t) und b(t) wILI LIe symboIIc InILIuI condILIons a(0) = a
0
,
a

(0) = a

0
, b(0) = b
0
, b

(0) = b

0
ure:
o .= l --> expond(x(l}_1]}. o(l}
a
0
6 b
0
sIn(c t) 3 t a

0
+
2 b

0
c

2 cos(c t) b

0
c
+
4 a

0
sIn(c t)
c
+ 6 b
0
c t
b .= l --> expond(x(l}_3]}. b(l}
4 b
0
3 b
0
cos(c t)
2 a

0
c
+
2 cos(c t) a

0
c
+
b

0
sIn(c t)
c
InuIIy, we cIeck LIuL LIe ubove expressIons reuIIy soIve LIe sysLem oI dIIIerenLIuI
equuLIons:
expond(diff(o(l}ll} - Z*c*diff(b(l}l}}
expond(diff(b(l}ll} + Z*c*diff(o(l}l} - 3*c^Z*b(l}}
0, 0
q-So
Polynomiols
Felyaemiuls
CompuLuLIon wILI poIynomIuIs Is un ImporLunL Lusk Ior u compuLer uIgebru
sysLem. OI course, you muy reuIIze u poIynomIuI In MuPAD

us un expressIon In
LIe sense oI SecLIon q.q und use LIe sLundurd urILImeLIc:
poiynomioiExpression .= 1 + x + x^Z.
expond(poiynomioiExpression^Z}
x
4
+ 2 x
3
+ 3 x
2
+ 2 x + 1
However, LIere exIsLs u specIuI duLu Lype 00MP0LY LogeLIer wILI some kerneI und
IIbrury IuncLIons, wIIcI sImpIIIIes sucI compuLuLIons und mukes LIem more
eIIIcIenL.
eIinition oI Polynomiuls
TIe sysLem IuncLIon poiy generuLes poIynomIuIs:
poiy(1 + Z*x + 3*x^Z}
poIy
_
3 x
2
+ 2 x + 1, [x]
_
Here we Iuve suppIIed LIe expressIon 1 + 2 x + 3 x
2
(oI domuIn Lype 00MEXPR) Lo
poiy, wIIcI converLs LIIs expressIon Lo u new objecL oI domuIn Lype 00MP0LY.
TIe IndeLermInuLe _x] Is u IIxed purL oI LIIs duLu Lype. TIIs Is reIevunL Ior
dIsLInguIsIIng beLween IndeLermInuLes und (symboIIc) coeIIIcIenLs or purumeLers.
or exumpIe, II you wunL Lo regurd LIe expressIon a
0
+a
1
x +a
2
x
2
us u
poIynomIuI In x wILI coeIIIcIenLs a
0
, a
1
, a
2
, LIen LIe ubove Iorm oI LIe cuII Lo poiy
does noL yIeId LIe desIred resuIL:
poiy(o0 + o1*x + oZ*x^Z}
poIy
_
a
0
+ a
1
x + a
2
x
2
, [a
0
, a
1
, a
2
, x]
_
TIIs does noL represenL u poIynomIuI In x buL u muILIvurIuLe poIynomIuI In Iour
IndeLermInuLes x, a
0
, a
1
, a
2
. You cun specIIy LIe IndeLermInuLes oI u poIynomIuI In
Iorm oI u IIsL us urgumenL Lo poiy. TIe sysLem LIen regurds uII oLIer symboIIc
IdenLIIIers us symboIIc coeIIIcIenLs:
q-S1
4 NuPAD

Cb[ec|s
poiy(o0 + o1*x + oZ*x^Z _x]}
poIy
_
a
2
x
2
+a
1
x +a
0
, [x]
_
I you do noL specIIy u IIsL oI IndeLermInuLes, LIen poiy cuIIs LIe IuncLIon indels
Lo deLermIne uII symboIIc IdenLIIIers In LIe expressIon und InLerpreLs LIem us
IndeLermInuLes oI LIe poIynomIuI:
indels(o0 + o1*x + oZ*x^Z PoiyExpr}
{a
0
, a
1
, a
2
, x}
TIe dIsLIncLIon beLween IndeLermInuLes und coeIIIcIenLs Is reIevunL Ior LIe
represenLuLIon oI LIe poIynomIuI:
expression .= 1 + x + x^Z + o*x + PT*x^Z - b
x b +a x + x
2
+x
2
+ 1
poiy(expression _o x]}
poIy
_
a x + ( + 1) x
2
+ x + (1 b) , [a, x]
_
poiy(expression _x]}
poIy
_
( + 1) x
2
+ (a + 1) x + (1 b) , [x]
_
You cun see LIuL MuPAD coIIecLs LIe coeIIIcIenLs oI equuI powers oI LIe
IndeLermInuLe. TIe Lerms ure sorLed uccordIng Lo IuIIIng exponenLs.
nsLeud oI usIng un expressIon, you muy uIso generuLe u poIynomIuI by specIIyIng
u IIsL oI LIe non-zero coeIIIcIenLs LogeLIer wILI LIe respecLIve exponenLs. TIe
commund poiy(iisl_x]} generuLes LIe poIynomIuI

k
i=0
a
i
x
n
i
Irom LIe IIsL
[[a
0
, n
0
], [a
1
, n
1
], . . . , [a
k
, n
k
]]:
iisl .= __1 0] _o 3] _b 5]]. poiy(iisl _x]}
poIy
_
b x
5
+a x
3
+ 1, [x]
_
I you wunL Lo consLrucL u muILIvurIuLe poIynomIuI In LIIs wuy, specIIy IIsLs oI
exponenLs Ior uII vurIubIes:
poiy(__3 _Z 1]] _Z _3 4]]] _x y]}
poIy
_
2 x
3
y
4
+ 3 x
2
y, [x, y]
_
q-S
Polynomiols
ConverseIy, LIe IuncLIon poiyZiisl converLs u poIynomIuI Lo u IIsL oI coeIIIcIenLs
und exponenLs:
poiyZiisl(poiy(b*x^5 + o*x^3 + 1 _x]} }
[[b, 5] , [a, 3] , [1, 0]]
or more ubsLrucL compuLuLIons, you muy wunL Lo resLrIcL LIe coeIIIcIenLs oI u
poIynomIuI Lo u cerLuIn seL (muLIemuLIcuIIy: u rIng) wIIcI Is represenLed by u
specIuI duLu sLrucLure. We Iuve uIreudy seen LypIcuI exumpIes oI rIngs und LIeIr
correspondIng MuPAD domuIns In SecLIon q.1q: LIe InLegers 0om..Tnleger, LIe
ruLIonuI numbers 0om..Rolionoi, or LIe resIdue cIuss rIng 0om..TnlegerMod(n}
oI InLegers moduIo n. You muy specIIy LIe coeIIIcIenL rIng us urgumenL Lo poiy:
poiy(x + 1 _x] 0om..Tnleger}
poIy (x + 1, [x] , Z)
poiy(Z*x - 1/Z _x] 0om..Rolionoi}
poIy
_
2 x
_
1
2
_
, [x] , Q
_
poiy(4*x + 11 _x] 0om..TnlegerMod(3}}
poIy (x + 2, [x] , Z
3
)
NoLe LIuL In LIe IusL exumpIe, LIe sysLem Ius uuLomuLIcuIIy sImpIIIIed LIe
coeIIIcIenLs uccordIng Lo LIe ruIes Ior compuLIng wILI InLegers moduIo 3:
1z
4 mod 3 11 mod 3
1, 2
n LIe IoIIowIng exumpIe, poiy converLs LIe coeIIIcIenLs Lo IIouLIng-poInL
numbers, us specIIIed by LIe LIIrd urgumenL:
poiy(PT*x - 1/Z _x] 0om..Fiool}
poIy (3.141592654 x 0.5, [x] , Dom::IouL)
1z
or poIynomIuIs, you muy uIso use TnlMod(3} InsLeud oI 0om..TnlegerMod(3}, In LIe Iorm
poiy(4*x+11_x]TnlMod(3}}. TIen LIe InLegers moduIo 3 ure represenLed by 1, 0, 1 und noL, us
Ior 0om..TnlegerMod(3}, by 0, 1, 2. PoIynomIuI urILImeLIc Is mucI IusLer wIen you use TnlMod(3}.
q-S
4 NuPAD

Cb[ec|s
I no coeIIIcIenL rIng Is specIIIed, LIen MuPAD by deIuuIL uses LIe rIng Expr wIIcI
symboIIzes urbILrury MuPAD expressIons. n LIIs cuse, you muy use symboIIc
IdenLIIIers us coeIIIcIenLs:
poiynomioi .= poiy(o + x + b*y _x y]}
op(poiynomioi}
poIy (x +b y +a, [x, y])
a +x +b y, [x, y] , Expr
We summurIze LIuL u MuPAD poIynomIuI comprIses LIree purLs:
1. u poIynomIuI expressIon oI LIe Iorm

a
i
1
i
2
...
x
i
1
1
x
i
2
2
. . .,
z. u IIsL oI IndeLermInuLes [x
1
, x
2
, . . .],
. LIe coeIIIcIenL rIng.
TIese ure LIe LIree operunds oI u MuPAD poIynomIuI p, wIIcI cun be uccessed vIu
op(p1}, op(pZ}, und op(p3}, respecLIveIy. TIus, you muy converL u
poIynomIuI Lo u muLIemuLIcuIIy equIvuIenL expressIon
1
oI domuIn Lype 00MEXPR
by
expression .= op(poiynomioi 1}.
However, you sIouId preIerubIy use LIe sysLem IuncLIon expr, wIIcI cun converL
vurIous domuIn Lypes sucI us poIynomIuIs Lo expressIons:
poiynomioi .= poiy(x^3 + 5*x + 3}
poIy
_
x
3
+ 5 x + 3, [x]
_
op(poiynomioi 1} = expr(poiynomioi}
x
3
+ 5 x + 3 = x
3
+ 5 x + 3
1
I LIe poIynomIuI Is deIIned over u rIng oLIer LIun 0om..ExpressionFieid or Expr, LIe resuIL muy
noL be equIvuIenL.
q-Sq
Polynomiols
Compoting with Polynomiuls
TIe IuncLIon degree deLermInes LIe degree oI u poIynomIuI:
p .= poiy(1 + x + o*x^Z*y _x y]}.
degree(p x} degree(p y}
2, 1
I you do noL specIIy LIe nume oI un IndeLermInuLe us second urgumenL, LIen
degree reLurns LIe LoLuI degree:
degree(p} degree(poiy(x^Z7 + x + 1}}
3, 27
TIe IuncLIon coeff exLrucLs coeIIIcIenLs Irom u poIynomIuI:
p .= poiy(1 + o*x + 7*x^7 _x]}.
coeff(p 1} coeff(p Z} coeff(p }
a, 0, 0
or muILIvurIuLe poIynomIuIs, LIe coeIIIcIenL oI u power oI one purLIcuIur
IndeLermInuLe Is uguIn u poIynomIuI In LIe remuInIng IndeLermInuLes:
p .= poiy(1 + x + o*x^Z*y _x y]}.
coeff(p y 0} coeff(p y 1}
poIy (x + 1, [x]) , poIy
_
a x
2
, [x]
_
TIe sLundurd operuLors +, -, * und ^ work Ior poIynomIuI urILImeLIc us weII:
p .= poiy(1 + o*x^Z _x]}. q .= poiy(b + c*x _x]}.
p + q p - q
p*q p^Z
poIy
_
a x
2
+c x + (b + 1) , [x]
_
, poIy
_
a x
2
+ (c) x + (1 b) , [x]
_
poIy
_
(a c) x
3
+ (a b) x
2
+c x +b, [x]
_
, poIy
_
a
2
x
4
+ (2 a) x
2
+ 1, [x]
_
q-Sg
4 NuPAD

Cb[ec|s
TIe IuncLIon divide perIorms u dIvIsIon wILI remuInder:
p .= poiy(x^3 + 1}. q .= poiy(x^Z - 1}. divide(p q}
poIy (x, [x]) , poIy (x + 1, [x])
TIe resuIL Is u sequence wILI Lwo operunds: LIe quoLIenL und LIe remuInder oI LIe
dIvIsIon:
_quolienl remoinder] .= _divide(p q}].
We cIeck:
p = quolienl*q + remoinder
poIy
_
x
3
+ 1, [x]
_
= poIy
_
x
3
+ 1, [x]
_
TIe poIynomIuI denoLed by remoinder Is oI Iower degree LIun q, wIIcI mukes LIe
decomposILIon p=quolienl*q+remoinder unIque. DIvIdIng Lwo poIynomIuIs by
meuns oI LIe usuuI dIvIsIon operuLor / Is onIy uIIowed In LIe specIuI cuse wIen LIe
remuInder LIuL divide wouId reLurn vunIsIes:
p .= poiy(x^Z - 1}. q .= poiy(x - 1}. p/q
poIy (x + 1, [x])
p .= poiy(x^Z + 1}. q .= poiy(x - 1}. p/q
A
NoLe LIuL LIe urILImeLIc operuLors process onIy poIynomIuIs oI exucLIy IdenLIcuI
Lypes:
poiy(x + y _x y]} + poiy(x^Z _x y]}
poiy(x} + poiy(x _x] Expr}
poIy
_
x
2
+ x + y, [x, y]
_
, poIy (2 x, [x])
BoLI LIe IIsL oI IndeLermInuLes und LIe coeIIIcIenL rIng musL coIncIde, oLIerwIse
LIe sysLem reLurns LIe InpuL us u symboIIc expressIon:
poiy(x + y _x y]} + poiy(x^Z _x]}
poIy (x + y, [x, y]) +poIy
_
x
2
, [x]
_
q-S6
Polynomiols
poiy(x 0om..Tnleger} + poiy(x}
poIy (x, [x] , Z) +poIy (x, [x])
TIe poIynomIuI urILImeLIc perIorms coeIIIcIenL uddILIons und muILIpIIcuLIons
uccordIng Lo LIe ruIes oI LIe coeIIIcIenL rIng:
p .= poiy(4*x + 11 _x] 0om..TnlegerMod(3}}.
p p + p p*p
poIy (x + 2, [x] , Z
3
)
poIy (2 x + 1, [x] , Z
3
)
poIy
_
x
2
+ x + 1, [x] , Z
3
_
TIe sLundurd operuLor * does noL work ImmedIuLeIy Ior muILIpIyIng u poIynomIuI
by u scuIur; you need Lo converL LIe scuIur IucLor Lo u poIynomIuI IIrsL:
p .= poiy(x^Z + y}.
scoior*p poiy(scoior op(p Z..3}}*p
scuIur poIy
_
x
2
+ y, [x, y]
_
poIy
_
scuIur x
2
+ scuIur y, [x, y]
_
Here we Iuve ensured LIuL LIe poIynomIuI generuLed Irom LIe scuIur IucLor Is oI
LIe sume Lype us p by pussIng op(pZ..3} (=_xy]Expr) us IurLIer urgumenLs Lo
poiy. AILernuLIveIy, LIe IuncLIon muilcoeffs muILIpIIes uII coeIIIcIenLs oI u
poIynomIuI by u scuIur IucLor:
muilcoeffs(p scoior}
poIy
_
scuIur x
2
+ scuIur y, [x, y]
_
TIe IuncLIon mopcoeffs uppIIes un urbILrury IuncLIon Lo uII coeIIIcIenLs oI u
poIynomIuI:
p .= poiy(Z*x^Z + 3*y}. mopcoeffs(p f}
poIy
_
f(2) x
2
+f(3) y, [x, y]
_
q-S,
4 NuPAD

Cb[ec|s
TIIs yIeIds unoLIer wuy oI muILIpIIcuLIon by u scuIur:
mopcoeffs(p muil scoior}
poIy
_
(2 scuIur) x
2
+ (3 scuIur) y, [x, y]
_
AnoLIer ImporLunL operuLIon Is LIe evuIuuLIon oI u poIynomIuI uL u poInL
(compuLIng LIe Imuge vuIue). TIe IuncLIon evoip ucIIeves LIIs:
p .= poiy(x^Z + 1 _x]}.
evoip(p x = Z} evoip(p x = x + y}
5, (x +y)
2
+ 1
TIIs compuLuLIon Is uIso vuIId Ior muILIvurIuLe poIynomIuIs und yIeIds u
poIynomIuI In LIe remuInIng IndeLermInuLes or, Ior u unIvurIuLe poIynomIuI, un
eIemenL oI LIe coeIIIcIenL rIng:
p .= poiy(x^Z + y}.
q .= evoip(p x = 0} evoip(q y = Z}
poIy (y, [y])
2
You cun uIso use LIe more generuI evuIuuLIon operuLor 1 Ior LIe sume eIIecL:
p 1 x = 0 p 1 _x = 0 y = Z]
poIy (y, [y])
2
You muy uIso regurd u poIynomIuI us u IuncLIon oI LIe IndeLermInuLes und cuII LIIs
IuncLIon wILI urgumenLs:
p(Z z}
z + 4
A vurIeLy oI MuPAD IuncLIons uccepL poIynomIuIs us InpuL. An ImporLunL
operuLIon Is IucLorIzuLIon, wIIcI Is perIormed uccordIng Lo LIe ruIes oI LIe
coeIIIcIenL rIng. You cun do IucLorIzuLIon wILI LIe MuPAD IuncLIon foclor:
q-SS
Polynomiols
foclor(poiy(x^3 - 1}}
poIy (x 1, [x]) poIy
_
x
2
+ x + 1, [x]
_
foclor(poiy(x^Z + 1 0om..TnlegerMod(Z}}}
poIy (x + 1, [x] , Z
2
)
2
TIe IuncLIon 0 dIIIerenLIuLes poIynomIuIs:
0(poiy(x^7 + x + 1}}
poIy
_
7 x
6
+ 1, [x]
_
EquIvuIenLIy, you muy uIso use diff(poiynomioix}.
nLegruLIon uIso works Ior poIynomIuIs:
p .= poiy(x^7 + x + 1}. inl(p x}
poIy
__
1
8
_
x
8
+
_
1
2
_
x
2
+ x, [x]
_
TIe IuncLIon gcd compuLes LIe greuLesL common dIvIsor oI poIynomIuIs:
p .= poiy((x + 1}^Z*(x + Z}}.
q .= poiy((x + 1}*(x + Z}^Z}.
foclor(gcd(p q}}
poIy (x + 2, [x]) poIy (x + 1, [x])
TIe InLernuI represenLuLIon oI u poIynomIuI sLores onIy LIose powers oI LIe
IndeLermInuLes wILI non-zero coeIIIcIenLs. TIIs Is purLIcuIurIy udvunLugeous Ior
spurse poIynomIuIs oI IIgI degree und mukes urILImeLIc wILI sucI poIynomIuIs
eIIIcIenL. TIe IuncLIon nlerms reLurns LIe number oI non-zero Lerms oI u
poIynomIuI. TIe IuncLIon nlhmonomioi exLrucLs IndIvIduuI monomIuIs (coeIIIcIenL
LImes powers oI LIe IndeLermInuLes), nlhcoeff und nlhlerm reLurn LIe
upproprIuLe coeIIIcIenL und producL oI powers oI LIe IndeLermInuLes, respecLIveIy:
p .= poiy(o*x^100 + b*x^10 + c _x]}.
q-Sq
4 NuPAD

Cb[ec|s
nlerms(p} nlhmonomioi(p Z}
nlhcoeff(p Z} nlhlerm(p Z}
3, poIy
_
b x
10
, [x]
_
, b, poIy
_
x
10
, [x]
_
TubIe q.6 Is u summury oI LIe operuLIons Ior poIynomIuIs dIscussed ubove. SecLIon
uncLIons Ior PoIynomIuIs oI LIe MuPAD QuIck ReIerence IIsLs IurLIer IuncLIons
Ior poIynomIuIs In LIe sLundurd IIbrury. TIe groebner IIbrury comprIses IuncLIons
Ior IundIIng muILIvurIuLe poIynomIuI IdeuIs (see ?groebner).
Ixercise q.q1: ConsIder LIe poIynomIuIs p = x
7
x
4
+x
3
1 und q = x
3
1.
CompuLe p q
2
. Does q dIvIde p? ucLor p und q.
Ixercise q.q: A poIynomIuI Is cuIIed IrreducIbIe (over u coeIIIcIenL IIeId) II IL
cunnoL be IucLored InLo u producL oI more LIun one nonconsLunL poIynomIuIs. TIe
IuncLIon irreducibie LesLs u poIynomIuI Ior IrreducIbIIILy. Ind uII IrreducIbIe
quudruLIc poIynomIuIs a x
2
+b x +c , a = 0 over LIe IIeId oI InLegers moduIo 3.
q-qo
Polynomiols

+, -, *, ^ : urILImeLIc
coeff : exLrucL coeIIIcIenLs
degree : poIynomIuI degree
diff, 0 : dIIIerenLIuLIon
divide : dIvIsIon wILI remuInder
evoip : evuIuuLIon
expr : conversIon Lo expressIon
foclor : IucLorIzuLIon
gcd : greuLesL common dIvIsor
mopcoeffs : uppIy u IuncLIon
muilcoeffs : muILIpIIcuLIon by u scuIur
nlerms : number oI non-zero coeIIIcIenLs
nlhcoeff : n-LI coeIIIcIenL
nlhmonomioi : n-LI monomIuI
nlhlerm : n-LI Lerm
poiy : consLrucL u poIynomIuI
poiyZiisl : conversIon Lo IIsL
TubIe q.6: MuPAD

IuncLIons operuLIng on poIynomIuIs


q-q1
4 NuPAD

Cb[ec|s
kurdwure lleuI krruys
UsuuIIy, IIouLIng-poInL compuLuLIons In compuLer uIgebru sysLems ure perIormed
In soILwure IIouLs, provIdIng user-conLroIIubIe precIsIon (In MuPAD

, vIu LIe
envIronmenL vurIubIe 0TCTTS) uL LIe expense oI memory und speed. TIere ure
cuses, Iowever, wIere especIuIIy LIe memory requIremenLs oI soILwure IIouLs ure
proIIbILIve, especIuIIy wIen ImporLIng duLu Irom un exLernuI source, sucI us
Imuge IIIes. or sucI occusIons, MuPAD versIon InLroduced u new duLu Lype,
urruys oI Iurdwure IIouLIng poInL numbers, 00M|FARRAY.
A Iurdwure IIouLIng poInL urruy Is creuLed by LIe IuncLIon hforroy, wIIcI mImIcs
orroy (cI. CIupLer q.q) cIoseIy. L cun conLuIn onIy IIouLIng poInL numbers (reuI
undJor compIex), und compIeLeIy Ignores LIe vuIues oI 0TCTTS Ior ILs
compuLuLIons, wIIcI ure perIormed on Iurdwure IIouLs wILI wIuLever precIsIon
LIe underIyIng Iurdwure undJor operuLIng sysLem provIde. (UsuuIIy, LIIs meuns
someLIIng uround 15 decImuI dIgILs.) AccessIng eIemenLs converLs LIem Lo und
Irom soILwure IIouLs:
A .= hforroy(1..10 1..10 _frondom(} S i = 1..100]}.
domlype(A} domlype(A_1 1]}
DOM_HARRAY, DOM_OAT
MosL oI LIe numeric IIbrury uccepLs Iurdwure IIouLIng poInL urruys us InpuLs und
reLurns objecLs oI LIe sume Lype:
B .= numeric..ffl(A}. domlype(B}
DOM_HARRAY
numeric..eigenvoiues(A}
[5.173121022, 0.8239615051, 0.3962245484 + 0.3259514491 i, . . . ]
q-q
Hordwore Floo| Arroys
n uddILIon Lo sLundurd urruy operuLIons, II-urruys uIIow uddILIon oI urruys oI LIe
sume sIze us weII us muLrIx muILIpIIcuLIon Ior Lwo-dImensIonuI II-urruys oI
compuLIbIe sIzes:
A .= hforroy(1..3 1..4 _S 1..1Z]}
B .= hforroy(1..4 1..Z _1/(i+g} S g = 1..Z S i= 1..4]}
_
_
_
1.0 2.0 3.0 4.0
5.0 6.0 7.0 8.0
9.0 10.0 11.0 12.0
_
_
_
_
_
_
_
_
_
0.5 0.3333333333
0.3333333333 0.25
0.25 0.2
0.2 0.1666666667
_
_
_
_
_
_
A + A A*B
_
_
_
2.0 4.0 6.0 8.0
10.0 12.0 14.0 16.0
18.0 20.0 22.0 24.0
_
_
_
_
_
_
2.716666667 2.1
7.85 5.9
12.98333333 9.7
_
_
_
q-q
4 NuPAD

Cb[ec|s
laIervul kriIhmeIit
TIere Is unoLIer kerneI duLu Lype, cuIIed 00MTWTERvAL. ObjecLs oI LIIs Lype
represenL reuI or compIex InLervuIs oI IIouLIng-poInL numbers. TIey provIde,
umong oLIer possIbIIILIes, u meuns oI conLroIIIng one oI LIe mosL IundumenLuI
probIems oI IIouLIng-poInL urILImeLIc: round-oII errors.
TIe busIc Ideu Is us IoIIows: nsLeud oI IIouLIng-poInL numbers x
1
, x
2
eLc., wIere
uImosL eucI operuLIon Ieuds Lo (usuuIIy smuII) errors, consIder InLervuIs X
1
, X
2
eLc. wIIcI ure known Lo conLuIn LIe precIse numbers comIng Irom LIe uppIIcuLIon.
One wouId IIke Lo Iuve u verIIIed sLuLemenL LIuL LIe vuIue y = f(x
1
, x
2
, . . . ) oI u
IuncLIon f IIes In some InLervuI Y . MuLIemuLIcuIIy, LIe Imuge seL
Y = f(X
1
, X
2
, . . . ) = {f(
1
,
2
, . . . );
1
X
1
;
2
X
2
; . . .}
Is wunLed. CompuLIng LIIs Imuge seL excctl Is u IormIdubIe Lusk. n IucL, IL Is Loo
umbILIous Lo usk Ior un exucL represenLuLIon wIen usIng IusL und memory eIIIcIenL
IIouLIng-poInL urILImeLIc. nsLeud, LIe InLervuI versIon oI u IuncLIon f Is un
uIgorILIm

f LIuL produces u Iurger seL

f(X
1
, X
2
, . . . ) wIIcI Is ucrcnteed Lo
conLuIn LIe exucL Imuge seL oI f:
f(X
1
, X
2
, . . . )

f(X
1
, X
2
, . . . ).
I we LIInk ubouL LIe InLervuIs X
1
, X
2
eLc. us IncorporuLIng LIe InuccurucIes In x
1
,
x
2
eLc. cuused by round-oII, LIe InLervuI versIon

f oI LIe IuncLIon f provIdes
verIIIed upper und Iower bounds Ior LIe resuIL y = f(x
1
, x
2
, . . . ) In wIIcI LIe
round-oII errors oI x
1
, x
2
eLc. Iuve propuguLed. AILernuLIveIy, you cun uIso regurd
X
1
, . . . us ImprecIse meusuremenLs or In some oLIer wuy underdeLermIned
quunLILy (LIIs purumeLer Is somewIere beLween 0 und 1, LIIs resIsLor Ius u
LoIerunce oI 10%). n sucI u seLLIng, LIe resuIL

f(X
1
, X
2
, . . . ) Is u seL ucrcnteed
Lo conLuIn cll possIbIe Lrue resuILs.
IouLIng-poInL InLervuIs ure creuLed Irom exucL numbers or IIouLIng-poInL
numbers usIng LIe IuncLIon huii or ILs operuLor equIvuIenL ...:
X1 .= huii(PT}
3.141592653 . . . 3.141592654
XZ .= cos(7*PT/9 ... 13*PT/9}
1.0 . . . 0.1736481776
q-qq
In|ervol Ari|hme|ic
CompIex InLervuIs ure recLunguIur ureus In LIe compIex pIuIn consIsLIng oI un
InLervuI Ior LIe reuI purL und un InLervuI Ior LIe ImugInury purL. UsIng huii or ...,
you muy specIIy LIe recLungIe by ILs Iower IeIL und upper rIgIL corners:
X3 .= (Z - 3*T} ... (4 + 5*T}
(2.0 . . . 4.0) +I (3.0 . . . 5.0)
TIe MuPAD

IuncLIons LIuL supporL InLervuI urILImeLIc IncIude LIe busIc


urILImeLIcuI operuLIons +, -, *, /, ^ us weII us mosL oI LIe specIuI IuncLIons sucI us
sin, cos, exp, in, obs eLc.:
X1^Z + XZ
8.869604401 . . . 9.695956224
X1 - T*XZ + X3
(5.141592653 . . . 7.141592654) +I (2.826351823 . . . 6.0)
sin(X1} + exp(obs(X3}}
7.389056098 . . . 603.728285
WIen dIvIdIng by un InLervuI conLuInIng 0, InIInILe InLervuIs ure produced. TIe
objecLs R0TWF und R0WTWF (rounded InIInILy und rounded neguLIve InIInILy,
respecLIveIy) represenL LIe vuIues In un InLervuI conLexL:
sin(XZ^Z - 1/Z}
0.4527492553 . . . 0.4794255387
1/x
RD_NN . . . 2.208728094 2.085829642 . . . RD_N
TIe IusL exumpIe sIows LIuL LIe urILImeLIc muy produce symboIIc unIons oI
IIouLIng-poInL InLervuIs. AcLuuIIy, LIe unIon Is sLIII oI Lype 00MTWTERvAL:
domlype(x}
DOM_NTERVA
q-qg
4 NuPAD

Cb[ec|s
n IucL, LIe IuncLIons union und inlersecl Ior creuLIng unIons und InLersecLIons oI
seLs cun be used Ior creuLIng InLervuIs (wIIcI ure, uILer uII, u specIuI kInd oI seLs):
X1 union XZ^Z
0.0301536896 . . . 1.0 3.141592653 . . . 3.141592654
cos(X1*XZ} inlersecl XZ
1.0 . . . 0.1736481776
SymboIIc objecLs sucI us IdenLIIIers (CIupLer q.) und IIouLIng poInL InLervuIs cun
be mIxed. TIe IuncLIon inlervoi repIuces uII numerIcuI subexpressIons oI un
expressIon (CIupLer q.q) by IIouLIng-poInL InLervuIs:
inlervoi(Z*x^Z + PT}
(2.0 . . . 2.0) x
2
+ (3.141592653 . . . 3.141592654)
n MuPAD, IdenLIIIers ure ImpIIcILIy ussumed Lo represenL urbILrury compIex
vuIues. ConsequenLIy, LIe IuncLIon huii repIuces x by LIe InLervuI represenLIng
LIe wIoIe compIex pIune:
huii(x}
(RD_NN . . . RD_N) +I (RD_NN . . . RD_N)
TIere Is u number oI specIuIIzed IuncLIons Ior IIouLIng-poInL InLervuIs uLLucIed us
meLIods Lo LIe kerneI domuIn 00MTWTERvAL. Here, we onIy menLIon
00MTWTERvAL..cenler (LIe cenLer oI un InLervuI or u unIon oI InLervuIs) und
00MTWTERvAL..Widlh (LIe wIdLI oI un InLervuI or u unIon oI InLervuIs):
00MTWTERvAL..cenler(Z ... 5 union 7 ... 9}
5.5
00MTWTERvAL..Widlh(Z ... 5 union 7 ... 9}
7.0
See ?00MTWTERvAL Ior u survey oI LIe uvuIIubIe meLIods.
urLIer, u IIbrury domuIn 0om..FioolTv exIsLs wIIcI Is jusL u Iuude Ior LIe
IIouLIng-poInL InLervuIs oI LIe kerneI Lype 00MTWTERvAL. L Is useIuI Ior
embeddIng IIouLIng-poInL InLervuIs In conLuIners sucI us muLrIces (CIupLer
q.1) or poIynomIuIs (CIupLer q.16). TIese conLuIners requIre LIe specIIIcIuLIon oI
u coeIIIcIenL domuIn LIuL Ius LIe muLIemuLIcuI properLIes oI u rIng. n order Lo
q-q6
In|ervol Ari|hme|ic
muke IIouLIng-poInL InLervuIs embeddubIe In sucI conLuIners, LIe domuIn
0om..FioolTv wus gIven u vurIeLy oI muLIemuLIcuI uLLrIbuLes (cuLegorIes)
requIred Ior sucI purposes:
0om..FioolTv..oiiColegories(}
_Col..Fieid ... Col..Ring ...]
n purLIcuIur, LIe seL oI uII IIouLIng poInL InLervuIs Is noL onIy regurded us u rIng,
buL even us u IIeId. SLrIcLIy speukIng, Iowever, LIese muLIemuLIcuI cuLegorIes ure
noL reuIIy udequuLe Ior InLervuI objecLs. or exumpIe, subLrucLIng un InLervuI Irom
ILseII does noL yIeId LIe zero eIemenL (LIe neuLruI eIemenL wILI respecL Lo
uddILIon):
(Z ... 3} - (Z ... 3}
1.0 . . . 1.0
PrugmuLIcuIIy, Iowever, LIe muLIemuLIcuI cuLegorIes were seL, unywuy, Lo enubIe
embeddIng. AILer uII, LIe operuLIons ImpIIed by LIese cuLegorIes do work. or
exumpIe, we consIder LIe Inverse oI u HIIberL muLrIx (uIso see ExercIse q.;).
TIese muLrIces ure noLorIousIy III-condILIoned. or LIe 8 8 HIIberL muLrIx, LIe
condILIon number (LIe ruLIo oI LIe IurgesL und LIe smuIIesL eIgenvuIue) Is
A .= iinoig..hiiberl(}.
ev .= numeric..eigenvoiues(A}.
mox(op(ev}}/min(op(ev}}
15257575299.0
RougIIy speukIng, wIen InverLIng LIIs muLrIx by u IIouLIng-poInL uIgorILIm, one
sIouId expecL Lo Ioose ubouL 1o decImuI dIgILs oI uccurucy:
iog(10 x}
10.18348552
ConsequenLIy, wILI Iow vuIues oI 0TCTTS, LIe Inverse sIouId be subsLunLIuIIy
murred by round-oII. ndeed, uILer conversIon oI A Lo u muLrIx oI IIouLIng-poInL
InLervuIs, we cun use LIe generIc uIgorILIm Ior muLrIx InversIon:
q-q,
4 NuPAD

Cb[ec|s
B .= 1/0om..Molrix(0om..FioolTv}(A}
orroy(1.. 1..
(1 1} = -73.Z9144677 ... Z01.Z91446
...
(3 Z} = -95519.1Z90 ... -9499Z1.709
...
( } = 176679046.Z ... 176679673.
}
TIe enLrIes oI LIe Inverse ure ucrcnteed Lo IIe In LIe IndIcuLed InLervuIs. TIe
componenL (8, 8) Is deLermIned Lo u precIsIon oI 6 IeudIng decImuI dIgILs, wIereus
LIe componenL (1, 1) Is onIy known Lo IIe somewIere beLween 73.29 und 201.3.
NoLe, Iowever, LIuL LIe generIc InversIon uIgorILIm Lends Lo overesLImuLe LIe
InLervuIs drusLIcuIIy. TIe resuILs reLurned by u numerIcuI InversIon wILI
sLundurd IIouLIng-poInL numbers miht ucLuuIIy be more uccuruLe LIun
predIcLed by LIIs InLervuI compuLuLIon.
TIe exucL componenLs oI LIe Inverse ure uvuIIubIe, Loo. AII enLrIes oI Inverse
HIIberL muLrIces ure InLegers:
C .= iinoig..invhiiberl(}
orroy(1.. 1..
(1 1} = 64
...
(3 Z} = -95Z560
...
( } = 176679360
}
UsIng LIe operuLor in, IL Is possIbIe Lo deLermIne wIeLIer u number or expressIon
Is InsIde un InLervuI. To combIne LIe muLrIces, we use zip (CIupLer q.1) und
cIeck Ior eucI enLry oI LIe exucL Inverse C II IL Is InsIde LIe InLervuI In LIe muLrIx B.
To LIIs end, LIe IoIIowIng InpuL converLs boLI muLrIces InLo IIsLs oI LIeIr enLrIes
und LIen perIorms LIe cIeck:
zip(_op(C}] _op(B}] (c b} -> booi(c in b}}
_TRuE TRuE TRuE TRuE ... TRuE]
q-qS
Null Cb[ec|s: nuii(}, WTL, FATL, undefined
ull 0bjetIs: nuii(}, WTL, FATL, undefined
TIere ure severuI objecLs represenLIng LIe voId In MuPAD

. IrsL, we Iuve LIe


empLy sequence generuLed by nuii(}. L Is oI domuIn Lype 00MWuLL und
generuLes no ouLpuL on LIe screen. SysLem IuncLIons sucI us resel (SecLIon 1.q),
prinl (SecLIon 1z.1), or if (CIupLer 16) wILIouL un eise bruncI, wIIcI cunnoL
reLurn muLIemuLIcuIIy useIuI vuIues, reLurn LIIs MuPAD objecL InsLeud:
o .= resel(}. b .= prinl("heiio"}.
"heiio"
domlype(o} domlype(b}
DOM_NU, DOM_NU
TIe objecL nuii(} Is purLIcuIurIy useIuI In connecLIon wILI sequences
(SecLIon q.). TIe sysLem uuLomuLIcuIIy removes LIIs objecL Irom sequences, und
you cun use IL, Ior exumpIe, Lo remove sequence enLrIes seIecLIveIy:
deiele o b c.
Seq .= o b c. Seq .= subs(Seq b = nuii(}}
a, c
Here we Iuve used LIe subsLILuLIon commund subs (CIupLer 6) Lo repIuce b by
nuii(}.
TIe MuPAD objecL WTL, wIIcI Is dIsLIncL Irom nuii(}, InLuILIveIy meuns no
vuIue. Some sysLem IuncLIons reLurn LIe WTL objecL wIen you cuII LIem wILI
urgumenLs Ior wIIcI LIey need noL compuLe unyLIIng. A LypIcuI exumpIe ure
unInILIuIIzed operunds oI urruys:
A .= orroy(1..Z}. op(A 1}
N
UnInILIuIIzed IocuI vurIubIes und purumeLers oI MuPAD procedures uIso Iuve LIe
vuIue WTL (SecLIon 1;.q).
TIe MuPAD objecL FATL InLuILIveIy meuns couId noL IInd u vuIue. SysLem
IuncLIons reLurn LIIs objecL wIen LIere Is no meunIngIuI resuIL Ior LIe gIven InpuL
purumeLers.
q-qq
4 NuPAD

Cb[ec|s
n LIe IoIIowIng exumpIe, we Lry Lo compuLe LIe Inverse oI u sInguIur muLrIx:
A .= molrix(__1 Z] _Z 4]]}
_
1 2
2 4
_
A^(-1}
A
AnoLIer objecL wILI u sImIIur meunIng Is undefined. or exumpIe, LIe MuPAD
IuncLIon iimil reLurns LIIs objecL wIen LIe requesLed IImIL does noL exIsL:
iimil(1/x x = 0}
undeIIned
ArILImeLIcuI operuLIons wILI undefined reLurn uguIn undefined:
undefined + 1 Z^undefined
undeIIned, undeIIned
q-1oo
5
Ivuloution und SimpliIicution
ldeaIihers uad heir ulues
ConsIder:
deiele x o. y .= o + x
a +x
SInce LIe IdenLIIIers o und x onIy represenL LIemseIves, LIe vuIue oI y Is LIe
symboIIc expressIon a +x. We Iuve Lo dIsLInguIsI cureIuIIy beLween LIe IdenLIIIer
y und ILs vuIue. More precIseIy, LIe tclue oI un IdenLIIIer denoLes LIe MuPAD

objecL LIuL LIe sysLem compuLes by evuIuuLIon und sImpIIIIcuLIon oI LIe


rIgIL-Iund sIde oI LIe ussIgnmenL idenlifier.=voiue ct the time oj cssinment.
NoLe LIuL In LIe exumpIe ubove, LIe vuIue oI y Is composed oI LIe symboIIc
IdenLIIIers o und x, wIIcI muy be ussIgned vuIues uL u IuLer LIme. or exumpIe, II
we ussIgn LIe vuIue 1 Lo LIe IdenLIIIer o, LIen o Is repIuced by ILs vuIue 1 In LIe
expressIon o+x, und LIe cuII y reLurns x + 1:
o .= 1. y
x + 1
We suy LIuL LIe etcluction oI LIe IdenLIIIer y reLurns LIe resuIL x + 1, buL ILs tclue
Is sLIII o+x:
We dIsLInguIsI beLween un IdenLIIIer, ILs vuIue, und ILs evuIuuLIon: LIe
tclue denoLes LIe evuIuuLIon ct the time oj cssinment, u IuLer
etcluction muy reLurn u dIIIerenL current tclue.
5 Evoluo|ion ond 5implihco|ion
I we now ussIgn LIe vuIue 2 Lo x, LIen boLI o und x ure repIuced by LIeIr vuIues uL
LIe nexL evuIuuLIon oI y. Hence we obLuIn LIe sum 2 + 1 us u resuIL, wIIcI MuPAD
uuLomuLIcuIIy sImpIIIIes Lo 3:
x .= Z. y
3
TIe etcluction oI y now reLurns LIe number 3; ILs tclue Is sLIII a +x.
L Is reusonubIe Lo suy LIuL LIe vuIue oI y Is LIe resuIL uL LIe LIme oI ussIgnmenL.
NumeIy, II we deIeLe LIe vuIues oI LIe IdenLIIIers o und x In LIe ubove exumpIe,
LIen LIe evuIuuLIon oI y yIeIds ILs orIgInuI vuIue ImmedIuLeIy uILer LIe ussIgnmenL:
deiele o x. y
a +x
I o or x uIreudy Iuve u vuIue bejore we ussIgn LIe expressIon o+x Lo y, LIen LIe
IoIIowIng Iuppens:
x .= 1. y .= o + x. y
a + 1
AL LIe LIme oI ussIgnmenL, y Is ussIgned LIe evuIuuLIon oI o+x, I.e., a + 1. ndeed,
LIIs Is now LIe tclue oI y, wIIcI conLuIns no reIerence Lo x:
deiele x. y
a + 1
Here ure some IurLIer exumpIes Ior LIIs mecIunIsm. We IIrsL ussIgn LIe ruLIonuI
number 1/3 Lo x, LIen we ussIgn LIe objecL _xx^Zx^3] Lo LIe IdenLIIIer iisl. n
LIe ussIgnmenL, LIe sysLem evuIuuLes LIe rIgIL-Iund sIde und uuLomuLIcuIIy
repIuces LIe IdenLIIIer x by ILs vuIue. TIus, uL LIe LIme oI ussIgnmenL, LIe IdenLIIIer
iisl geLs LIe vuIue [
1
/3,
1
/9,
1
/27] und noL [x, x
2
, x
3
]:
x .= 1/3. iisl .= _x x^Z x^3]
_
1
3
,
1
9
,
1
27
_
g-
Iden|ihers ond Their Volues
deiele x. iisl
_
1
3
,
1
9
,
1
27
_
MuPAD uppIIes LIe sume evuIuuLIon scIeme Lo symboIIc IuncLIon cuIIs:
deiele f. y .= f(PT}
f()
AILer LIe ussIgnmenL
f .= sin.
we obLuIn LIe evuIuuLIon
y
0
WIen evuIuuLIng y, LIe sysLem repIuced LIe IdenLIIIer f by ILs vuIue, wIIcI Is LIe
vuIue oI LIe IdenLIIIer sin. TIIs Is u procedure wIIcI Is execuLed wIen y Is
evuIuuLed und reLurns sIn() us 0.
g-
5 Evoluo|ion ond 5implihco|ion
fempleIe, latempleIe, uad alerted vuluuIiea
We consIder once uguIn LIe IIrsL exumpIe Irom LIe prevIous secLIon. TIere we Iuve
ussIgned LIe expressIon o+x Lo LIe IdenLIIIer y, und o und x dId noL Iuve u vuIue:
deiele o x. y .= o + x. o .= 1. y
x + 1
We now expIuIn In greuLer deLuII Iow MuPAD

perIorms LIe IInuI evuIuuLIon.


IrsL (IeveI 1) LIe evuIuuLor consIders LIe vuIue a +x oI y. SInce LIIs vuIue
conLuIns IdenLIIIers x und o, u second evuIuuLIon sLep (IeveI 2) Is necessury Lo
deLermIne LIe vuIue oI LIese IdenLIIIers. TIe sysLem recognIzes LIuL o Ius LIe
vuIue 1, wIIIe x Ius no vuIue (und LIus muLIemuLIcuIIy represenLs un unknown).
Now LIe sysLem`s urILImeLIc combInes LIese resuILs Lo x + 1, und LIIs Is LIe
evuIuuLIon oI y. Igures .1-. IIIusLruLe LIIs process. A box represenLs un
IdenLIIIer und ILs vuIue (or , respecLIveIy, II IL Ius no vuIue). An urrow represenLs
one evuIuuLIon sLep.
y
Igure .1: TIe IdenLIIIer
y wILIouL u vuIue.
y
+ x u
Igure .z: AILer LIe us-
sIgnmenL y.=o+x.
y
+ x u
1
Igure .: AILer LIe us-
sIgnmenL o.=1, we IInuIIy
obLuIn x+1 us LIe evuIuu-
LIon oI y.
n unuIogy Lo LIe expressIon Lrees Ior represenLIng symboIIc expressIons
(SecLIon q.q), you muy ImugIne LIe process oI evuIuuLIon us un etcluction tree,
wIose verLIces ure expressIons wILI symboIIc IdenLIIIers, wILI bruncIes poInLIng
Lo LIe correspondIng vuIues oI LIese IdenLIIIers. TIe sysLem Lruverses LIIs Lree
unLII LIere ure eILIer no IdenLIIIers IeIL or uII remuInIng IdenLIIIers Iuve no vuIue.
g-q
Comple|e, Incomple|e, ond Enlorced Evoluo|ion
TIe user muy conLroI LIe IeveIs oI LIIs Lree vIu LIe sysLem IuncLIon ievei. We Iook
uL un exumpIe:
deiele o b c. x .= o + b. o .= b + 1. b .= c.
TIe evuIuuLIon Lree Ior x Is:
x
+ u
b
+
b 1 c
c
IeveI 0 :
IeveI 1 :
IeveI 2 :
IeveI 3 :
TIe IdenLIIIer x Iorms LIe Lop IeveI (LIe rooL, IeveI 0) oI ILs own evuIuuLIon Lree:
ievei(x 0}
x
TIe nexL IeveI 1 deLermInes LIe vuIue oI x:
ievei(x 1}
a +b
AL LIe IoIIowIng IeveI 2, o und b ure repIuced by LIeIr vuIues b + 1 und c,
respecLIveIy:
ievei(x Z}
b +c + 1
g-g
5 Evoluo|ion ond 5implihco|ion
TIe remuInIng b Is repIuced by ILs vuIue c onIy In LIe nexL IeveI 3:
ievei(x 3}
2 c + 1
We cuII LIe Lype oI evuIuuLIon descrIbed Iere u complete etcluction. TIIs meuns
LIuL IdenLIIIers ure repIuced by LIeIr vuIues recursIveIy unLII no IurLIer evuIuuLIons
ure possIbIe. TIe envIronmenL vurIubIe LEvEL, wIIcI Ius LIe deIuuIL vuIue 100,
deLermInes Iow Iur MuPAD descends uL mosL In un evuIuuLIon Lree.
n InLerucLIve mode, MuPAD uIwuys evuIuuLes compIeLeIy!
More precIseIy, LIIs meuns LIuL MuPAD evuIuuLes up Lo depLI LEvEL In InLerucLIve
mode.
1
deiele o0 o1 oZ. LEvEL .= Z.
o0 .= o1. o0
u1
o1 .= oZ. o0
uz
Up Lo now, LIe evuIuuLIon Lree Ior o0 Ius depLI 2, und LIe LEvEL vuIue oI 2
ucIIeves u compIeLe evuIuuLIon. However, In LIe nexL sLep, LIe vuIue oI oZ Is noL
Luken InLo uccounL:
oZ .= o3. o0
uz
To resLore LIe deIuuIL vuIue oI LEvEL, we use deiele:
deiele LEvEL.
As soon us MuPAD reuIIzes LIuL LIe currenL evuIuuLIon IeveI exceeds LIe vuIue oI
LIe envIronmenL vurIubIe MAXLEvEL (wIose deIuuIL vuIue Is 100), LIen IL ussumes
Lo be In un InIInILe Ioop und uborLs LIe evuIuuLIon wILI un error messuge:
1
One sIouId noL conIuse LIIs wILI LIe eIIecL oI u sysLem IuncLIon cuII, wIIcI muy reLurn u not com-
pletel etclucted object, sucI us subs (CIupLer 6). TIe cuII subs(sin(x}x=0}, Ior exumpIe, reLurns
sIn(0) und noL 0! TIe IuncLIonuIILy oI subs Is Lo perIorm u subsLILuLIon und Lo reLurn LIe resuILIng objecL
wILIouL IurLIer evuIuuLIon.
g-6
Comple|e, Incomple|e, ond Enlorced Evoluo|ion
MAXLEvEL .= Z. o0
Error. Recursive definilion _See ?MAXLEvEL]
deiele MAXLEvEL.
We now presenL some ImporLunL excepLIons Lo LIe ruIe oI compIeLe evuIuuLIon.
TIe cuIIs iosl(i}, xi, or x (CIupLer 1.z) do noL Ieud Lo un evuIuuLIon! We
consIder LIe exumpIe
deiele x. _sin(x} cos(x}]. x .= 0.
Now, xZ uccesses LIe IIsL wILIouL evuIuuLIng IL:
xZ
[sIn(x) , cos(x)]
However, you cun enIorce evuIuuLIon by meuns oI evoi:
evoi(x}
[0, 1]
Compure LIIs Lo LIe IoIIowIng sLuLemenLs, wIere requesLIng LIe IdenLIIIer iisl
cuuses LIe usuuI compIeLe evuIuuLIon:
deiele x. iisl .= _sin(x} cos(x}]. x .= 0. iisl
[0, 1]
Arruys oI domuIn Lype 00MARRAY ure uIwuys evuIuuLed wILI IeveI 1:
deiele o b. A .= orroy(1..Z _o b]}.
b .= o. o .= 1. A
_
a b
_
As you cun see, LIe cuII oI A reLurns LIe vuIue (LIe urruy), buL does noL repIuce ob
by LIeIr vuIues. You cun evuIuuLe LIe enLrIes vIu mop(Aevoi}:
mop(A evoi}
_
1 1
_
g-,
5 Evoluo|ion ond 5implihco|ion
NoLe LIuL In conLrusL Lo LIe ubove beIuvIor, LIe Indexed uccess oI un IndIvIduuI
enLry Is evuIuuLed compIeLeIy:
A_1] A_Z]
1, 1
MuLrIces (oI Lype 0om..Molrix(}), LubIes (oI domuIn Lype 00MTABLE), und
poIynomIuIs (00MP0LY) ure LreuLed In LIe sume wuy us urruys. Moreover, wILIIn
procedures, MuPAD uIwuys evuIuuLes onIy up Lo IeveI 1 (SecLIon 1;.11). I LIIs Is
noL suIIIcIenL, you muy conLroI LIIs beIuvIor expIIcILIy by meuns oI ievei.
TIe commund hoid(obgecl} Is sImIIur Lo ievei(obgecl0} und prevenLs LIe
evuIuuLIon oI obgecl.
z
TIIs muy be desIrubIe In muny sILuuLIons. TIe IoIIowIng
IuncLIon, wIIcI cunnoL be execuLed Ior symboIIc urgumenLs, yIeIds un exumpIe
wIere LIe (premuLure) evuIuuLIon Is undesIrubIe:
obsvoiue .= X -> (if X >= 0 lhen X eise -X endif}.
obsvoiue(X}
Error. Conl evoiuole lo booieon _ieequoi]
during evoiuolion of obsvoiue
I you wunL Lo numerIcuIIy InLegruLe LIIs IuncLIon usIng numeric..inl, LIe
obvIous InpuL reLurns LIe sume error:
numeric..inl(obsvoiue(X} X = -1..1}
Error. Conl evoiuole lo booieon _ieequoi]
during evoiuolion of obsvoiue
I you deIuy LIe evuIuuLIon oI obsvoiue(X} by hoid, LIe vuIue Is compuLed:
numeric..inl(hoid(obsvoiue}(X} X = -1..1}
1.0
TIe reuson Is LIuL numeric..inl InLernuIIy subsLILuLes numerIcuI vuIues Ior X, Ior
wIIcI obsvoiue cun be evuIuuLed wILIouL probIems.
z
See ?hoid Ior LIe exucL dIIIerence beLween hoid(obgecl} und ievei(obgecl0}.
g-S
Comple|e, Incomple|e, ond Enlorced Evoluo|ion
Here Is unoLIer exumpIe: IIke mosL MuPAD IuncLIons, LIe IuncLIon domlype IIrsL
evuIuuLes ILs urgumenL, so LIuL LIe commund domlype(obgecl} reLurns LIe
domuIn Lype oI LIe etcluction oI obgecl:
x .= 1. y .= 1. x x + y sin(0} sin(0.1}
1, 2, 0, 0.09983341665
domlype(x} domlype(x + y} domlype(sin(0}}
domlype(sin(0.1}}
DOM_NT, DOM_NT, DOM_NT, DOM_OAT
UsIng hoid, you obLuIn LIe domuIn Lypes oI LIe objecLs LIemseIves: x Is un
IdenLIIIer, x+y Is un expressIon, und sin(0} und sin(0.1} ure IuncLIon cuIIs und
Ience expressIons us weII:
domlype(hoid(x}} domlype(hoid(x + y}}
domlype(hoid(sin(0}}} domlype(hoid(sin(0.1}}}
DOM_DENT, DOM_EXPR, DOM_EXPR, DOM_EXPR
TIe communds ?ievei und ?hoid provIde IurLIer InIormuLIon Irom LIe
correspondIng IeIp puges.
Ixercise g.1: WIuL ure LIe tclues oI LIe IdenLIIIers x, y, und z uILer LIe IoIIowIng
sLuLemenLs? WIuL Is LIe etcluction oI LIe IusL sLuLemenL In eucI cuse?
deiele o1 b1 c1 x.
x .= o1. o1 .= b1. o1 .= c1. x
deiele oZ bZ cZ y.
oZ .= bZ. y .= oZ. bZ .= cZ. y
deiele o3 b3 z.
b3 .= o3. z .= b3. o3 .= 10. z
PredIcL LIe resuILs oI LIe IoIIowIng sLuLemenL sequences:
deiele u1 v1 W1.
u1 .= v1. v1 .= W1. W1 .= u1. u1
deiele uZ vZ.
uZ .= vZ. uZ .= uZ^Z - 1. uZ
g-q
5 Evoluo|ion ond 5implihco|ion
kuIemuIit $implihtuIiea
MuPAD

uuLomuLIcuIIy sImpIIIIes muny objecLs sucI us cerLuIn IuncLIon cuIIs or


urILImeLIcuI expressIons wILI numbers:
sin(15*PT} exp(0} (1 + T}*(1 - T}
0, 1, 2
TIe sume IoIds Lrue Ior urILImeLIc expressIons conLuInIng infinily:
Z*infinily - 5

SucI uuLomuLIc sImpIIIIcuLIons serve Ior reducIng LIe compIexILy oI expressIons


wILIouL un expIIcIL requesL by LIe user:
cos(1 + exp((-1}^(1/Z}*PT}}
1
TIe user cun neILIer conLroI nor exLend LIe uuLomuLIc sImpIIIIer.
n mosL cuses, Iowever, MuPAD does not uuLomuLIcuIIy sImpIIIy expressIons. TIe
reuson Is LIuL LIe sysLem generuIIy cunnoL decIde wIIcI Is LIe mosL reusonubIe
wuy oI sImpIIIIcuLIon. or exumpIe, consIder LIe IoIIowIng expressIon wIIcI Is noL
sImpIIIIed:
y .= (-4*x + x^Z + x^3 - 4}*(7*x - 5*x^Z + x^3 - 3}

_
x
3
5 x
2
+ 7 x 3
_ _
x
3
x
2
+ 4 x + 4
_
NuLuruIIy, you cun expund LIIs expressIon, wIIcI muy be reusonubIe, Ior exumpIe,
beIore compuLIng ILs symboIIc InLegruI:
expond(y}
x
6
4 x
5
2 x
4
+ 20 x
3
11 x
2
16 x + 12
g-1o
Au|omo|ic 5implihco|ion
However, II you ure InLeresLed In LIe rooLs oI LIe poIynomIuI, IL mukes more sense
Lo compuLe ILs IIneur IucLors:
foclor(y}
(x 3) (x 1)
2
(x 2) (x + 2) (x + 1)
No unIversuI unswer Is possIbIe Lo LIe quesLIon wIIcI oI LIe Lwo represenLuLIons Is
sImpIer. DependIng on LIe InLended uppIIcuLIon, you cun seIecLIveIy uppIy
upproprIuLe sysLem IuncLIons (sucI us expond or foclor) Lo sImpIIIy un
expressIon.
TIere Is unoLIer urgumenL uguInsL uuLomuLIc sImpIIIIcuLIon. TIe symboI f, Ior
exumpIe, mIgIL represenL u bounded IuncLIon, Ior wIIcI LIe IImIL IIm
x0
xf(x) Is
0. However, sImpIIIyIng LIIs expressIon Lo 0 cun be wrong Ior IuncLIons f wILI u
sInguIurILy uL LIe orIgIn sucI us f(x) = 1/x! TIus, uuLomuLIc sImpIIIIcuLIons sucI
us 0 f(0) = 0 ure quesLIonubIe us Iong us LIe sysLem Ius no uddILIonuI knowIedge
ubouL LIe symboIs InvoIved. n generuI, MuPAD cunnoL know wIIcI ruIe cun be
uppIIed und wIIcI musL noL. Now you mIgIL objecL LIuL MuPAD sIouId perIorm
no sImpIIIIcuLIons uL uII InsLeud oI wrong ones. UnIorLunuLeIy, LIIs Is noL
reusonubIe eILIer, sInce In symboIIc compuLuLIons, expressIons Lend Lo grow very
quIckIy, und LIIs serIousIy uIIecLs LIe perIormunce oI LIe sysLem. n IucL, In mosL
cuses MuPAD sImpIIIIes un expressIon oI LIe Iorm 0*y Lo 0, excepL, e.g., wIen LIe
vuIue oI y Is infinily, FATL, or undefined. You sIouId uIwuys keep In mInd LIuL
sucI u sImpIIIIed resuIL muy be wrong In exLreme cuses.
or LIuL reuson, MuPAD perIorms onIy some sImpIIIIcuLIons uuLomuLIcuIIy, und
you musL expIIcILIy requesL oLIer sImpIIIIcuLIons yourseII. or LIIs purpose
MuPAD provIdes u vurIeLy oI IuncLIons, some oI wIIcI ure descrIbed In
SecLIon q.z.
WIIIe LIe uuLomuLIc sImpIIIIcuLIons Iuve been cureIuIIy cIosen, LIere ure sLIII
exumpIes wIere LIey Ieud Lo unexpecLed resuILs, usuuIIy becuuse oI umbIguILIes In
muLIemuLIcuI noLuLIon. An exumpIe Is LIe soIuLIon oI LIe equuLIon x/x = 1 Ior
x = 0:
soive(x/x = 1 x}
C
g-11
5 Evoluo|ion ond 5implihco|ion
TIe MuPAD equuLIon soIver soive (CIupLer 8) reLurns LIe seL C oI uII compIex
numbers.

TIus, soive cIuIms LIuL crbitrcr compIex vuIues oI x yIeId u soIuLIon


oI LIe equuLIon x/x = 1. TIe reuson Is LIuL LIe sysLem IIrsL uuLomuLIcuIIy
sImpIIIIes LIe expressIon x/x Lo 1, und LIen In IucL soIves LIe equuLIon 1 = 1. TIe
excepLIonuI cuse x = 0, Ior wIIcI LIe orIgInuI probIem mukes no sense, Is
compIeLeIy Ignored In LIe sImpIIIIed ouLpuL!

To enLer LIIs seL, Lype C.


g-1
Evoluo|ion o| o Poin|
vuluuIiea uI u FeiaI
TIere Is uIso unoLIer concepL commonIy known us evuIuuLIon, numeIy repIucIng
some pIuceIoIder (Iree vurIubIe) by u specIIIc vuIue und sImpIIIyIng LIe resuILIng
expressIon. TIIs operuLIon Is ImpIemenLed by LIe IuncLIon evoiAl, wIIcI Is uIso
uccessIbIe us LIe 1 operuLor. (TIe 1 operuLor mImIcs LIe noLuLIon f(x)|
x=1
commonIy used In muLI LexLs.)
f .= sin(x}.
f 1 x=0 f 1 x=1
0, sIn(1)
NoLe LIuL, unIIke subs, evoiAl respecLs LIe muLIemuLIcuI meunIng und onIy
subsLILuLes Iree vurIubIes, noL bound ones:
deiele f.
F .= inl(f(x} x=0..infinily} + sin(x}.
subs(F x = 1} F 1 x=1
sIn(1) +
_

0
f(1) d1, sIn(1) +
_

0
f(x) dx
g-1
6
Sobstitotion: subs, subsex, und
subsop
AII MuPAD

objecLs consIsL oI operunds (SecLIon q.1). An ImporLunL IeuLure oI u


compuLer uIgebru sysLem Is LIuL IL cun repIuce LIese buIIdIng bIocks by new
vuIues. or LIuL purpose, MuPAD provIdes LIe IuncLIons subs, subsex (sIorL Ior:
subsLILuLe expressIon), und subsop (sIorL Ior: subsLILuLe operund).
TIe commund subs(obgecl 0id=WeW} repIuces uII occurrences oI LIe
subexpressIon 0id In obgecl by LIe vuIue WeW:
f .= o + b*c^b. g .= subs(f b = Z}. f g
a +b c
b
, 2 c
2
+a
You see LIuL subs reLurns LIe resuIL oI LIe subsLILuLIon, buL LIe IdenLIIIer f
remuIns uncIunged. I you represenL u mup F by LIe expressIon f = F(x), LIen
you muy use subs Lo evuIuuLe LIe IuncLIon uL some poInL:
f .= 1 + x + x^Z.
subs(f x = 0} subs(f x = 1}
subs(f x = Z} subs(f x = 3}
1, 3, 7, 13
NoLe, Iowever, LIuL subs (us weII us LIe communds subsex und subsop Lo be
IundIed sIorLIy) perIorms u pureIy synLucLIcuI repIucemenL, wIIcI muy Ieud Lo
IncorrecL resuILs wIen evuIuuLIng u IuncLIon In LIIs wuy:
f .= x/sin(x}. subs(f x = 0}
0
5ubs|i|u|ion: subs, subsex, ond subsop
deiele g. C .= inl(g(x} x=0..infinily}.
subs(C x=0}
_

0
g(0) d0
To geL subsLILuLIons respecLIng muLIemuLIcuI meunIng, use LIe 1 operuLor or ILs
equIvuIenL IuncLIon evoiAl InsLeud, wIIcI Ius uIreudy been descrIbed uL LIe end
oI CIupLer :
f 1 x=0
Error. 0ivision by zero _poWer]
during evoiuolion of evoiAl
C 1 x=0
_

0
g(x) dx
TIe ouLpuL oI LIe subs commund Is subjecLed Lo LIe usuuI sImpIIIIcuLIons oI LIe
InLernuI sImpIIIIer. n LIe ubove exumpIe, LIe cuII subs(fx=0} produces LIe
objecL 1+0+0^Z, wIIcI Is uuLomuLIcuIIy sImpIIIIed Lo 1. You musL noL conIuse LIIs
wILI etcluction (CIupLer ), wIere In uddILIon uII IdenLIIIers In un expressIon ure
repIuced by LIeIr vuIues.
TIe IuncLIon subs perIorms u subsLILuLIon. TIe sysLem onIy sImpIIIIes
LIe resuILIng objecL, buL does noL evuIuuLe IL upon reLurn!
n LIe IoIIowIng exumpIe
f .= x + sin(x}. g .= subs(f x = 0}
sIn(0)
LIe IdenLIIIer sin Ior LIe sIne IuncLIon Is noL repIuced by LIe correspondIng
MuPAD IuncLIon, wIIcI wouId reLurn sin(0}=0. OnIy LIe nexL cuII Lo g perIorms
u compIeLe evuIuuLIon:
g
0
6-
5ubs|i|u|ion: subs, subsex, ond subsop
You cun enIorce evuIuuLIon by usIng evoi:
evoi(subs(f x = 0}}
0
You muy repIuce urbILrury MuPAD objecLs by subsLILuLIon. n purLIcuIur, you cun
subsLILuLe IuncLIons or procedures us new vuIues:
evoi(subs(h(o + b} h = (x -> 1 + x^Z}}}
(a +b)
2
+ 1
I you wunL Lo repIuce u sysLem IuncLIon, encIose ILs nume In u hoid commund:
evoi(subs(sin(o + b} hoid(sin} = (x -> x - x^3/3}}}
a +b
(a +b)
3
3
You cun uIso repIuce more compIex subexpressIons:
subs(sin(x}/(sin(x} + cos(x}} sin(x} + cos(x} = 1}
sIn(x)
You sIouId be cureIuI wILI sucI subsLILuLIons: LIe commund
subs(obgecl0id=WeW} repIuces uII LIose occurrences oI LIe expressIon 0id thct
ccn be jound b mecns oj op. TIIs expIuIns wIy noLIIng Iuppens In LIe IoIIowIng
exumpIe:
subs(o + b + c o + b = 1} subs(o * b * c o * b = 1}
a +b +c, a b c
Here LIe sum o+b und LIe producL o*b ure not operunds oI LIe correspondIng
expressIons. Even worse, we IInd:
f .= o + b + sin(o + b}. subs(f o + b = 1}
a +b + sIn(1)
AguIn, you cunnoL obLuIn LIe subexpressIon o+b oI LIe ouLer sum by meuns oI op.
However, LIe urgumenL oI LIe sIne Is LIe sub-operund op(f_31]} (see
SecLIons q.1 und q.q), und Ience IL Is repIuced by 1.
6-
5ubs|i|u|ion: subs, subsex, ond subsop
n conLrusL Lo subs, LIe IuncLIon subsex uIso repIuces subexpressIons In sums und
producLs:
subsex(f o + b = x + y} subsex(o * b * c o * b = x + y}
x +y + sIn(x +y) , c (x +y)
TIIs kInd oI subsLILuLIon requIres u cIoser unuIysIs oI LIe expressIon Lree, und
Ience subsex Is mucI sIower LIun subs Ior Iurge objecLs. WIen repIucIng more
compIex subexpressIons, you sIouId noL be mIsIed by LIe screen ouLpuL oI
expressIons:
f .= o/(b*c}
a
b c
subs(f b*c = WeW} subsex(f b*c = WeW}
a
b c
,
a
New
I you Iook uL LIe operunds oI f, you see LIuL LIe expressIon Lree does noL conLuIn
LIe producL b*c. TIIs expIuIns wIy no subsLILuLIon Look pIuce In LIe subs cuII:
op(f}
a,
1
b
,
1
c
You cun perIorm severuI subsLILuLIons wILI u sIngIe cuII oI subs:
subs(o + b + c o = A b = B c = C}
A+B +C
TIIs Is equIvuIenL Lo LIe nesLed cuII
subs(subs(subs(o + b + c o = A} b = B} c = C}.
TIus we obLuIn:
subs(o + b^Z o = b b = o}
a
2
+a
IrsL, MuPAD repIuces o by b, yIeIdIng b+b^Z. TIen IL subsLILuLes o Ior b In LIIs
new expressIon und reLurns LIe ubove resuIL. n conLrusL, you muy ucIIeve u
6-q
5ubs|i|u|ion: subs, subsex, ond subsop
simultcneous substitution by specIIyIng LIe subsLILuLIon equuLIons In Iorm oI u
IIsL or u seL:
subs(o + b^Z _o = b b = o]}
subs(o + b^Z {o = b b = o]}
a
2
+b, a
2
+b
TIe ouLpuL oI LIe equuLIon soIver soive (CIupLer 8) supporLs LIe IuncLIonuIILy oI
subs. n generuI, soive reLurns IIsLs oI equuLIons, wIIcI muy be used In subs:
equolions .= {x + y = Z x - y = 1].
soiulion .= soive(equolions {x y]}
__
x =
3
2
, y =
1
2
__
subs(equolions op(soiulion 1}}
{1 = 1, 2 = 2}
TIe IuncLIon subsop provIdes unoLIer vurIunL oI subsLILuLIon:
subsop(obgecl i=WeW} seIecLIveIy repIuces LIe i-LI operund oI LIe objecL by LIe
vuIue WeW:
subsop(Z*c + o^Z Z = d^5}
d
5
+ 2 c
Here, we Iuve repIuced LIe second operund o^Z oI LIe sum by d^5. n LIe
IoIIowIng exumpIe, we IIrsL repIuce LIe exponenL oI LIe second Lerm (LIIs Is LIe
operund _ZZ] oI LIe sum), und LIen LIe IIrsL Lerm:
subsop(Z*c + o^Z _Z Z] = 4 1 = x*y}
a
4
+xy
n LIe IoIIowIng expressIon, we IIrsL repIuce LIe IIrsL Lerm, yIeIdIng LIe expressIon
x*y+c^Z. TIen we subsLILuLe z Ior LIe second IucLor oI LIe IIrsL Lerm (wIIcI now
Is y):
subsop(o*b + c^Z 1 = x*y _1 Z] = z}
c
2
+xz
6-g
5ubs|i|u|ion: subs, subsex, ond subsop
TIe expressIon o+Z Is u symboIIc sum, wIIcI Ius u 0-LI operund, numeIy, LIe
sysLem IuncLIon pius Ior generuLIng sums:
op(o + Z 0}
_pIus
You cun repIuce LIIs operund by uny oLIer IuncLIon (Ior exumpIe, by LIe sysLem
IuncLIon muil wIIcI muILIpIIes ILs urgumenLs):
subsop(o + Z 0 = muil}
2 a
WIen usIng subsop, you need Lo know LIe posILIon oI LIe operund LIuL you wunL
Lo repIuce. NoneLIeIess, you sIouId be cuuLIous, sInce LIe sysLem muy cIunge LIe
order oI LIe operunds wIen LIIs Is muLIemuLIcuIIy vuIId (Ior exumpIe, In sums,
producLs, or seLs):
sel .= {sin(1 + o} o b c^Z]
_
a, b, sIn(a + 1) , c
2
_
I you use subs, you need noL know LIe posILIon oI LIe subexpressIon. AnoLIer
dIIIerence beLween subs und subsop Is LIuL subs Lruverses LIe expressIon Lree oI
LIe objecL recursitel, und LIus uIso repIuces suboperunds:
subs(sel o = o^Z}
_
b, sIn
_
a
2
+ 1
_
, a
2
, c
2
_
6-6
5ubs|i|u|ion: subs, subsex, ond subsop
Ixercise 6.1: Does LIe commund subsop(b+o 1=c} repIuce
LIe IdenLIIIer b by c?
Ixercise 6.: TIe communds
deiele f. g .= diff(f(x}/diff(f(x} x} x S 5}
Z5 diff(f(x} x x} diff(f(x} x x x x}
------------------------------------------ -
Z
diff(f(x} x}
4 diff(f(x} x x x x x}
--------------------------- - ...
diff(f(x} x}
generuLe u IengLIy expressIon conLuInIng symboIIc derIvuLIves. Muke LIIs
expressIon more reudubIe by repIucIng LIese derIvuLIves by sImpIer numes
f
0
= f(x), f
1
= f

(x), eLc.
6-,
7
iIIerentiution und Integrution
We Iuve uIreudy used LIe MuPAD

communds Ior dIIIerenLIuLIon und InLegruLIon.


SInce LIey ure ImporLunL, we recupILuIuLe LIe usuge oI LIese rouLInes Iere.
Z Dilleren|io|ion ond In|egro|ion
0illereaIiuIiea
TIe cuII diff(expressionx} compuLes LIe derIvuLIve oI LIe expressIon wILI
respecL Lo LIe unknown x:
diff(sin(x^Z} x}
2 x cos
_
x
2
_
I LIe expressIon conLuIns symboIIc cuIIs Lo IuncLIons wIose derIvuLIve Is noL
known, LIen diff reLurns ILseII symboIIcuIIy:
diff(x*f(x} x}
f(x) +x

x
f(x)
You muy compuLe IIgIer derIvuLIves vIu diff(expressionxx...}. TIe
sequence xx... oI IdenLIIIers muy be generuLed convenIenLIy vIu LIe sequence
operuLor S (SecLIon q.):
diff(sin(x^Z} x x x} = diff(sin(x^Z} x S 3}
12 x sIn
_
x
2
_
8 x
3
cos
_
x
2
_
= 12 x sIn
_
x
2
_
8 x
3
cos
_
x
2
_
You cun compuLe purLIuI derIvuLIves In LIe sume wuy. MuPAD

ussumes LIuL
mIxed purLIuI derIvuLIves oI symboIIc expressIons ure symmeLrIc:
diff(f(xy} x y} - diff(f(xy} y x}
0
I u muLIemuLIcuI mup Is represenLed by u IuncLIon InsLeud oI un expressIon, LIen
LIe dIIIerenLIuI operuLor 0 compuLes LIe derIvuLIve us u IuncLIon:
0(sin} 0(exp} 0(in} 0(sin*cos} 0(sinein} 0(f+g}
cos, exp,
1
Id
, cos
2
sIn
2
,
cos In
Id
, f

+g

f .= x -> (sin(in(x}}}. 0(f}


x
cos(In(x))
x
,-
Dilleren|io|ion
Here, id denoLes LIe IdenLILy mup x x. TIe expressIon 0(f}(x} reLurns LIe
vuIue oI LIe derIvuLIve uL u poInL:
0(f}(1} 0(f}(y^Z} 0(g}(0}
1,
cos
_
In
_
y
2
__
y
2
, g

(0)
TIe sysLem converLs LIe prIme Ior LIe derIvuLIve Lo u cuII oI 0:
f(1} f(y^Z} g(0}
1,
cos
_
In
_
y
2
__
y
2
, g

(0)
or u IuncLIon wILI more LIun one urgumenL, 0(_i]f} Is LIe purLIuI derIvuLIve
wILI respecL Lo LIe i-LI urgumenL, und 0(_ig...]f} Is equIvuIenL Lo
0(_i]0(_g]...}}, Ior IIgIer purLIuI derIvuLIves.
Ixercise ,.1: ConsIder LIe IuncLIon f : x sIn(x)/x. CompuLe IIrsL LIe vuIue oI
f uL LIe poInL x = 1.23, und LIen LIe derIvuLIve f

(x). WIy does LIe IoIIowIng


InpuL noL yIeId LIe desIred resuIL?
f .= sin(x}/x. x .= 1.Z3. diff(f x}
Ixercise ,.: De I`HospILuI`s ruIe sLuLes LIuL
IIm
xx
0
f(x)
g(x)
= IIm
xx
0
f

(x)
g

(x)
= = IIm
xx
0
f
(k1)
(x)
g
(k1)
(x)
=
f
(k)
(x
0
)
g
(k)
(x
0
)
,
II f(x
0
) = g(x
0
) = = f
(k1)
(x
0
) = g
(k1)
(x
0
) = 0 und g
(k)
(x
0
) = 0. CompuLe
IIm
x0
x
3
sIn(x)
(1 cos(x))
2
by uppIyIng LIIs ruIe InLerucLIveIy. Use LIe IuncLIon iimil Lo
cIeck your resuIL.
Ixercise ,.: DeLermIne LIe IIrsL und second order purLIuI derIvuLIves oI
f
1
(x
1
, x
2
) = sIn(x
1
x
2
) . eL x = x(t) = sIn(t), y = y(t) = cos(t), und
f
2
(x, y) = x
2
y
2
. CompuLe LIe derIvuLIve oI f
2
(x(t), y(t)) wILI respecL Lo t.
,-
Z Dilleren|io|ion ond In|egro|ion
laIegruIiea
TIe IuncLIon inl IeuLures boLI deIInILe und IndeIInILe InLegruLIon:
inl(sin(x} x} inl(sin(x} x = 0..PT/Z}
cos(x) , 1
I inl Is unubIe Lo compuLe u resuIL, IL reLurns ILseII symboIIcuIIy. n LIe IoIIowIng
exumpIe, LIe InLegrund Is spIIL InLo Lwo Lerms. OnIy one oI LIese Ius un InLegruI
LIuL cun be respresenLed by eIemenLury IuncLIons:
inl((x - 1}/(x*sqrl(x^3 + 1}} x}
_
x 1
x

x
3
+ 1
dx
TIe IuncLIon SI(x) =
_
x
0
sIn(t)/t dt Is ImpIemenLed us u specIuI IuncLIon In
MuPAD:
inl(sin(o*x}/x x}
SI(a x)
WIIIe InLegruLIng, LIe InLegruLIon vurIubIe ILseII Is ussumed Lo be reuI. OLIer LIun
LIIs, uII compuLuLIons Luke pIuce over LIe compIex numbers, und LIe sysLem
regurds every symboIIc purumeLer In LIe InLegrund us u compIex number unIess
LoId oLIerwIse. n LIe IoIIowIng exumpIe, LIe deIInILe InLegruI exIsLs onIy Ior
specIIIc runges oI LIe purumeLer a, und LIe sysLem reLurns u symboIIc iimil cuII:
inl(sin(o*x}/x x = 0..infinily}
IIm
x
SI(xa)
You cun LeII LIe sysLem LIuL un IdenLIIIer Ius cerLuIn properLIes by usIng LIe
operuLor ossuming (SecLIon q.). TIe IoIIowIng cuII sLIpuIuLes LIuL a be u posILIve
reuI number:
inl(sin(o*x}/x x = 0..infinily} ossuming o > 0

2
,-q
In|egro|ion
BesIdes LIe exucL compuLuLIon oI deIInILe InLegruIs, MuPAD uIso provIdes severuI
numerIcuI meLIods:
fiool(inl(sin(x}/x x = 0..Z}}
1.605412977
n LIe prevIous compuLuLIon, inl IIrsL reLurns u symboIIc resuIL (LIe error
IuncLIon erf), wIIcI Is LIen upproxImuLed by fiool. I you wunL Lo compuLe
numerIcuIIy Irom LIe begInnIng, LIen you cun suppress LIe symboIIc compuLuLIon
vIu inl by usIng hoid (SecLIon .z):
fiool(hoid(inl}(sin(x}/x x = 0..Z}}
1.605412977
AILernuLIveIy, LIe IuncLIon numeric..inl Irom LIe numeric IIbrury cun be used:
numeric..inl(sin(x}/x x = 0..Z}
1.605412977
TIIs IuncLIon uIIows you Lo cIoose dIIIerenL numerIcuI meLIods Ior compuLIng LIe
InLegruI. You IInd more deLuIIed InIormuLIon usIng ?numeric..inl. L works In u
pureIy numerIcuI IusIIon wILIouL uny symboIIc preprocessIng oI LIe InLegrund.
or smooLI InLegrunds wILIouL sInguIurILIes, numeric..inl Is quILe eIIIcIenL.
Ixercise ,.q: CompuLe LIe IoIIowIng InLegruIs:
_
/2
0
sIn(x) cos(x) dx,
_
1
0
dx

1 x
2
,
_
1
0
x urcLun(x) dx.
Use MuPAD Lo verIIy LIe IoIIowIng equuIILy:
_
1
2
dx
x
= In(2) .
Ixercise ,.g: Use MuPAD Lo deLermIne LIe IoIIowIng IndeIInILe InLegruIs:
_
x
t dt
_
(2 a t t
2
)
3
,
_
x
_
t
2
a
2
dt ,
_
x
dt
t

1 +t
2
.
,-g
Z Dilleren|io|ion ond In|egro|ion
Ixercise ,.6: TIe IuncLIon inliib..chongevor perIorms u cIunge oI vurIubIe In
u symboIIc InLegruI. Reud LIe correspondIng IeIp puge. MuPAD cunnoL compuLe
LIe InLegruI
_
/2
/2
sIn(x)
_
1 + sIn(x) dx.
AssIsL LIe sysLem by usIng LIe subsLILuLIon l=sin(x}. Compure LIe vuIue LIuL you
geL Lo LIe numerIcuI resuIL reLurned by LIe IuncLIon numeric..inl.
,-6
8
Solving Iqoutions: soive
TIe IuncLIon soive soIves equuLIons, InequuIILIes, sysLems oI LIese, dIIIerenLIuI
equuLIons, recurrence equuLIons eLc. TIIs rouLIne cun IundIe vurIous dIIIerenL
Lypes oI equuLIons. BesIdes uIgebruIc equuLIons, uIso cerLuIn cIusses oI
dIIIerenLIuI und recurrence equuLIons cun be soIved. urLIer, LIere Is u vurIeLy oI
specIuIIzed soIvers LIuL onIy IundIe specIuI cIusses oI equuLIons. Muny oI LIese
uIgorILIms ure ucLuuIIy cuIIed by LIe unIversuI soive once IL Ius IdenLIIIed LIe
Lype oI LIe equuLIons. TIe user cun uIso cuII LIe specIuIIzed soIvers dIrecLIy. You
cun IInd u survey oI uII uvuIIubIe MuPAD

soIvers In In LIe QuIck ReIerence In


LIe onIIne documenLuLIon.
8 5olving Equo|ions: soive
Felyaemiul quuIieas
You cun suppIy un IndIvIduuI equuLIon us IIrsL urgumenL Lo soive. TIe unknown
Ior wIIcI you wunL Lo soIve Is LIe second urgumenL:
soive(x^Z + x = y/4 x} soive(x^Z + x - y/4 = 0 y}
_

y + 1
2

1
2
,

y + 1
2

1
2
_
,
_
4 x
2
+ 4 x
_
n LIIs cuse, LIe sysLem reLurns u seL oI soIuLIons. I you specIIy un expressIon
InsLeud oI un equuLIon, LIen soive ussumes LIe equuLIon expression=0:
soive(x^Z + x - y/4 y}
_
4 x
2
+ 4 x
_
or poIynomIuIs oI IIgIer degree, IL Is provubIy ImpossIbIe Lo uIwuys IInd u cIosed
Iorm Ior LIe soIuLIons by meuns oI rudIcuIs eLc. n sucI cuses, MuPAD

uses LIe
Rool0f objecL:
soive(x^7 + x^Z + x x}
{0} RooLOI(X1
6
+X1 + 1, X1)
TIe ubove Rool0f objecL represenLs uII soIuLIons oI LIe equuLIon x^6+x+1=0.
You cun use fiool Lo upproxImuLe sucI objecLs by IIouLIng-poInL numbers. TIe
sysLem InLernuIIy empIoys u numerIcuI procedure Lo deLermIne uII (compIex) rooLs
oI LIe poIynomIuI:
fiool(x}
{0.0 - 0.1547351445 + 1.0330754 T
- 0.7906671 + 0.3005069Z03 T
0.94540Z3333 - 0.61136693 T
0.94540Z3333 + 0.61136693 T
- 0.7906671 - 0.3005069Z03 T
- 0.1547351445 - 1.0330754 T]
S-
Polynomiol Equo|ions
I you wunL Lo soIve u coIIecLIon oI equuLIons Ior possIbIy severuI unknowns,
specIIy boLI LIe equuLIons und LIe unknowns us seLs or IIsLs. n LIe IoIIowIng
exumpIe, we soIve Lwo linecr equuLIons In LIree unknowns:
deiele x y z.
equolions .= {x + y + z = 3 x + y = Z].
soiulion .= soive(equolions {x y z]}
{[x = 2 z1, y = z1, z = 1]}
I you soIve equuLIons Ior severuI vurIubIes, LIen MuPAD reLurns u seL oI soIved
equuLIons equIvuIenL Lo LIe orIgInuI sysLem oI equuLIons. You cun now reud oII
LIe soIuLIons ImmedIuLeIy: LIe unknown z Ius LIe vuIue 1, LIe unknown y muy be
urbILrury (IndIcuLed by LIe new IndeLermInuLe z1) und, Ior uny gIven vuIue oI y, we
Iuve x = 2 y. L Is possIbIe Lo geL u cIeurer IndIcuLIon oI LIe new purumeLer noL
presenL In LIe InpuL by gIvIng LIe opLIon veclorFormol Lo LIe soive commund:
soive(equolions {x y z] veclorFormol}
_
_
_
x
y
z
_
_
_
_

_
_
_
_
2 z1
z1
1
_
_
_

z1 C
_

_
However, LIIs reLurn IormuL Is more dIIIIcuIL Lo use In subsequenL communds.
TIe cuII Lo soive does noL ussIgn LIe vuIues Lo LIe unknowns; x, y, und z ure sLIII
unknowns. However, LIe Iorm oI LIe ouLpuL us u IIsL oI soIved equuLIons Is cIosen
In sucI u wuy LIuL you cun convenIenLIy use 1 (CIupLer .q) Lo subsLILuLe LIese
vuIues In oLIer objecLs. or exumpIe, you muy subsLILuLe LIe soIuLIon In LIe
orIgInuI equuLIons Lo verIIy LIe resuIL:
equolions 1 soiulion_1]
{2 = 2, 3 = 3}
You cun use ossign(soiulion_1]} Lo ussIgn LIe soIuLIon vuIues Lo LIe IdenLIIIers
x, y, und z.
S-
8 5olving Equo|ions: soive
n LIe nexL exumpIe, we soIve Lwo nonlinecr poIynomIuI equuLIons In severuI
unknowns:
equolions .= {x^Z + y = 1 x - y = Z].
soiulions .= soive(equolions {x y]}
__
x =

13
2

1
2
, y =

13
2

5
2
_
,
_
x =

13
2

1
2
, y =

13
2

5
2
__
MuPAD Iound Lwo dIsLIncL soIuLIons. AguIn, you cun use 1 Lo subsLILuLe LIe
soIuLIons In oLIer expressIons:
mop(equolions 1 soiulions_1] expond}
mop(equolions 1 soiulions_Z] expond}
{1 = 1, 2 = 2} , {1 = 1, 2 = 2}
OILen, soIuLIons ure represenLed by Rool0f expressIons:
soive({x^3 + x^Z + Z*x = y y^Z = x^3] {x y]}
+- -+ { +- -+ ]
1 x 1 { 1 0 1 ]
1 1 in { 1 1 ] union
1 y 1 { 1 0 1 ]
+- -+ { +- -+ ]
{ +- -+ 1
{ 1 3 1 1
{ 1 - z + 4 z + 4 1 1
{ 1 1 1 z in
{ 1 z 1 1
{ +- -+ 1
]
]
4 3 Z ]
Rool0f(z1 - 3 z1 - Z z1 + 5 z1 + z1} ]
]
]
S-q
Polynomiol Equo|ions
I you use LIe opLIon Mox0egree=n, LIen Rool0f expressIons Ior poIynomIuIs oI
degree up Lo n ure repIuced by represenLuLIons In Lerms oI rudIcuIs II LIIs Is
possIbIe. NoLe LIuL sucI soIuLIons Lend Lo be ruLIer compIIcuLed:
soive({x^3 + x^Z + Z*x = y y^Z = x^3] {x y]
Mox0egree = 4}
_

_
_

_
x = 7 +
_
_
_
_
_
_

129
_
3485
54
+

73 5 I
18
_1
3
4
+ 9
_
3485
54
+

73 5 I
18
_2
3
+ 145
6
_
3485
54
+

73 5 I
18
_1
6
+. . .
SpecIIyIng LIe unknowns Lo soIve Ior Is opLIonuI. or LIe specIuI cuse wIere you
Iuve one unknown, Iowever, LIe IormuL oI LIe ouLpuL depends on wIeLIer you
specIIy LIe unknown or noL. TIe generuI ruIe Is us IoIIows:
A cuII oI LIe Iorm soive(equolionunknoWn}, wIere unknoWn Is un
IdenLIIIer, reLurns u MuPAD objecL represenLIng u seL oI numbers. AII
oLIer Iorms oI soive Ior (one or severuI) poIynomIuI equuLIons,
wILIouL specIuI opLIons IIke veclorFormol, reLurn u seL oI IIsLs oI
equuLIons or un expressIon InvoIvIng Rool0f.
Here ure some exumpIes:
soive(x^Z - 3*x + Z = 0 x} soive(x^Z - 3*x + Z x}
{1, 2} , {1, 2}
soive(x^Z - 3*x + Z = 0} soive(x^Z - 3*x + Z}
{[x = 1] , [x = 2]} , {[x = 1] , [x = 2]}
soive({x^Z - 3*x + Z = 0] x}
soive({x^Z - 3*x + Z] x}
{1, 2} , {1, 2}
soive({x^Z - 3*x + y = 0 y - Z*x = 0] {x y]}
{[x = 0, y = 0] , [x = 1, y = 2]}
soive({x^Z - 3*x + y = 0 y - Z*x = 0]}
{[x = 0, y = 0] , [x = 1, y = 2]}
S-g
8 5olving Equo|ions: soive
I you do noL suppIy unknowns Lo soIve Ior, soive InLernuIIy uses LIe sysLem
IuncLIon indels Lo IInd LIe symboIIc IdenLIIIers In LIe equuLIons und regurds uII oI
LIem us unknowns:
soive({x + y^Z = 1 x^Z - y = 0]}
_
x
y
_

__
1 z
2
z
_

z RooLOI(z1
4
2 z1
2
z1 + 1, z1)
_
By deIuuIL, soive LrIes Lo IInd uII complex soIuLIons oI LIe gIven equuLIon(s). I
you wunL Lo IInd onIy LIe reuI soIuLIons oI u sIngIe equuLIon, use LIe opLIon
0omoin=0om..Reoi or ussume x Lo be reuI:
soive(x^3 + x = 0 x}
{0, I, I}
soive(x^3 + x = 0 x} ossuming x in R
{0}
OLIer ussumpLIons, sucI us x>0, xin, xinZondx>Z, eLc., ure IundIed us weII.
n some (usuuIIy exoLIc) cuses, LIe reuI soIuLIons muy IncIude unexpecLed vuIues:
soive(in(x}^4=PT^4 x} ossuming x in R
_
1, e

, e

_
WIen repIucIng LIe x In our InpuL by 1, we geL un In(1), wIIcI Is I, u compIex
vuIue. n LIe end, we geL u reuI-vuIued resuIL, buL u common requesL Is Lo IInd
soIuLIons Ior u probIem resLrIcLed Lo LIe reuIs, IncIudIng uII InLermedIuLe vuIues
(soIvIng over LIe reuIs). To muke soive LuckIe LIIs probIem, use LIe opLIon Reoi
InsLeud oI LIe ussumpLIon:
soive(in(x}^4=PT^4 x Reoi}
_
e

, e

_
OI course, usIng LIe opLIon suves u bIL oI LypIng, Loo.
S-6
Polynomiol Equo|ions
I uII compIex numbers suLIsIy u gIven equuLIon, LIen soive reLurns C, LIe seL oI
uII compIex numbers:
soive(sin(x} = cos(x - PT/Z} x}
C
domlype(x}
soIveIIb::BusIcSeL
TIere ure Iour sucI busIc seLs: LIe InLegers Z (enLered us Z In MuPAD InpuL),
LIe ruLIonuI numbers Q(), LIe reuI numbers R (R), und LIe compIex numbers C
(C).
You cun use LIe IuncLIon fiool Lo IInd numericcl soIuLIons. However, wILI u
sLuLemenL oI LIe Iorm fiool(soive(equolions unknoWns}}, soive IIrsL LrIes Lo
soIve LIe equuLIons symboIIcuIIy. I un exucL soIuLIon Is Iound, fiool converLs LIe
resuIL Lo IIouLIng-poInL upproxImuLIons. I you wunL Lo compuLe In u pureIy
numerIcuI wuy, you cun use hoid (SecLIon .z) Lo uvoId symboIIc preprocessIng:
fiool(hoid(soive}({x^3 + x^Z + Z*x = y y^Z = x^Z]
{x y]}}
{_x = - 0.5 + 1.6531Z395 T y = 0.5 - 1.6531Z395 T]
_x = - 0.5 - 1.6531Z395 T y = 0.5 + 1.6531Z395 T
] _x = - 0.5 + 0.660Z5403 T
y = - 0.5 + 0.660Z5403 T] _x = 0.0 y = 0.0]
_x = - 0.5 - 0.660Z5403 T
y = - 0.5 - 0.660Z5403 T]]
AILernuLIveIy, LIe IIbrury numeric provIdes vurIous IuncLIons Ior numerIcuI
equuLIon soIvIng sucI us numeric..soive
1
, numeric..fsoive, or
numeric..reoirools. TIe IeIp sysLem gIves deLuIIs ubouL LIese rouLInes: cuII
?soivers Ior u survey or see ?numeric..soive eLc.
1
n IucL, LIe cuIIs fiool(hoid(soive}(...}} und numeric..soive(...} ure equIvuIenL.
S-,
8 5olving Equo|ions: soive
Ixercise S.1: CompuLe LIe generuI soIuLIon oI LIe sysLem oI IIneur equuLIons
a + b + c + d + e = 1 ,
a + 2 b + 3 c + 4 d + 5 e = 2 ,
a 2 b 3 c 4 d 5 e = 2 ,
a b c d e = 3 .
How muny Iree purumeLers does LIe soIuLIon Iuve?
S-S
Generol Equo|ions ond Inequoli|ies
6eaerul quuIieas uad laequuliIies
soive cun IundIe u vurIeLy oI (non-poIynomIuI) equuLIons. or exumpIe, LIe
equuLIon exp(x) = 8 Ius InIInILeIy muny soIuLIons oI LIe Iorm In(8) + 2 I k wILI
k Z In LIe compIex pIune:
S .= soive(exp(x} = x}
{In(8) + k 2 I| k Z}
TIe duLu Lype oI LIe reLurned resuIL Is u so-cuIIed Imuge seL. L represenLs u
muLIemuLIcuI seL oI LIe Iorm {f(x) | x A}, wIere A Is some oLIer seL:
domlype(S}
Dom::mugeSeL
TIIs duLu Lype Is cupubIe oI represenLIng InIInILeIy muny eIemenLs.
I you omIL LIe vurIubIe Lo soIve Ior, LIe sysLem reLurns u IogIcuI IormuIu, usIng LIe
operuLor in:
soive(exp(x} = }
_
x
_

__
In(8) + k 2 I
_

k Z
_
You cun use mop Lo uppIy u IuncLIon Lo un Imuge seL:
mop(S pius -in(}}
{ k 2 I| k Z}
AILernuLIveIy, mosL urILImeLIcuI operuLIons cun be uppIIed dIrecLIy:
exp(S}
{8}
TIe IuncLIon is (SecLIon q.) cun IundIe Imuge seLs:
S .= soive(sin(PT*x/Z} = 0 x}
{2 k| k Z}
S-q
8 5olving Equo|ions: soive
is(1 in S} is(4 in S}
ASE, TRUE
TIe equuLIon exp(x}=sin(x} uIso Ius InIInILeIy muny soIuLIons, wIIcI, Iowever,
MuPAD

cunnoL represenL exucLIy. n LIIs cuse, IL reLurns LIe cuII Lo soive


symboIIcuIIy:
soiulions .= soive(exp(x} = sin(x} x}
soIve(e
x
sIn(x) = 0, x)
Wurning: n conLrusL Lo poIynomIuI equuLIons, LIe numerIcuI soIver compuLes uL
mosL one soIuLIon oI u non-poIynomIuI equuLIon:
fiool(soiulions}
{226.1946711}
However, you cun specIIy u seurcI runge Lo seIecL u purLIcuIur numerIcuI soIuLIon:
numeric..soive(exp(x} = sin(x} x = -10..-9}
{9.424858654}
UsIng numeric..reoirools, you cun IInd encIosures Ior cll reuI rooLs In u gIven
InLervuI:
numeric..reoirools(exp(x} = sin(x} x = -10..-5}
[[9.43359375, 9.423828125] , [6.2890625, 6.279296875]]
MuPAD Ius u specIuI duLu Lype Ior LIe soIuLIon oI purumeLrIc equuLIons:
pieceWise. or exumpIe, LIe seL oI soIuLIons x C oI LIe equuLIon
(a x
2
4) (x b) = 0 Lukes on dIIIerenL Iorms, dependIng on LIe vuIue oI LIe
purumeLer a:
deiele o. p .= soive((o*x^Z - 4}*(x - b} x}
_
{b} II a = 0
_
b,
2

a
,
2

a
_
II a = 0
domlype(p}
pIecewIse
S-1o
Generol Equo|ions ond Inequoli|ies
TIe IuncLIon mop uppIIes u IuncLIon Lo uII bruncIes oI u pieceWise objecL:
mop(p poWer Z}
_
_
b
2
_
II a = 0
_
4
a
, b
2
_
II a = 0
AILer LIe IoIIowIng subsLILuLIon, LIe pieceWise objecL Is sImpIIIIed Lo u seL:
x 1 _o = 4 b = Z]
{1, 4}
TIe IuncLIon soive cun uIso IundIe InequuIILIes. L LIen reLurns un InLervuI or u
unIon oI InLervuIs, oI domuIn Lype 0om..Tnlervoi:
soive(x^Z < 1 x}
(1, 1) {xI| x (, )}
domlype(x}
DOM_EXPR
S .= soive(x^Z >= 1 x}
[1, ) (, 1]
is(-Z in S} is(0 in S}
TRUE, ASE
S-11
8 5olving Equo|ions: soive
0illereaIiul quuIieas
TIe IuncLIon ode deIInes un ordInury dIIIerenLIuI equuLIon. SucI un objecL Ius Lwo
componenLs: un equuLIon und LIe IuncLIon Lo soIve Ior.
diffEquolion .= ode(y(x} = y(x}^Z y(x}}
ode
_

x
y(x) y(x)
2
, y(x)
_
TIe IoIIowIng cuII Lo soive IInds LIe generuI soIuLIon conLuInIng un urbILrury
consLunL C
3
:
soive(diffEquolion}
_
0,
1
C +x
_
DIIIerenLIuI equuLIons oI IIgIer order cun be IundIed us weII:
soive(ode(y(x} = y(x} y(x}}}
_
C; e
x
+
C6
e
x
_
You cun specIIy InILIuI condILIons or boundury vuIues by pussIng LIe dIIIerenLIuI
equuLIon LogeLIer wILI LIe InILIuIJboundury condILIons us u seL wIen cuIIIng ode:
diffEquolion .=
ode({y(x} = y(x} y(0} = 1 y(0} = 0] y(x}}.
MuPAD now udjusLs LIe Iree consLunLs In LIe generuI soIuLIon uccordIng Lo LIe
InILIuIJboundury condILIons:
soive(diffEquolion}
_
1
2 e
x
+
e
x
2
_
S-1
Dilleren|iol Equo|ions
You cun specIIy sysLems oI equuLIons wILI severuI IuncLIons In Iorm oI u seL:
soive(ode({y(x} = y(x} + Z*z(x} z(x} = y(x}]
{y(x} z(x}]}}
__
z(x) =
C1z e
2 x
2

C11
e
x
, y(x) =
C11
e
x
+C1z e
2 x
__
TIe IuncLIon numeric..odesoive oI LIe numeric IIbrury soIves LIe ordInury
dIIIerenLIuI equuLIon Y

(x) = f(x, Y (x)) wILI LIe InILIuI condILIon Y (x


0
) = Y
0
numerIcuIIy. You musL suppIy LIe rIgIL-Iund sIde oI LIe dIIIerenLIuI equuLIon us u
IuncLIon f(x, Y ) oI Lwo urgumenLs, wIere x Is u scuIur und Y Is u vecLor. I you
combIne LIe componenLs y und z In LIe prevIous exumpIe Lo u vecLor Y = (y, z),
you cun deIIne LIe rIgIL-Iund sIde oI LIe equuLIon
d
dx
Y =
d
dx
_
y
z
_
=
_
y + 2 z
y
_
=
_
Y[1] + Z Y[Z]
Y[1]
_
=: f(x, Y)
In LIe Iorm
f .= (x Y} -> _Y_1] + Z*Y_Z] Y_1]].
NoLe LIuL f(x, Y ) musL be u vecLor. Here, LIIs Is reuIIzed by meuns oI u IIsL
conLuInIng LIe componenLs on LIe rIgIL-Iund sIde oI LIe dIIIerenLIuI equuLIon.
TIe cuII
numeric..odesoive(0..1 f _1 1]}
[9.729448318, 5.04866388]
InLegruLes LIe sysLem oI dIIIerenLIuI equuLIons wILI LIe InILIuI vuIues
Y (0) = (y(0), z(0)) = (1, 1) over LIe InLervuI x [0, 1]; LIe InILIuI condILIons ure
specIIIed by LIe IIsL _11]. TIe numerIcuI soIver reLurns LIe numerIcuI soIuLIon
vecLor Y (1) = (y(1), z(1)) us u IIsL.
Ixercise S.: CIeck LIe numerIcuI soIuLIons y(1) = 9.729 . . . und
z(1) = 5.048 . . . oI LIe sysLem oI dIIIerenLIuI equuLIons
y

(x) = y(x) + 2 z(x) , z

(x) = y(x)
compuLed ubove by subsLILuLIng LIe InILIuI vuIues y(0) = 1, z(0) = 1 In LIe generuI
symboIIc soIuLIon, deLermInIng LIe vuIues Ior LIe Iree consLunLs, und evuIuuLIng
LIe symboIIc soIuLIon uL x = 1.
S-1
8 5olving Equo|ions: soive
Ixercise S.:
1) CompuLe LIe generuI soIuLIon y(x) oI LIe dIIIerenLIuI equuLIon y

= y
2
/x .
z) DeLermIne LIe soIuLIon y(x) Ior eucI oI LIe IoIIowIng InILIuI vuIue probIems:
a) y

y sIn(x) = 0 , y

(1) = 1,
b) 2 y

+
y
x
= 0 , y

(1) = .
) Ind LIe generuI soIuLIon oI LIe IoIIowIng sysLem oI ordInury dIIIerenLIuI
equuLIons In x(t), y(t), z(t):
x

= y z, y

= xz, z

= t z.
S-1q
kecurrence Equo|ions
keturreate quuIieas
Recurrence equuLIons ure equuLIons Ior IuncLIons dependIng on u dIscreLe
purumeLer (un Index). You cun generuLe sucI un objecL wILI LIe IuncLIon rec,
wIose urgumenLs ure un equuLIon, LIe IuncLIon Lo be deLermIned und, opLIonuIIy,
u seL oI InILIuI condILIons:
equolion .= rec(y(n + Z} = y(n + 1} + Z*y(n} y(n}}.
soive(equolion}
{(1)
n
C1 + 2
n
Cz}
TIe generuI soIuLIon conLuIns Lwo urbILrury consLunLs (C
1
, C
2
In LIIs cuse), wIIcI
ure suILubIy udjusLed wIen you specIIy InILIuI condILIons:
soive(rec(y(n + Z} = Z*y(n} + y(n + 1} y(n}
{y(0} = 1]}}
{2
n
Cq (1)
n
(Cq 1)}
soive(rec(y(n + Z} = Z*y(n} + y(n + 1} y(n}
{y(0} = 1 y(1} = 1]}}
_
(1)
n
3
+
2 2
n
3
_
Ixercise S.q: TIe IbonuccI numbers ure deIIned by LIe recurrence
F
n
= F
n1
+F
n2
wILI LIe InILIuI vuIues F
0
= 0, F
1
= 1. Use soive Lo IInd un
expIIcIL represenLuLIon Ior F
n
.
S-1g
?
Munipoluting Ixpressions
WIen evuIuuLIng objecLs, MuPAD

uuLomuLIcuIIy perIorms u vurIeLy oI


sImpIIIIcuLIons. or exumpIe, urILImeLIc operuLIons beLween InLegers ure execuLed
or exp(In(x)) Is sImpIIIIed Lo x. OLIer sImpIIIIcuLIons sucI us
sIn(x)
2
+cos(x)
2
= 1, In(exp(x)) = x, (x
2
1)/(x 1) = x + 1, or

x
2
= x do noL
Iuppen uuLomuLIcuIIy. One reuson Is LIuL muny oI LIese ruIes ure noL unIversuIIy
vuIId: Ior exumpIe,

x
2
= x Is wrong Ior x = 2. OLIer sImpIIIIcuLIons sucI us
sIn(x)
2
+cos(x)
2
= 1 ure vuIId unIversuIIy, buL LIere wouId be u sIgnIIIcunL Ioss oI
eIIIcIency II MuPAD wouId uIwuys scun expressIons Ior LIe occurrence oI sIn und
cos Lerms.
Moreover, IL Is noL cIeur In generuI wIIcI oI severuI muLIemuLIcuIIy equIvuIenL
represenLuLIons Is LIe mosL upproprIuLe. or exumpIe, IL mIgIL be reusonubIe Lo
repIuce un expressIon sucI us sIn(x) by ILs compIex exponenLIuI represenLuLIon
sIn(x) =
I
2
exp(xI) +
I
2
exp(xI).
n sucI u sILuuLIon, you cun conLroI LIe munIpuIuLIon und sImpIIIIcuLIon oI
expressIons by expIIcILIy uppIyIng upproprIuLe sysLem IuncLIons. MuPAD provIdes
LIe IoIIowIng IuncLIons, wIIcI we Iuve purLIy dIscussed In SecLIon z.q:
Nonipulo|ing Epressions

coiiecl : coIIecLIng coeIIIcIenLs


combine : combInIng subexpressIons
expond : expunsIon
foclor : IucLorIzuLIon
normoi : normuIIzuLIon oI ruLIonuI expressIons
porlfroc : purLIuI IrucLIon decomposILIon
rodsimp : sImpIIIIcuLIon oI rudIcuIs
reclform : CurLesIun represenLuLIon oI compIex vuIues
reWrile : uppIyIng muLIemuLIcuI IdenLILIes
simpiify : unIversuI sImpIIIIer
Simpiify : unIversuI sImpIIIIer
q-
Tronslorming Epressions
ruaslermiag xpressieas
I you enLer LIe commund coiiecl(expressionunknoWn}, LIe sysLem regurds
LIe expressIon us u poIynomIuI In LIe specIIIed unknown und groups LIe
coeIIIcIenLs oI equuI powers:
x^Z + o*x + sqrl(Z}*x + b*x^Z + sin(x} + o*sin(x}.
coiiecl(x x}
(b + 1) x
2
+
_
a +

2
_
x + (sIn(x) +a sIn(x))
You cun specIIy severuI unknowns, wIIcI muy LIemseIves be expressIons, us u
IIsL:
coiiecl(x _x sin(x}]}
(b + 1) x
2
+
_
a +

2
_
x + (a + 1) sIn(x)
TIe IuncLIon combine(expressionoplion} combInes subexpressIons usIng
muLIemuLIcuI IdenLILIes beLween IuncLIons IndIcuLed by oplion. TIe ImpIemenLed
opLIons ure orclon, exp, in, iog, sincos, sinhcosh, und gommo.
By deIuuIL, combine onIy empIoys LIe IdenLILIes a
b
a
c
= a
b+c
, a
c
b
c
= (a b)
c
, und
(a
b
)
c
= a
bc
Ior powers, wIere LIey ure vuIId
1
:
f .= x^(n + 1}*x^PT/x^Z. f = combine(f}
x

x
n+1
x
2
= x
+n1
f .= o^x*3^y/Z^x/9^y. f = combine(f}
3
y
a
x
2
x
9
y
=
_
1
3
_
y
_
a
2
_
x
combine(sqrl(6}*sqrl(7}*sqrl(x}}

42 x
1
An exumpIe wIere LIey ure noL Is ((1)
2
)
1/2
= 1.
q-
Nonipulo|ing Epressions
f .= (PT^(1/Z}}^x. f = combine(f}

x
=
x
2
I |xy| < 1, LIe Inverse orclon oI LIe LungenL IuncLIon suLIsIIes LIe IoIIowIng
IdenLILy:
f .= orclon(x} + orclon(y}.
f = combine(f orclon} ossuming 0 < x*y < 1
urcLun(x) + urcLun(y) = urcLun
_
x +y
xy 1
_
or LIe exponenLIuI IuncLIon, we Iuve exp(x) exp(y) = exp(x +y):
combine(exp(x}*exp(y}^Z/exp(-z} exp}
e
x+2 y+z
NoLe, Iowever, LIuL LIe IdenLILy exp(x)
y
= exp(xy) known Lo IoId Ior reuI vuIues
oI x does noL IoId LIrougIouL LIe compIex pIune. ConsequenLIy, wILIouL
uddILIonuI ussumpLIons on x, MuPAD

does noL combIne sucI Lerms:


combine(exp(x}^y exp}
(e
x
)
y
combine(exp(x}^y exp} ossuming x in R
e
x y
WILI cerLuIn ussumpLIons ubouL x und y, LIe IogurILIm suLIsIIes LIe ruIes
In(x) +In(y) = In(xy) und x In(y) = In(y
x
):
combine(in(x} + in(Z} + 3*in(3/Z} in}
In
_
27 x
4
_
q-q
Tronslorming Epressions
TIe LrIgonomeLrIc IuncLIons suLIsIy u vurIeLy oI IdenLILIes LIuL LIe sysLem empIoys
Lo combIne producLs:
combine(sin(x}*cos(y} sincos}
combine(sin(x}^Z sincos}
sIn(x y)
2
+
sIn(x +y)
2
,
1
2

cos(2 x)
2
SImIIur ruIes ure uppIIed Lo LIe IyperboIIc IuncLIons:
combine(sinh(x}*cosh(y} sinhcosh}
combine(sinh(x}^Z sinhcosh}
sInI(x y)
2
+
sInI(x +y)
2
,
cosI(2 x)
2

1
2
TIe IuncLIon expond uppIIes LIe IdenLILIes used by combine In LIe reverse
dIrecLIon: IL LrunsIorms specIuI IuncLIon cuIIs wILI composILe urgumenLs Lo sums
or producLs oI IuncLIon cuIIs wILI sImpIer urgumenLs vIu uddILIon LIeorems:
expond(x^(y + z}} expond(exp(x + y - z + 4}}
expond(in(Z*PT*x*y}}
x
y
x
z
,
e
4
e
x
e
y
e
z
, In(2) + In() +In(xy)
expond(sin(x + y}} expond(cosh(x + y}}
cos(x) sIn(y) +cos(y) sIn(x) , cosI(x) cosI(y) + sInI(x) sInI(y)
expond(sqrl(4Z*x*y}}

42

xy
Here, LIe sysLem does noL perIorm cerLuIn expunsIons sucI us
In(xy) = In(x) +In(y), sInce sucI un IdenLILy IoIds onIy under uddILIonuI
ussumpLIons (Ior exumpIe, Ior posILIve reuI x und y).
TIe mosL IrequenL use oI expond Is Ior LrunsIormIng u producL oI sums InLo u sum
oI producLs:
expond((x + y}^Z*(x - y}^Z}
x
4
2 x
2
y
2
+y
4
q-g
Nonipulo|ing Epressions
TIe IuncLIon expond works recursIveIy Ior uII subexpressIons:
expond((x - y}*(x + y}*sin(exp(x + y + z}}}
x
2
sIn(e
x
e
y
e
z
) y
2
sIn(e
x
e
y
e
z
)
You cun suppIy expressIons us uddILIonuI urgumenLs Lo expond. TIese
subexpressIons ure not expunded:
expond((x - y}*(x + y}*sin(exp(x + y + z}}
x - y x + y + z}
x sIn
_
e
x+y+z
_
(x y) +y sIn
_
e
x+y+z
_
(x y)
TIe IuncLIon foclor IucLors poIynomIuIs und expressIons:
foclor(x^3 + 3*x^Z + 3*x + 1}
(x + 1)
3
Here LIe sysLem IucLors over LIe ruLIonuI numbers: IL Iooks Ior poIynomIuI
IucLors wILI ruLIonuI number coeIIIcIenLs. n eIIecL, MuPAD does noL reLurn LIe
IucLorIzuLIon x
2
2 = (x

2) (x +

2):
foclor(x^Z - Z}
_
x
2
2
_
To exLend LIe rIng oI consLunLs over wIIcI Lo IucLor, you cun expIIcILIy udjoIn
consLunLs Lo LIe IIeId oI ruLIonuI numbers:
foclor(x^Z - Z Adgoin = sqrl(Z}}
_
x

2
_

_
x +

2
_
or sums oI ruLIonuI expressIons, foclor IIrsL compuLes u common denomInuLor
und LIen IucLors boLI LIe numeruLor und LIe denomInuLor:
f .= (x^3 + 3*y^Z}/(x^Z - y^Z} + 3. f = foclor(f}
x
3
+ 3 y
2
x
2
y
2
+ 3 =
x
2
(x + 3)
(x y) (x +y)
MuPAD cun IucLor noL onIy poIynomIuIs und ruLIonuI IuncLIons. or more generuI
expressIons, LIe sysLem InLernuIIy repIuces subexpressIons sucI us symboIIc
q-6
Tronslorming Epressions
IuncLIon cuIIs by IdenLIIIers, IucLors LIe correspondIng poIynomIuI or ruLIonuI
IuncLIon, und re-subsLILuLes LIe Lemporury IdenLIIIers:
foclor((exp(x}^Z - 1}/(cos(x}^Z - sin(x}^Z}}
_
e
2 x
1
_
(cos(x) sIn(x)) (cos(x) + sIn(x))
TIe IuncLIon normoi compuLes u normuI Iorm Ior ruLIonuI expressIons. Ike
foclor, IL IIrsL compuLes u common denomInuLor Ior sums oI ruLIonuI expressIons,
buL IL LIen expunds numeruLor und denomInuLor InsLeud oI IucLorIng LIem:
f .= ((x + 6}^Z - 17}/(x - 1}/(x + 1} + 1.
f foclor(f} normoi(f}
(x + 6)
2
17
(x 1) (x + 1)
+ 1,
2 (x + 3)
2
(x 1) (x + 1)
,
2 x
2
+ 12 x + 18
x
2
1
NeverLIeIess, normoi cunceIs common IucLors In numeruLor und denomInuLor:
f .= x^Z/(x + y} - y^Z/(x + y}. f = normoi(f}
x
2
x +y

y
2
x +y
= x y
Ike foclor, normoi cun IundIe urbILrury expressIons:
f .= (exp(x}^Z-exp(y}^Z}/(exp(x}^3 - exp(y}^3}.
f = normoi(f}
e
2 x
e
2 y
e
3 x
e
3 y
=
e
x
+e
y
e
2 x
+e
2 y
+e
x
e
y
TIe IuncLIon porlfroc decomposes u ruLIonuI expressIon InLo u poIynomIuI purL
pIus u sum oI ruLIonuI Lerms In wIIcI LIe degree oI LIe numeruLor Is smuIIer LIun
LIe degree oI LIe correspondIng denomInuLor (purLIuI IrucLIon decomposILIon):
f .= x^Z/(x^Z - 1}. f = porlfroc(f x}
x
2
x
2
1
=
1
2 (x 1)

1
2 (x + 1)
+ 1
TIe denomInuLors oI LIe Lerms ure LIe IucLors LIuL MuPAD IInds wIen IucLorIng
q-,
Nonipulo|ing Epressions
LIe common denomInuLor:
denominolor .= x^5 + x^4 - 7*x^3 - 11*x^Z - *x - 1Z.
foclor(denominolor}
(x 3)
_
x
2
+ 1
_
(x + 2)
2
porlfroc(1/denominolor x}
9 x
250

13
250
x
2
+ 1

1
25 (x + 2)

1
25 (x + 2)
2
+
1
250 (x 3)
AnoLIer IuncLIon Ior munIpuIuLIng expressIons Is reWrile. L empIoys IdenLILIes
Lo eIImInuLe cerLuIn IuncLIons compIeLeIy Irom un expressIon und repIuces LIem
by oLIer IuncLIons. or exumpIe, you cun uIwuys express sIn und cos by Lun wILI
LIe IuII urgumenL:
sIn(x) =
2 Lun(x/2)
1 + Lun(x/2)
2
, cos(x) =
1 Lun(x/2)
2
1 + Lun(x/2)
2
.
TIe LrIgonomeLrIc IuncLIons ure uIso reIuLed Lo LIe compIex exponenLIuI IuncLIon:
sIn(x) =
I
2
exp(I x) +
I
2
exp(I x) ,
cos(x) =
1
2
exp(I x) +
1
2
exp(I x) .
You cun express LIe IyperboIIc IuncLIons und LIeIr Inverse IuncLIons In Lerms oI
LIe exponenLIuI IuncLIon und LIe IogurILIm:
sInI(x) =
exp(x) exp(x)
2
, cosI(x) =
exp(x) +exp(x)
2
,
urcsInI(x) = In(x +
_
x
2
+ 1) , urccosI(x) = In(x +
_
x
2
1) .
A cuII oI LIe Iorm reWrile(expressionlorgel} empIoys LIese IdenLILIes.
TubIe q.1 IIsLs LIe ruIes ImpIemenLed In MuPAD.
reWrile(0(0(u}}(x} diff}

2
x
2
u(x)
q-S
Tronslorming Epressions

tcret : junction(s) reuritten


in terms oj
ondor : IogIcuI operuLors xor, ==>, <=> ond, or, nol
orccos : Inverse LrIg. IuncLIons orccos
orccosh : Inverse LrIg. IuncLIons, in orccosh
orccol : Inverse LrIg. IuncLIons orccol
orccolh : Inverse LrIg. IuncLIons, in orccolh
orcsin : Inverse LrIg. IuncLIons orcsin
orcsinh : Inverse LrIg. IuncLIons, in orcsinh
orclon : Inverse LrIg. IuncLIons orclon
orclonh : Inverse LrIg. IuncLIons, in orclonh
bernouiii : euier bernouiii
cos : exponenLIuI IuncLIon exp,
LrIg. und IyperboIIc IuncLIons
cos
cosh : exponenLIuI IuncLIon exp,
LrIg. und IyperboIIc IuncLIons
cosh
col : exponenLIuI IuncLIon exp,
LrIg. und IyperboIIc IuncLIons
col
colh : exponenLIuI IuncLIon exp,
LrIg. und IyperboIIc IuncLIons
colh
diff : dIIIerenLIuI operuLor 0 diff
0 : dIIIerenLIuLIng IuncLIon diff 0
exp : powers (^), LrIg. und IyperboIIc
IuncLIons und LIeIr Inverses,
poIur ungIe org, doWson
exp, in
erf : doWson erf
focl : -IuncLIon gommo,
doubIe IucLorIuI foclZ,
bInomIuI coeIIIcIenLs binomioi,
-IuncLIon belo, pochhommer
focl
gommo : IucLorIuI focl,
doubIe IucLorIuI foclZ,
bInomIuI coeIIIcIenLs binomioi,
-IuncLIon belo, pochhommer
gommo
TubIe q.1u: TurgeLs oI reWrile
q-q
Nonipulo|ing Epressions

tcret : junction(s) reuritten


in terms oj
hormonic : psi hormonic
heoviside : sign heoviside
Tm : Re Tm
in : Inverse LrIg. und Inverse IyperboIIc
IuncLIons, poIur ungIe org, iog
in
iomberln : Wrighl0mego iomberln
mox : min, obs mox
min : mox, obs min
pieceWise : sign, ubsoIuLe vuIue obs,
sLep IuncLIon heoviside,
muxImum mox, mInImum min,
kronecker0eilo
pieceWise
psi : hormonic psi
Re : Tm Re
sign : sLep IuncLIon heoviside,
ubsoIuLe vuIue obs
sign
sin : exponenLIuI IuncLIon exp,
LrIg. und IyperboIIc IuncLIons
sin
sincos : exponenLIuI IuncLIon exp,
LrIg. und IyperboIIc IuncLIons
sin, cos
sinh : exponenLIuI IuncLIon exp,
LrIg. und IyperboIIc IuncLIons
sinh
sinhcosh : exponenLIuI IuncLIon exp,
LrIg. und IyperboIIc IuncLIons
sinh, cosh
lon : exponenLIuI IuncLIon exp,
LrIg. und IyperboIIc IuncLIons
lon
lonh : exponenLIuI IuncLIon exp,
LrIg. und IyperboIIc IuncLIons
lonh
TubIe q.1b: TurgeLs oI reWrile (cont.)
q-1o
Tronslorming Epressions
reWrile(sin(x}/cos(x} exp} = reWrile(lon(x} exp}
e
x I
I
2

e
x I
I
2
e
x I
2
+
e
x I
2
=
e
x 2 I
I I
e
x 2 I
+ 1
reWrile(orcsinh(x} - orccosh(x} in}
In
_
x +
_
x
2
+ 1
_
In
_
x +
_
x
2
1
_
or expressIons represenLIng compIex numbers, you cun eusIIy compuLe reuI und
ImugInury purLs by usIng Re und Tm:
z .= Z + 3*T. Re(z} Tm(z}
2, 3
z .= sin(Z*T} - in(-1}. Re(z} Tm(z}
0, sInI(2)
WIen un expressIon conLuIns symboIIc IdenLIIIers, MuPAD ussumes uII sucI
unknowns Lo be compIex vuIues. Re und Tm ure reLurned symboIIcuIIy:
Re(o*b + T} Tm(o*b + T}
(a b) , (a b) + 1
n sucI u cuse, you cun use LIe IuncLIon reclform (sIorL Ior: recLunguIur Iorm) Lo
decompose LIe expressIon InLo reuI und ImugInury purL. TIe nume oI LIIs IuncLIon
Is derIved Irom LIe IucL LIuL IL compuLes LIe coordInuLes oI LIe usuuI recLunguIur
(CurLesIun) coordInuLe sysLem. MuPAD decomposes LIe symboIs conLuIned In LIe
expressIon InLo LIeIr reuI und ImugInury purLs und expresses LIe IInuI resuIL
uccordIngIy:
reclform(o*b + T}
(a) (b) (a) (b) +(a) (b) I +(b) (a) I +I
reclform(exp(x}}
cos((x)) e
(x)
+sIn((x)) e
(x)
I
q-11
Nonipulo|ing Epressions
AguIn, you cun exLrucL LIe reuI und ImugInury purLs oI LIe resuIL wILI Re und Tm,
respecLIveIy:
Re(x} Tm(x}
cos((x)) e
(x)
, sIn((x)) e
(x)
As u busIc prIncIpIe, reclform regurds uII symboIIc IdenLIIIers us represenLuLIves
oI compIex numbers. However, you cun use ossume (SecLIon q.) Lo specIIy LIuL un
IdenLIIIer represenLs onIy reuI numbers:
ossume(o in R}.
z .= reclform(o*b + T}
a (b) +a (b) I +I
TIe resuILs oI reclform Iuve u specIuI duLu Lype:
domlype(z}
recLIorm
You cun use LIe IuncLIon expr Lo converL sucI un objecL Lo u normuI expressIon
oI domuIn Lype 00MEXPR:
expr(z}
a (b) I +a (b) +I
q-1
5implilying Epressions
$implilyiag xpressieas
n some cuses, u LrunsIormuLIon Ieuds Lo u sImpIer expressIon:
f .= Z^x*3^x/^x/9^x. f = combine(f}
2
x
3
x
8
x
9
x
=
_
1
12
_
x
f .= x/(x + y} + y/(x + y}. f = normoi(f}
x
x +y
+
y
x +y
= 1
To LIIs end, Iowever, you musL InspecL LIe expressIon und decIde yourseII wIIcI
IuncLIon Lo use Ior sImpIIIIcuLIon. TIere ure LooIs Ior uppIyIng vurIous
sImpIIIIcuLIon uIgorILIms Lo un expressIon cutomcticcll: LIe IuncLIons simpiify
und Simpiify. TIese ure unIversuI sImpIIIIers wIIcI MuPAD

uses Lo ucIIeve u
represenLuLIon oI un expressIon LIuL Is us sImpIe us possIbIe:
f .= Z^x*3^x/^x/9^x. f = simpiify(f}
2
x
3
x
8
x
9
x
=
_
1
12
_
x
f .= (1 + (sin(x}^Z + cos(x}^Z}^Z}/sin(x}.
f = simpiify(f}
_
cos(x)
2
+sIn(x)
2
_
2
+ 1
sIn(x)
=
2
sIn(x)
f .= x/(x + y} + y/(x + y} - sin(x}^Z - cos(x}^Z.
f = simpiify(f}
x
x +y
sIn(x)
2
cos(x)
2
+
y
x +y
= 0
f .= (exp(x} - 1}/(exp(x/Z} + 1}. f = simpiify(f}
e
x
1
e
x
2
+ 1
= e
x
2
1
q-1
Nonipulo|ing Epressions
f .= sqrl(997} - (997^3}^(1/6}. f = simpiify(f}

997 991026973
1
6
= 0
NoLe LIuL simpiify operuLes In u pureIy IeurIsLIc wuy sInce LIere Is no generuI
unswer wIuL sImpIe meuns. You cun conLroI LIe sImpIIIIcuLIon process by
suppIyIng uddILIonuI urgumenLs. As In LIe cuse oI combine, you cun requesL
purLIcuIur sImpIIIIcuLIons by meuns oI opLIons. or exumpIe, you cun LeII LIe
sImpIIIIer expIIcILIy Lo sImpIIIy expressIons conLuInIng squure rooLs:
f .= sqrl(4 + Z*sqrl(3}}.
f = simpiify(f sqrl}

2
_

3 + 2 =

3 + 1
TIe possIbIe opLIons ure exp, in, iog, cos, sin, cosh, sinh, sqrl, gommo, unil,
condilion, iogic, und reiolion. nLernuIIy, simpiify LIen conIInes ILseII Lo
LIose sImpIIIIcuLIon ruIes LIuL ure vuIId Ior LIe IuncLIon gIven us opLIon. TIe
opLIons iogic und reiolion ure Ior sImpIIIyIng IogIcuI expressIons und equuLIons
und InequuIILIes, respecLIveIy (see uIso LIe correspondIng IeIp puge: ?simpiify).
nsLeud oI simpiify(expressionsqrl}, you muy uIso use LIe IuncLIon rodsimp
Lo sImpIIIy numerIcuI expressIons conLuInIng squure rooLs or oLIer rudIcuIs:
f = rodsimp(f}

2
_

3 + 2 =

3 + 1
f .= Z^(1/4}*Z + Z^(3/4} - sqrl( + 6*Z^(1/Z}}.
f = rodsimp(f}
2 2
1
4

2
_
3

2 + 4 + 2
3
4
= 0
n muny cuses, usIng simpiify wILIouL opLIons Is upproprIuLe. However, sucI u
cuII Is oILen very LIme consumIng, sInce LIe sImpIIIIcuLIon uIgorILIm Is quILe
compIex. L muy be useIuI Lo specIIy uddILIonuI opLIons Lo suve compuLIng LIme,
sInce LIen sImpIIIIcuLIons ure perIormed onIy Ior specIuI IuncLIons.
q-1q
5implilying Epressions
TIe second generuI sImpIIIIer, Simpiify (noLe LIe cupILuI S), Is oILen sIower LIun
simpiify, buL mucI more powerIuI und uIIows mucI IIner LunIng:
Simpiify(1/(x+y} + 1/(x-y}}
Simpiify(1/(x+y} + 1/(x-y} voiuolion=ienglh}
2 x
x
2
y
2
,
1
x y
+
1
x +y
f .= gommo(n + n!/gommo(n+1}}.
f simpiify(f} Simpiify(f} Simpiify(f Sleps = Z00}

_
n +
n!
(n + 1)
_
,
_
n! +n(n + 1)
(n + 1)
_
,
_
n +
n!
(n + 1)
_
, (n + 1)
Here, we Iuve used LIe opLIon Sleps Lo LeII Simpiify Iow muny eIemenLury
sLeps IL muy Lry beIore gIvIng up LIe seurcI Ior u sImpIer expressIon. n LIe end,
uImosL uII oI LIe sLeps Iuve Ied nowIere; we cun usk Simpiify Ior u IIsL oI sLeps IL
perIormed und see LIuL onIy LIree sLeps were ucLuuIIy used:
Simpiify(f Sleps = Z00 0ulpulType = "Proof"}
Tnpul Wos gommo(n + 1/gommo(n + 1}*n!}.
Lemmo. n + 1/gommo(n + 1}*n! = n + 1
Tnpul Wos n + 1/gommo(n + 1}*n!.
Appiying lhe ruie proc Simpiify..expond(o} ... end(X}`
Slrolegy. lobie`
("0efouil" = 0.}
lo n + 1/gommo(n + 1}*n! gives n + 1/n*n!/gommo(n}
Lemmo. 1/n*n!/gommo(n} = 1
Tnpul Wos 1/n*n!/gommo(n}.
Appiying lhe ruie X -> combine(X gommo}(X}
lo 1/n*n!/gommo(n} gives 1/gommo(n + 1}*n!
Lemmo. n! = gommo(n + 1}
Tnpul Wos n!.
Appiying lhe ruie X -> gommo(op(X 1} + 1}(X}
lo n! gives gommo(n + 1}
End of iemmo
subsliluling gives 1
End of iemmo
subsliluling gives n + 1
End of iemmo
subsliluling gives gommo(n + 1}
EW0 0F PR00F
q-1g
Nonipulo|ing Epressions
As LIIs (udmILLedIy dIIIIcuIL Lo reud) ouLpuL suggesLs, Simpiify works by IoIIowIng
u rule bcse. TIe documenLuLIon, uccessIbIe uL ?Simpiify (deloiis} (noLe LIe
spuce und LIe purenLIeses!), sIows exumpIes wILI uppIIcuLIon-specIIIc ruIe seLs.
As we Iuve seen ubove In LIe IIrsL exumpIe, LIe user cun uIso conLroI Simpiify`s
Ideu oI wIuL Is sImpIe. ExercIse q.q sIows un uppIIcuLIon.
Ixercise q.1: L Is possIbIe Lo rewrILe producLs oI LrIgonomeLrIc IuncLIons us
IIneur combInuLIons oI sIn und cos Lerms wIose urgumenLs ure InLegruI muILIpIes
oI LIe orIgInuI urgumenLs (ourIer expunsIon). Ind consLunLs a, b, c, d, und e sucI
LIuL
cos(x)
2
+sIn(x) cos(x)
= a +b sIn(x) +c cos(x) +d sIn(2 x) +e cos(2 x)
IoIds.
Ixercise q.: Use MuPAD Lo prove LIe IoIIowIng IdenLILIes:
1)
cos(5 x)
sIn(2 x) cos
2
(x)
= 5 sIn(x) +
cos
2
(x)
2 sIn(x)
+
5 sIn
3
(x)
2 cos
2
(x)
,
z)
sIn
2
(x) e
2 x
sIn
2
(x) + 2 sIn(x) e
x
+e
2 x
=
sIn(x) e
x
sIn(x) +e
x
,
)
sIn(2 x) 5 sIn(x) cos(x)
sIn(x) (1 +Lun
2
(x))
=
9 cos(x)
4

3 cos(3 x)
4
,
q)

_
14 + 3

3 + 2
_
5 12
_
3 2

2 =

2 + 3 .
Ixercise q.: MuPAD compuLes LIe IoIIowIng InLegruI Ior f:
f .= sqrl(sin(x} + 1}. inl(f x}
2 (sIn(x) 1)
_
sIn(x) + 1
cos(x)
q-16
5implilying Epressions
Ls derIvuLIve Is noL IILeruIIy IdenLIcuI Lo LIe InLegrund:
diff(x x}
sIn(x) 1
_
sIn(x) + 1
+ 2
_
sIn(x) + 1 +
2 sIn(x) (sIn(x) 1)
_
sIn(x) + 1
cos(x)
2
SImpIIIy LIIs expressIon.
Ixercise q.q: UsIng LIe opLIon voiuolion, we muy puss u IuncLIon Lo Simpiify
Lo deLermIne wIIcI expressIons ure sImpIe: LIe IuncLIon Is cuIIed wILI un
expressIon us ILs urgumenL und reLurns u number, IIgIer numbers Ior more
compIex expressIons.
eL us Lry Lo wrILe Lun(x) coL(x) wILIouL LIe LungenL und coLungenL IuncLIons.
TIe IIrsL, somewIuL nuIve upproucI Is Lo use u vuIuuLIon IuncLIon LIuL sImpIy
Iooks Ior LIe presence oI lon und col:
z
noTongenl .= x -> if hos(x _hoid(lon} hoid(col}]}
lhen 10
eise 1 endif.
Simpiify(lon(x} - col(x} voiuolion = noTongenl}
2 sIn(x)
2
1
sIn(x) 2 sIn
_
x
2
_
2
sIn(x)
Now, LIIs expressIon ucLuuIIy does noL conLuIn lon, buL Is IurdIy sImpIe.
mprove noTongenl sucI LIuL LIe cuII ubove reLurns u sImpIe expressIon wILIouL
lon und col. You mIgIL wunL Lo InIorm yourseII ubouL ienglh IIrsL or use
Simpiify..defouilvoiuolion InsLeud, wIIcI Is LIe IuncLIon used by Simpiify II
noLIIng Is specIIIed.
z
See CIupLer 16 Ior un expIunuLIon oI if.
q-1,
Nonipulo|ing Epressions
kssumpIieas ubeuI MuIhemuIitul FreperIies
MuPAD

perIorms LrunsIormuLIons or sImpIIIIcuLIons Ior objecLs conLuInIng


symboIIc IdenLIIIers onIy II LIe correspondIng ruIes uppIy In LIe enLIre compIex
pIune. However, some IumIIIur ruIes Ior compuLIng wILI reuI numbers ure noL
generuIIy vuIId Ior compIex numbers. or exumpIe, LIe squure rooL und LIe
IogurILIm ure bruncIes oI muILI-vuIued compIex IuncLIons, und LIe MuPAD
IuncLIons InLernuIIy muke cerLuIn ussumpLIons ubouL LIe bruncI cuLs.

In(e
x
) = x Ior reuI x
In(x
n
) = n In(x) Ior reuI x > 0
In(xy) = In(x) +In(y) Ior reuI x > 0 or reuI y > 0

x
2
= |x| Ior reuI x
e
x/2
= (e
x
)
1/2
Ior reuI x
You cun use LIe IuncLIon ossume Lo LeII LIe sysLem IuncLIons sucI us expond,
simpiify, iimil, soive, und inl LIuL LIey muy muke cerLuIn ussumpLIons ubouL
LIe meunIng oI cerLuIn expressIons. We onIy demonsLruLe some sImpIe exumpIes
Iere. You IInd more InIormuLIon on LIe correspondIng IeIp puge: ?ossume.
You cun use un expressIon sucI us un InequuIILy or conLuInmenL In u seL, IncIudIng
LIe busIc seLs oI LIe soIver (cI. puge 8-;) Lo LeII MuPAD LIuL u symboIIc IdenLIIIer
or expressIon represenLs onIy vuIues correspondIng Lo LIe muLIemuLIcuI meunIng
oI LIe Lype. or exumpIe, LIe communds
ossume(x in R}. ossume(y in R}. ossume(n in Z}.
resLrIcL x und y Lo be reuI numbers und n Lo be un InLeger. Now simpiify cun
uppIy uddILIonuI ruIes:
simpiify(in(exp(x}}} simpiify(sqrl(x^Z}}
x, xsIgn(x)
TIe commund
ossume(x > 0}.
q-1S
Assump|ions obou| No|hemo|icol Proper|ies
resLrIcLs x Lo posILIve reuI numbers. AILer LIIs ussumpLIon, one obLuIns:
simpiify(in(x^n}} simpiify(in(x*y} - in(x} - in(y}}
simpiify(sqrl(x^Z}}
n In(x) , 0, x
TrunsIormuLIons und sImpIIIIcuLIons wILI consLunLs ure execuLed wILIouL
uddILIonuI ussumpLIons sInce LIeIr muLIemuLIcuI meunIng Is known:
expond(in(Z*PT*z}} sqrl((Z*PT*z}^Z}
In(2) +In() +In(z) , 2

z
2
TIe urILImeLIc operuLors Luke InLo uccounL cerLuIn muLIemuLIcuI properLIes
uuLomuLIcuIIy:
(o*b}^m
(a b)
m
ossume(m in Z}. (o*b}^m
a
m
b
m
TIe IuncLIon is cIecks wIeLIer u MuPAD expressIon Is known Lo be Lrue:
is(1 in Z} is(PT + 1 in R}
TRUE, TRUE
n uddILIon, is Lukes InLo uccounL LIe muLIemuLIcuI properLIes seL by ossume:
deiele x. is(x in Z}
UNKNOWN
ossume(x in Z}.
is(x in Z} is(x in R}
TRUE, TRUE
Here, LIe BooIeun vuIue uWKW0nW expresses LIe IucL LIuL LIe sysLem cunnoL decIde
wIeLIer x represenLs un InLeger or noL.
q-1q
Nonipulo|ing Epressions
n conLrusL Lo is, LIe IuncLIon lesllype presenLed In SecLIon 1q.1 cIecks LIe
techniccl Lype oI u MuPAD objecL:
lesllype(x Type..Tnleger} lesllype(x 00MT0EWT}
ASE, TRUE
QuerIes oI LIe IoIIowIng Iorm ure uIso possIbIe:
ossume(y > 5}. is(y + 1 > 4}
TRUE
To seL un ussumpLIon onIy LemporurIIy durIng u sIngIe commund, use LIe
ossuming operuLor:
iimil(exp(o*x} x=infinily}
iimil(exp(o*x} x=infinily} ossuming o < 0
_

_
1 II a = 0
0 II (a) < 0
II 0 < (a) 0 < sIgn((a)) + sIgn((a)) I
IIm
x
e
a x
II (a) = 0 a = 0 0 < (a) . . .
0
TIe IuncLIon gelprop reLurns u muLIemuLIcuI properLy oI un IdenLIIIer or un
expressIon, I.e., u seL sucI LIuL x geLprop(x):
gelprop(y} gelprop(y^Z + 1}
(5, ), (26, )
You cun deIeLe LIe properLIes oI un IdenLIIIer usIng unossume or LIe keyword
deiele:
deiele y. is(y > 5}
UNKNOWN
q-o
Assump|ions obou| No|hemo|icol Proper|ies
I none oI LIe sub-expressIons In un expressIon Ius uny properLIes uLLucIed Lo IL,
LIen gelprop muy reLurn LIe seL oI compIex numbers:
gelprop(y} gelprop(y^Z + 1} gelprop(obs(y}}
C, C, [0, )
gelprop(3} gelprop(sqrl(Z} + 1}
{3} ,
_

2 + 1
_
AssumIng some properLy deIeLes uII prevIous ussumpLIons usIng LIe sume
IdenLIIIers:
ossume(sin(x} > y}.
gelprop(y}
(, sIn(x))
ossume(obs(x} > 1}.
gelprop(y}
C
To muke un ussumpLIon In uddILIon Lo exIsLIng ussumpLIons, use ossumeAiso
InsLeud oI ossume, und ossumingAiso InsLeud oI ossuming:
ossume(sin(x} > y}.
gelprop(y}
(, sIn(x))
ossumeAiso(obs(x} > 1}.
gelprop(y}
(, sIn(x))
q-1
Nonipulo|ing Epressions
We now IIIusLruLe some oI LIe vurIous Lypes oI properLIes wILI u sIorL exumpIe.
TIe equuLIon (x
a
)
b
= x
ab
Is noL generuIIy vuIId, us LIe exumpIe x = 1, a = 2, und
b = 1/2 sIows. However, IL Is vuIId II b Is un InLeger:
ossume(b in Z}. (x^o}^b
x
a b
unossume(b}. (x^o}^b
(x
a
)
b
TIe IuncLIon iinoig..isPos0ef cIecks wIeLIer u muLrIx Is posILIve deIInILe. or
u muLrIx wILI symboIIc enLrIes, IL muy noL be possIbIe Lo decIde LIIs correcLIy:
A .= molrix(__1/o 1] _1 1/o]]}
_
1
a
1
1
1
a
_
iinoig..isPos0ef(A}
Error. connol check Whelher molrix componenl is posilive
_iinoig..foclorChoiesky]
WILI LIe uddILIonuI ussumpLIon LIuL LIe purumeLer o be posILIve und Iess LIun 1,
MuPAD cun decIde LIuL LIe muLrIx Is posILIve deIInILe:
ossume(o Type..Tnlervoi(0 1}}
iinoig..isPos0ef(A}
TRUE
ProperLIes oI LIIs Lype cun be specIIIed In LIe IoIIowIng more InLuILIve wuy us weII:
ossume(0 < o < 1}
TIe IuncLIon simpiify reucLs Lo properLIes:
ossume(k Type..Residue(34}}
sin(k*PT/Z}
sIn
_
k
2
_
q-
Assump|ions obou| No|hemo|icol Proper|ies
simpiify(x}
1
TIe properLy ubove cun uIso be specIIIed In uny oI LIe IoIIowIng equIvuIenL Iorms:
ossume(k in 4*Z + 3}
ossume((k - 3}/4 in Z}
TIe IuncLIons Re, Tm, sign, und obs Luke properLIes InLo uccounL:
ossume(x > 1}.
Re(x*(x - 1}} sign(x*(x - 1}} obs(x*(x - 1}}
x (x 1) , 1, x (x 1)
SInce onIy u IImILed number oI muLIemuLIcuI properLIes und derIvuLIon ruIes ure
ImpIemenLed In MuPAD, LIe sysLem perIorms some sImpIIIIcuLIons wIen
evuIuuLIng LIe properLIes oI u nonLrIvIuI expressIon. TIus LIe unswer oI gelprop
or is Is someLImes noL us cIose us possIbIe. or exumpIe, II x Is u reuI number,
LIen x
2
x 1/4, buL gelprop yIeIds LIe IoIIowIng Iess uccuruLe unswer:
ossume(x Type..Reoi}. gelprop(x^Z - x}
R
Ixercise q.g: Use MuPAD Lo sIow:
IIm
x
EI(ax) =
_
Ior a > 0 ,
0 Ior a < 0 .
HInL: Use LIe IuncLIon ossume Lo dIsLInguIsI LIe cuses. TIe exponenLIuI InLegruI
EI(x) =
_
x

e
t
t
dt Is uvuIIubIe us Ei.
q-
T0
Chunce und Probubility
You cun use MuPAD

`s rundom number generuLors rondom, frondom und


slols..xxxRondom Lo perIorm muny experImenLs.
TIe cuII rondom(} generuLes u rundom nonneguLIve 12 dIgIL InLeger. You obLuIn u
sequence oI 4 sucI rundom numbers us IoIIows:
rondom(} rondom(} rondom(} rondom(}
427419669081, 321110693270, 343633073697, 474256143563
I you wunL Lo generuLe rundom InLegers In u dIIIerenL runge, you cun consLrucL u
rundom number generuLor generolor.=rondom(m..n}. You cuII LIIs generuLor
wILIouL urgumenLs,
1
und IL reLurns InLegers beLween m und n. TIe cuII rondom(n}
Is equIvuIenL Lo rondom(0..n-1}. TIus you cun sImuIuLe 15 roIIs oI u dIe us
IoIIows:
die .= rondom(1..6}.
dieExperimenl .= _die(} S i = 1..15]
[5, 3, 6, 3, 2, 2, 2, 4, 4, 3, 3, 2, 1, 4, 4]
We sLress LIuL you musL specIIy u Ioop vurIubIe wIen usIng LIe sequence generuLor
S, sInce oLIerwIse die(} Is cuIIed onIy once und u sequence oI copIes oI LIIs vuIue
Is generuLed:
die(} S 15
6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6
1
n IucL, you cun cuII generolor wILI urbILrury urgumenLs, wIIcI ure Ignored wIen generuLIng run-
dom numbers.
T0 Chonce ond Probobili|y
Here Is u sImuIuLIon oI 8 coIn Losses:
coin .= rondom(Z}.
coinTosses .= _coin(} S i = 1..]
[0, 0, 0, 1, 1, 1, 0, 0]
subs(coinTosses _0 = heod 1 = loii]}
[Ieud, Ieud, Ieud, LuII, LuII, LuII, Ieud, Ieud]
TIe IoIIowIng exumpIe generuLes unIIormIy dIsLrIbuLed IIouLIng-poInL numbers
Irom LIe InLervuI [0, 1]. L uses LIe rundom generuLor frondom:
rondomWumbers .= _frondom(} S i = 1..10]
_0.Z70351656 0.31037177 0.153156516
0.9941Z70 0.Z66Z7Z90Z1 0.10164ZZ77
0.45Z03055 0.67719563 0.354949Z61
0.61513Z]
TIe IIbrury slols comprIses IuncLIons Ior sLuLIsLIcuI unuIysIs. You obLuIn
InIormuLIon by enLerIng info(slols} or ?slols. or exumpIe, LIe IuncLIon
slols..meon compuLes LIe meun vuIue X =
1
n

n
i=1
x
i
oI u IIsL oI numbers
[x
1
, . . . , x
n
]:
slols..meon(dieExperimenl}
slols..meon(coinTosses}
slols..meon(rondomWumbers}
16
5
,
3
8
, 0.4863510522
TIe IuncLIon slols..vorionce reLurns LIe vurIunce
V ar =
1
n 1
n

i=1
(x
i
X)
2
:
1o-
Chonce ond Probobili|y
slols..vorionce(dieExperimenl}
slols..vorionce(coinTosses}
slols..vorionce(rondomWumbers}
61
35
,
15
56
, 0.08565360412
You cun compuLe LIe sLundurd devIuLIon

V ar wILI slols..sldev:
slols..sldev(dieExperimenl}
slols..sldev(coinTosses}
slols..sldev(rondomWumbers}

35

61
35
,

14

15
28
, 0.29266637
I you specIIy LIe opLIon Popuiolion, LIe sysLem reLurns
_
n1
n
V ar InsLeud:
slols..sldev(dieExperimenl Popuiolion}
slols..sldev(coinTosses Popuiolion}
slols..sldev(rondomWumbers Popuiolion}

122
15
,

15
8
, 0.2776476971
TIe duLu sLrucLure 0om..Muilisel (see ?0om..Muilisel) provIdes u sImpIe meuns
oI deLermInIng IrequencIes In sequences. TIe cuII 0om..Muilisel(ob...}
reLurns u muILIseL, wIIcI Is prInLed us u seL oI IIsLs. TIe IIrsL enLry oI eucI sucI IIsL
Is one oI LIe urgumenLs; LIe second enLry counLs LIe number oI occurrences In LIe
urgumenL sequence:
0om..Muilisel(o b o c b b o o c d e d}
{[a, 4] , [b, 3] , [c, 2] , [d, 2] , [e, 1]}
I you sImuIuLe 1000 roIIs oI u dIe, you mIgIL obLuIn LIe IoIIowIng IrequencIes:
roiis .= die(} S i = 1..1000.
0om..Muilisel(roiis}
{[1, 158] , [2, 152] , [3, 164] , [4, 188] , [5, 176] , [6, 162]}
n LIIs cuse, you wouId Iuve roIIed 158 LImes u 1, 152 LImes u 2 eLc.
1o-
T0 Chonce ond Probobili|y
An exumpIe Irom number LIeory Is LIe dIsLrIbuLIon oI LIe greuLesL common
dIvIsors (gcd) oI rundom puIrs oI InLegers. We use LIe IuncLIon zip (SecLIon q.6)
Lo combIne Lwo rundom IIsLs vIu LIe IuncLIon igcd, wIIcI compuLes LIe gcd oI
InLegers:
iisl1 .= _rondom(} S i=1..1000].
iislZ .= _rondom(} S i=1..1000].
gcdiisl .= zip(iisl1 iislZ igcd}
_1 7 1 1 1 5 1 3 1 1 1 3 6 1 3 5 ...]
Now, we use 0om..Muilisel Lo counL LIe IrequencIes oI LIe IndIvIduuI gcds:
frequencies .= 0om..Muilisel(op(gcdiisl}}
{_11 5] _13 3] _14 Z] ... _377 1] _1 596]]
TIe resuIL becomes mucI more reudubIe II we sorL IL by LIe IIrsL enLry oI LIe
subIIsLs. We empIoy LIe IuncLIon sorl wIIcI Lukes u IuncLIon represenLIng u
sorLIng order us second urgumenL. TIIs IuncLIon decIdes wIIcI oI Lwo eIemenLs
x, y sIuII precede LIe oLIer. We reIer Lo LIe correspondIng IeIp puge: ?sorl. n
LIIs cuse, x, y ure IIsLs wILI Lwo enLrIes, und we wunL x Lo uppeur beIore y II we
Iuve x[1] < y[1] (I.e., we sorL numerIcuIIy wILI respecL Lo LIe IIrsL enLrIes):
sorling0rder .= (x y} -> (x_1] < y_1]}.
sorl(_op(frequencies}] sorling0rder}
__1 596] _Z 14Z] _3 4] ... _Z1Z 1] _377 1]]
n LIIs experImenL, 596 ouL oI LIe 1000 cIosen rundom puIrs Iuve u gcd oI 1 und
Ience ure coprIme. TIus, we Iound 59.6% us un upproxImuLIon oI LIe probubIIILy
LIuL Lwo rundomIy cIosen InLegers ure coprIme. TIe LIeoreLIcuI vuIue oI LIIs
probubIIILy Is 6/
2
0.6079.. =60.79%.
TIe slols IIbrury provIdes muny sLocIusLIc dIsLrIbuLIon IuncLIons. EucI sucI
dIsLrIbuLIon xxx, suy, consIsLs oI Iour IuncLIons: u cumuIuLIve dIsLrIbuLIon
IuncLIon xxxC0F, u probubIIILy densILy IuncLIon xxxP0F (or u dIscreLe probubIIILy
IuncLIon xxxPF, respecLIveIy), u quunLIIe IuncLIon xxxuonliie, und u rundom
number generuLor xxxRondom. or exumpIe, LIe IoIIowIng commund creuLes u IIsL
oI rundom numbers dIsLrIbuLed uccordIng Lo LIe sLundurd normuI dIsLrIbuLIon
wILI meun 0 und vurIunce 1:
1o-q
Chonce ond Probobili|y
rondomCenerolor .= slols..normoiRondom(0 1}.
dolo .= _rondomCenerolor(} S i = 1..1000].
TIe slols IIbrury IncIudes un ImpIemenLuLIon oI LIe cIussIcuI
2
-LesL. We use IL
Iere Lo LesL wIeLIer LIe rundom duLu generuLed ubove do Indeed suLIsIy u normuI
dIsLrIbuLIon. PreLendIng LIuL we do noL know LIe meun und LIe vurIunce oI LIe
duLu, we compuLe sLuLIsLIcuI esLImuLes oI LIese purumeLers:
m .= slols..meon(dolo}
0.03440235553
v .= slols..vorionce(dolo}
0.9962289589
TIe
2
-LesL requIres Lo specIIy u ceII purLILIonIng oI LIe reuI IIne Lo compure LIe
observed IrequencIes oI LIe duLu IuIIIng InLo LIe ceIIs wILI LIe expecLed
IrequencIes gIven u IypoLIesIzed dIsLrIbuLIon oI LIe duLu. TIe IuncLIon
slols..equiprobobieCeiis Is u convenIenL uLIIILy IuncLIon Lo compuLe u ceII
purLILIonIng consIsLIng oI ceIIs LIuL ure equIprobubIe wILI respecL Lo u gIven
dIsLrIbuLIon. TIe IoIIowIng cuII purLILIons LIe reuI IIne InLo 32 ceIIs wIIcI ure
equIprobubIe wILI respecL Lo LIe normuI dIsLrIbuLIon wILI LIe empIrIcuI meun und
vurIunce compuLed ubove:
ceiis .= slols..equiprobobieCeiis(3Z
slols..normoiuonliie(m v}}
__-infinily -1.909653] _-1.909653 -1.5531136]
... _1.939Z30531 infinily]]
TIe
2
-goodness-oI-IIL LesL Is ImpIemenLed by slols..csC0FT. We use IL Lo LesL
Iow good LIe rundom duLu IIL u normuI dIsLrIbuLIon wILI meun und vurIunce gIven
by LIe empIrIcuI vuIues m und v:
slols..csC0FT(dolo ceiis
C0F = slols..normoiC0F(m v}}
_Pvoiue = 0.36Z347505 Slolvoiue = 3Z.64
MinimoiExpecledCeiiFrequency = 31.Z5]
TIe IIrsL vuIue reLurned by slols..csC0FT Is LIe sIgnIIIcunce IeveI uLLuIned by LIe
duLu. SInce LIIs vuIue Is noL smuII, LIe gIven duLu puss LIe LesL weII.
1o-g
T0 Chonce ond Probobili|y
InuIIy, we doLe LIe duLu by uddIng 35 zeroes:
dolo .= oppend(dolo 0 S 35}.
We cIeck wIeLIer LIe new duLu sLIII muy be regurded us u normuIIy dIsLrIbuLed
sumpIe:
m .= slols..meon(dolo}. v .= slols..vorionce(dolo}.
ceiis .= slols..equiprobobieCeiis(3Z
slols..normoiuonliie(m v}}.
slols..csC0FT(dolo ceiis
C0F = slols..normoiC0F(m v}}
_Pvoiue = 0.000004764116336 Slolvoiue = 7.7Z607
MinimoiExpecledCeiiFrequency = 3Z.34375]
Now, LIe uLLuIned sIgnIIIcunce IeveI 0.0010... IndIcuLes LIuL LIe IypoLIesIs oI u
normuI dIsLrIbuLIon oI LIe duLu musL be rejecLed uL sIgnIIIcunce IeveIs us Iow us
0.001.
See LIe IeIp puge oI slols..csC0FT Ior IurLIer deLuIIs.
Ixercise 1o.1: TIree dIce ure LIrown sImuILuneousIy. or eucI vuIue beLween 3
und 18, LIe IoIIowIng LubIe conLuIns LIe expecLed IrequencIes oI LIe LoLuI dIce
score wIen roIIIng LIe dIce 216 LImes:
score
q 6 ; 8 q 1o 11 1z 1 1q 1 16 1; 18
1 6 1o 1 z1 z z; z; z z1 1 1o 6 1
Irequency
SImuIuLe 216 roIIs und compure LIe IrequencIes LIuL you observe wILI LIose Irom
LIe LubIe.
Ixercise 1o.: TIe MonLe-CurIo meLIod Ior upproxImuLIng LIe ureu oI u regIon
A R
2
works us IoIIows. IrsL, we cIoose u (preIerubIy smuII) recLungIe Q
encIosIng A. TIen we rundomIy cIoose n poInLs In Q. I m oI LIese poInLs IIe In A,
LIe IoIIowIng esLImuLe IoIds Ior suIIIcIenLIy Iurge n:
ureu oI A
m
n
ureu oI Q.
1o-6
Chonce ond Probobili|y
eL r(} be u cuII Lo u generuLor r oI unIIormIy dIsLrIbuLed rundom numbers In LIe
InLervuI [0, 1]. We cun use r Lo generuLe unIIormIy dIsLrIbuLed rundom vecLors In
LIe recLungIe Q = [0, a] [0, b] vIu _o*r(}b*r(}].
u) ConsIder LIe rIgIL upper quudrunL oI LIe unIL cIrcIe uround LIe orIgIn. Use
MonLe-CurIo sImuIuLIon wILI Q = [0, 1] [0, 1] Lo upproxImuLe ILs ureu. TIIs
wuy, one geLs sLocIusLIc upproxImuLIons oI .
b) eL f : x x sIn(x) +cos(x) exp(x). DeLermIne un upproxImuLIon Ior
_
1
0
f(x) dx. or LIuL purpose, IInd un upper bound M Ior f on LIe InLervuI
[0, 1] und uppIy LIe sImuIuLIon Lo Q = [0, 1] [0, M]. Compure your resuIL Lo
LIe exucL InLegruI.
1o-,
TT
Gruphics
laIredutIiea
SInce expIorIng muLIemuLIcuI objecLs Is probubIy one oI LIe mosL ImporLunL uses
oI compuLer uIgebru sysLems, grupIIcs ure u ruLIer cenLruI purL oI modern CAS.
TIe MuPAD

sysLem uIIows Lo eusIIy creuLe Lwo- und LIree-dImensIonuI grupIIcs


und unImuLIons wILI IIgI quuIILy ouLpuL und udvunced InLerucLIve munIpuIuLIon
cupubIIILIes.
To uId LIe user In IIne-LunIng u pIoL, un objecL browser Is provIded. L uIIows Lo
InspecL und unuIyze LIe Lree sLrucLure oI grupIIcuI scenes InLerucLIveIy, gIvIng eusy
uccess Lo uII purLs oI LIe pIoL by u mouse-cIIck. AILer seIecLIng un objecL, uII pIoL
uLLrIbuLes sucI us coIor, IIne wIdLI, unnoLuLIons eLc. ussocIuLed wILI LIe objecL
become vIsIbIe. One muy seIecL LIe uLLrIbuLes wILI LIe mouse und cIunge LIeIr
vuIues InLerucLIveIy (see puge 11-o). TIus, uImosL uny deLuII oI u pIoL generuLed
by u MuPAD cuII cun be cIunged InLerucLIveIy mukIng IL possIbIe Lo IIne-Lune boLI
LIe conLenLs us weII us LIe Iooks by vIsuuI InspecLIon.
TIe IeuLures oI LIe renderer ure IuIIy supporLed by LIe piol IIbrury. L provIdes u
IIsL oI grupIIcuI prImILIves sucI us poInLs, IInes, poIygons eLc. LIuL one muy use Lo
buIId up IIgIIy compIex grupIIcuI scenes. TIe prImILIves uIso IncIude grupIIcuI
objecLs LIuL ure noL uL uII prImILIve, buL come uIong wILI udvunced uIgorILIms
und mucI buIIL-In InLeIIIgence. ExumpIes ure IuncLIon grupIs In zD und D (wILI
uuLomuLIc cIIppIng Ior sInguIur IuncLIons), ImpIIcIL pIoLs In zD und D, vecLor IIeId
pIoLs, grupIIcuI soIuLIons oI ordInury dIIIerenLIuI equuLIons In zD und D eLc.
TIIs cIupLer gIves un InLroducLIon Lo LIe new grupIIcs sysLem. L expIuIns LIe
busIc concepLs und Ideus und provIdes muny exumpIes.
TT Grophics
usy FleIIiag: 6ruphs el luatIieas
ProbubIy LIe mosL ImporLunL grupIIcuI Lusk In u muLIemuLIcuI conLexL Is Lo
vIsuuIIze IuncLIon grupIs, I.e., Lo pIoL IuncLIons. TIe piol commund uIIows Lo
creuLe zD pIoLs oI IuncLIons wILI one urgumenL (sucI us f(x) = sIn(x)) or D pIoLs
oI IuncLIons wILI Lwo urgumenLs (sucI us f(x, y) = sIn(x
2
+y
2
)). TIe cuIIIng
synLux Is sImpIe: jusL puss LIe expressIon LIuL deIInes LIe IuncLIon und,
opLIonuIIy, u runge Ior LIe IndependenL vurIubIe(s). To dIsLInguIsI D pIoLs Irom
zD unImuLIons, udd #30 Lo LIe cuII.
Ionction Gruphs
We consIder zD exumpIes, I.e., pIoLs oI unIvurIuLe IuncLIons f(x). Here Is one
perIod oI LIe sIne IuncLIon:
piol(sin(x} x = 0..Z*PT}
I severuI IuncLIons ure Lo be pIoLLed In LIe sume grupIIcuI scene, jusL puss u
sequence oI IuncLIon expressIons. AII IuncLIons ure pIoLLed over LIe specIIIed
common runge:
11-
Eosy Plo||ing: Grophs ol Func|ions
piol(sin(x}/x x*cos(x} lon(x} x = -4..4}
To geL u Iegend expIuInIng LIe muppIng Irom coIor Lo IuncLIon, udd LIe opLIon
Legendvisibie:
piol(sin(x}/x x*cos(x} lon(x} x = -4..4 Legendvisibie}
11-
TT Grophics
uncLIons LIuL do noL uIIow u sImpIe symboIIc represenLuLIon by un expressIon
cun uIso be deIIned by u procedure LIuL produces u numerIcuI vuIue f(x) wIen
cuIIed wILI u numerIcuI vuIue x Irom LIe pIoL runge. n LIe IoIIowIng exumpIe we
consIder LIe IurgesL eIgenvuIue oI u symmeLrIc 3 3 muLrIx LIuL conLuIns u
purumeLer x. We pIoL LIIs eIgenvuIue us u IuncLIon oI x:
f .= x -> mox(numeric..eigenvoiues(
molrix(__-x x -x ]
_ x x x ]
_-x x x^Z]]}}}.
piol(f x = -1..1}
TIe nume x used In LIe specIIIcuLIon oI LIe pIoLLIng runge provIdes LIe nume LIuL
IubeIs LIe IorIzonLuI uxIs.
11-q
Eosy Plo||ing: Grophs ol Func|ions
uncLIons cun uIso be deIIned by pieceWise objecLs:
piol(pieceWise(_x < 1 1 - x]
_1 < x ond x < Z 1/Z]
_x > Z Z - x]}
x = -Z..3}
NoLe LIuL LIere ure gups In LIe deIInILIon oI LIe IuncLIon ubove: no IuncLIon vuIue
Is specIIIed Ior x = 1 und x = 2. TIIs does noL cuuse uny probIem, becuuse piol
sImpIy Ignores uII poInLs LIuL do noL produce reuI numerIcuI vuIues. TIus, In LIe
IoIIowIng exumpIe, LIe pIoL Is uuLomuLIcuIIy resLrIcLed Lo LIe regIons wIere LIe
IuncLIons produce reuI vuIues:
11-g
TT Grophics
piol(sqrl( - x^4} in(x^3 + Z}/(x - 1} x = -Z ..Z}
11-6
Eosy Plo||ing: Grophs ol Func|ions
WIen severuI IuncLIons ure pIoLLed In LIe sume scene, LIey ure druwn In dIIIerenL
coIors LIuL ure cIosen uuLomuLIcuIIy. WILI LIe Coiors uLLrIbuLe one muy specIIy u
IIsL oI RGB coIors LIuL piol sIuII use:
piol(x x^Z x^3 x^4 x^5 x = 0..1
Coiors = _RCB..Red RCB..0ronge RCB..YeiioW
RCB..BiueLighl RCB..Biue]
Legendvisibie}
11-,
TT Grophics
AnImuLed zD pIoLs oI IuncLIons ure creuLed by pussIng IuncLIon expressIons
dependIng on u vurIubIe (x, suy) und un unImuLIon purumeLer (a, suy) und
specIIyIng u runge boLI Ior x und a. n LIIs LexL, unImuLIons ure represenLed by u
IIIm sLrIp:
piol(cos(o*x} x = 0..Z*PT o = 1..Z}
11-S
Eosy Plo||ing: Grophs ol Func|ions
Once LIe pIoL Is creuLed, LIe IIrsL Irume oI LIe pIcLure uppeurs us u sLuLIc pIoL.
AILer doubIe-cIIckIng on LIe pIcLure, LIe grupIIcs LooI uIIows Lo sLurL LIe
unImuLIon by pusIIng LIe SLurL buLLon:
11-q
TT Grophics
An unImuLIon consIsLs oI sepuruLe Irumes, I.e., IndIvIduuI sLIII Imuges. TIe deIuuIL
number oI Irumes Is 50. I u dIIIerenL vuIue Is desIred, jusL puss LIe uLLrIbuLe
Fromes=n, wIere n Is LIe number oI Irumes LIuL sIuII be creuLed:
piol(sin(o*x} sin(x - o} x = 0..PT o = 0..4*PT
Fromes = Z00 Coiors = _RCB..Biue RCB..Red]}
ApurL Irom LIe coIor specIIIcuLIon or LIe Fromes number, LIere Is u Iurge number
oI IurLIer uLLrIbuLes LIuL muy be pussed Lo piol. EucI uLLrIbuLe Is pussed us un
equuLIon AllribuleWome=Allribulevoiue. Here, we onIy presenL some seIecLed
uLLrIbuLes. SecLIon ALLrIbuLes Ior piolfuncZd und piolfunc3d oI LIe onIIne piol
documenLuLIon provIdes IurLIer LubIes wILI more uLLrIbuLes.

uLLrIbuLe nume possIbIe vuIues meunIng deIuuIL


|eighl *unil..cm pIysIcuI IeIgIL
oI LIe pIcLure
0*unil..mm
nidlh 1Z*unil..cm pIysIcuI wIdLI
oI LIe pIcLure
1Z0*unil..mm
Fooler sLrIng IooLer LexL "" (no IooLer)
|eoder sLrIng Ieuder LexL "" (no Ieuder)
Tilie sLrIng LILIe LexL "" (no LILIe)
TiliePosilion _reuI vuIue,
reuI vuIue]
coordInuLes oI LIe
Iower IeIL corner oI
LIe LILIe
TubIe 11.1: Some ImporLunL uLLrIbuLes Ior pIoLLIng zD IuncLIons
11-1o
Eosy Plo||ing: Grophs ol Func|ions

uLLrIbuLe nume possIbIe vuIues meunIng deIuuIL


Cridvisibie TRuE, FALSE vIsIbIIILy oI mujor
grId IInes
FALSE
Subgridvisibie TRuE, FALSE vIsIbIIILy oI mInor
grId IInes
FALSE
AdopliveMesh InLeger 0 depLI oI LIe udupLIve
mesI
Z
Axes Wone, Aulomolic,
Boxed, Frome, 0rigin
uxes Lype Aulomolic
Axesvisibie TRuE, FALSE vIsIbIIILy
oI uII uxes
TRuE
AxesTilies _slring slring] LILIes oI LIe uxes _"x""y"]
CoordinoleType LinLin, LinLog,
LogLin, LogLog
IIneur-IIneur,
IIneur-IogurILImIc,
Iog-IIneur, Iog-Iog
LinLin
Coiors IIsL oI RGB vuIues IIne coIors IIrsL 1o enLrIes oI
RCB..CoiorLisl
Fromes InLeger 0 number oI Irumes oI
un unImuLIon
50
Legendvisibie TRuE, FALSE Iegend onJoII TRuE II pIoLLIng more
LIun one IuncLIon
LineCoiorType 0ichromolic, Fiol,
Funclionoi,
Monochrome, RoinboW
coIor scIeme Fiol
Mesh InLeger 2 number oI sumpIe
poInLs
1Z1
Scoiing Aulomolic,
Conslroined,
unconslroined
scuIIng mode unconslroined
TicksWumber Wone, LoW, Wormoi,
|igh
number oI IubeIed
LIcks
Wormoi
vieWingBoxYRonge ymin..ymox resLrIcLed vIewIng
runge In y dIrecLIon
Aulomolic
..Aulomolic
TubIe 11.1: Some ImporLunL uLLrIbuLes Ior pIoLLIng zD IuncLIons
We now presenL some exumpIes Ior LIe use oI LIese uLLrIbuLes.
11-11
TT Grophics
IrsL, we wIII gIve un exumpIe wIere LIe number oI evuIuuLIon poInLs needs
udjusLmenL. TIe IoIIowIng pIoL exumpIe IeuLures LIe noLorIous IuncLIon sIn(1/x)
LIuL oscIIIuLes wIIdIy neur LIe orIgIn:
piol(sin(1/x} x = -0.5..0.5}
CIeurIy, LIe deIuuIL oI 121 sumpIe poInLs used by piol does noL suIIIce Lo creuLe u
suIIIcIenLIy resoIved pIoL.
11-1
Eosy Plo||ing: Grophs ol Func|ions
We Increuse LIe number oI numerIcuI mesI poInLs vIu LIe Mesh uLLrIbuLe.
AddILIonuIIy, we Increuse LIe resoIuLIon depLI oI LIe udupLIve pIoLLIng mecIunIsm
Irom ILs deIuuIL vuIue AdopliveMesh=Z Lo AdopliveMesh=4:
piol(sin(1/x} x = -0.5..0.5 Mesh = 500
AdopliveMesh = 4}
11-1
TT Grophics
TIe IoIIowIng cuII specIIIes u Ieuder vIu |eoder="The funclion sin(x^Z}".
TIe dIsLunce beLween IubeIed LIcks Is seL Lo 0.5 uIong LIe x uxIs und Lo 0.2 uIong LIe
y uxIs vIu XTicks0islonce=0.5 und YTicks0islonce=0.Z, respecLIveIy. our
uddILIonuI unIubeIed LIcks beLween eucI puIr oI IubeIed LIcks ure seL In LIe x
dIrecLIon vIu XTicksBelWeen=4. One uddILIonuI unIubeIed LIck beLween eucI puIr
oI IubeIed LIcks In LIe y dIrecLIon Is requesLed vIu YTicksBelWeen=1. GrId IInes
uLLucIed Lo LIe LIcks ure swILcIed on by Cridvisibie=TRuE und
Subgridvisibie=TRuE:
piol(sin(x^Z} x = 0..7
|eoder = "The funclion sin(x^Z}"
XTicks0islonce = 0.5 YTicks0islonce = 0.Z
XTicksBelWeen = 4 YTicksBelWeen = 1
Cridvisibie = TRuE Subgridvisibie = TRuE}
11-1q
Eosy Plo||ing: Grophs ol Func|ions
WIen sInguIurILIes ure Iound In LIe IuncLIon, un uuLomuLIc cIIppIng Is cuIIed LryIng
Lo resLrIcL LIe verLIcuI vIewIng runge In some wuy Lo obLuIn u reusonubIy scuIed
pIcLure. TIIs Is u IeurIsLIc upproucI LIuL someLImes needs u IeIpIng udupLIon by
Iund. n LIe IoIIowIng exumpIe, LIe uuLomuLIcuIIy cIosen runge beLween y 40
und y 260 In verLIcuI dIrecLIon Is suILubIe Lo represenL LIe 6LI order poIe uL
x = 1, buL IL does noL provIde u good resoIuLIon oI LIe IIrsL order poIe uL x = 1:
piol(1/(x + 1}/(x - 1}^6 x = -Z..Z}
TIere Is no good vIewIng runge LIuL Is udequuLe Ior boLI poIes becuuse LIey ure oI
dIIIerenL order. However, some compromIse cun be Iound.
11-1g
TT Grophics
We overrIde LIe uuLomuLIc vIewIng runge suggesLed by piol und requesL u specIIIc
vIewIng runge In verLIcuI dIrecLIon vIu vieWingBoxYRonge:
piol(1/(x + 1}/(x - 1}^6 x = -Z..Z
vieWingBoxYRonge = -10..10}
11-16
Eosy Plo||ing: Grophs ol Func|ions
TIe vuIues oI LIe IoIIowIng IuncLIon Iuve u Iower bound, buL no upper bound. We
use LIe uLLrIbuLe vieWingBoxYRonge=Aulomolic..10 Lo IeL piol IInd u Iower
bound Ior LIe vIewIng box by ILseII wIIIsL requesLIng u specIIIc vuIue oI 10 Ior LIe
upper bound:
piol(exp(x}*sin(PT*x} + 1/(x + 1}^Z/(x - 1}^4
x = -Z..Z vieWingBoxYRonge = Aulomolic..10}
11-1,
TT Grophics
Ionction Gruphs
We consIder D exumpIes, I.e., pIoLs oI bI-vurIuLe IuncLIons f(x, y). As noLed
ubove, Lo dIsLInguIsI sLuLIc D und unImuLed zD pIoLs, LIe Iormer need LIe opLIon
#30. Here Is u pIoL oI LIe IuncLIon sIn(x
2
+y
2
):
piol(sin(x^Z + y^Z} x = -Z..Z y = -Z..Z #30}
11-1S
Eosy Plo||ing: Grophs ol Func|ions
I severuI IuncLIons ure Lo be pIoLLed In LIe sume grupIIcuI scene, jusL puss u
sequence oI IuncLIon expressIons; uII IuncLIons ure pIoLLed over LIe specIIIed
common runge:
piol((x^Z + y^Z}/4 sin(x - y}/(x - y}
x = -Z..Z y = -Z..Z #30}
11-1q
TT Grophics
uncLIons LIuL do noL uIIow u sImpIe symboIIc represenLuLIon by un expressIon
cun uIso be deIIned by u procedure LIuL produces u numerIcuI vuIue f(x, y) wIen
cuIIed wILI numerIcuI vuIues x, y Irom LIe pIoL runge. n LIe IoIIowIng exumpIe we
consIder LIe IurgesL eIgenvuIue oI u symmeLrIc 3 3 muLrIx LIuL conLuIns Lwo
purumeLers x, y. We pIoL LIIs eIgenvuIue us u IuncLIon oI x und y:
f .= (x y} -> mox(numeric..eigenvoiues(
molrix(__-y x -x ]
_ x y x ]
_-x x y^Z]]}}}.
piol(#30 f x = -1..1 y = -1..1}
TIe numes x, y used In LIe specIIIcuLIon oI LIe pIoLLIng runge provIde LIe IubeIs oI
LIe correspondIng uxes.
11-o
Eosy Plo||ing: Grophs ol Func|ions
uncLIons cun uIso be deIIned by pieceWise objecLs:
piol(pieceWise(_x < y y-x] _x > y (y-x}^Z]}
x = 0..1 y = 0..1 #30}
NoLe LIuL LIere ure gups In LIe deIInILIon oI LIe IuncLIon ubove: no IuncLIon vuIue
Is specIIIed Ior x = y. TIIs does noL cuuse uny probIem, becuuse piol sImpIy
Ignores poInLs LIuL do noL produce reuI numerIcuI vuIues II IL IInds suILubIe vuIues
In LIe neIgIborIood. TIus, mIssIng poInLs or sInguIurILIes do noL ruIse un error.
11-1
TT Grophics
I LIe IuncLIon Is noL reuI-vuIued In regIons oI non-zero meusure, gups wIII be
vIsIbIe In LIe ouLpuL. TIe IoIIowIng IuncLIon Is reuI-vuIued onIy In LIe dIsc
x
2
+y
2
1:
piol(sqrl(1 - x^Z - y^Z} x = 0..1 y = 0..1 #30}
11-
Eosy Plo||ing: Grophs ol Func|ions
WIen severuI IuncLIons ure pIoLLed In LIe sume scene, LIey ure druwn In dIIIerenL
coIors LIuL ure cIosen uuLomuLIcuIIy. WILI LIe Coiors uLLrIbuLe one muy specIIy u
IIsL oI RGB coIors LIuL piol sIuII use:
piol(Z + x^Z + y^Z 1 + x^4 + y^4 x^6 + y^6
x = -1..1 y = -1..1 #30
Coiors = _RCB..Red RCB..Creen RCB..Biue]}
11-
TT Grophics
AnImuLed D pIoLs oI IuncLIons ure creuLed by pussIng IuncLIon expressIons
dependIng on Lwo vurIubIes (x und y, suy) und un unImuLIon purumeLer (a, suy)
und specIIyIng u runge Ior x, y, und a.
piol(x^o + y^o x = 0..Z y = 0..Z o = 1..Z #30}
Once LIe pIoL Is creuLed, LIe IIrsL Irume oI LIe pIcLure uppeurs us u sLuLIc pIoL.
AILer doubIe-cIIckIng on LIe pIcLure, LIe grupIIcs LooI uIIows Lo sLurL LIe
unImuLIon by pusIIng LIe SLurL buLLon.
11-q
Eosy Plo||ing: Grophs ol Func|ions
An unImuLIon consIsLs oI sepuruLe Irumes. TIe deIuuIL number oI Irumes Is 50. I u
dIIIerenL vuIue Is desIred, jusL puss LIe uLLrIbuLe Fromes=n, wIere n Is LIe number
oI Irumes LIuL sIuII be creuLed:
piol(sin(o}*sin(x} + cos(o}*cos(y} x = 0..Z*PT
y = 0..Z*PT o = 0..Z*PT #30 Fromes = 3Z}
ApurL Irom LIe coIor specIIIcuLIon or LIe Fromes number, LIere Is u Iurge number
oI IurLIer uLLrIbuLes LIuL muy be pussed Lo piol. EucI uLLrIbuLe Is pussed us un
equuLIon Lo piol. Here, we onIy presenL some seIecLed uLLrIbuLes. SecLIon
ALLrIbuLes Ior piolfuncZd und piolfunc3d oI LIe onIIne piol documenLuLIon
provIdes IurLIer LubIes wILI more uLLrIbuLes.

uLLrIbuLe nume possIbIe vuIues meunIng deIuuIL


|eighl *unil..cm pIysIcuI IeIgIL oI LIe
pIcLure
0*unil..mm
nidlh 1Z*unil..cm pIysIcuI wIdLI oI LIe
pIcLure
1Z0*unil..mm
Fooler sLrIng IooLer LexL "" (no IooLer)
|eoder sLrIng Ieuder LexL "" (no Ieuder)
Tilie sLrIng LILIe LexL "" (no LILIe)
TiliePosilion _reuI vuIue,
reuI vuIue]
coordInuLes oI LIe
Iower IeIL corner oI
LIe LILIe
Cridvisibie TRuE, FALSE vIsIbIIILy oI mujor
grId IInes
FALSE
TubIe 11.z: Some ImporLunL uLLrIbuLes Ior pIoLLIng D IuncLIons
11-g
TT Grophics

uLLrIbuLe nume possIbIe vuIues meunIng deIuuIL


Subgridvisibie TRuE, FALSE vIsIbIIILy oI mInor
grId IInes
FALSE
AdopliveMesh InLeger 0 depLI oI LIe udupLIve
mesI
0
Axes Aulomolic, Boxed,
Frome, 0rigin
uxes Lype Boxed
Axesvisibie TRuE, FALSE vIsIbIIILy oI uII uxes TRuE
AxesTilies _slring slring
slring]
LILIes oI LIe uxes _"x""y""z"]
Coiors IIsL oI RGB coIors IIII coIors
Fromes InLeger 0 number oI Irumes oI
LIe unImuLIon
50
Legendvisibie TRuE, FALSE Iegend onJoII TRuE II pIoLLIng more
LIun one IuncLIon
FiiiCoiorType 0ichromolic, Fiol,
Funclionoi,
Monochrome, RoinboW
coIor scIeme 0ichromolic
Mesh |InLeger 2, InLeger
2|
number oI mujor
mesI poInLs
_Z5 Z5]
Submesh |InLeger 0, InLeger
0|
number oI mInor
mesI poInLs
_0 0]
Scoiing Aulomolic,
Conslroined,
unconslroined
scuIIng mode unconslroined
TicksWumber Wone, LoW, Wormoi,
|igh
number oI IubeIed
LIcks
Wormoi
vieWingBoxZRonge zmin..zmox resLrIcLed vIewIng
runge In z dIrecLIon
Aulomolic
..Aulomolic
TubIe 11.z: Some ImporLunL uLLrIbuLes Ior pIoLLIng D IuncLIons
eL us presenL some exumpIe uses oI LIese uLLrIbuLes. As Ior zD pIoLs, we`II sLurL
wILI LIe evuIuuLIon densILy.
11-6
Eosy Plo||ing: Grophs ol Func|ions
n LIe IoIIowIng exumpIe, LIe deIuuIL mesI oI 25 25 sumpIe poInLs used by piol
does noL suIIIce Lo creuLe u suIIIcIenLIy resoIved pIoL:
piol(sin(x^Z + y^Z} x = -3..3 y = -3..3 #30}
11-,
TT Grophics
We Increuse LIe number oI numerIcuI mesI poInLs vIu LIe Submesh uLLrIbuLe:
piol(sin(x^Z + y^Z} x = -3..3 y = -3..3
Submesh = _3 3] #30}
11-S
Eosy Plo||ing: Grophs ol Func|ions
TIe IoIIowIng cuII specIIIes u Ieuder vIu |eoder="The funclion sin(x - y^Z}".
GrId IInes uLLucIed Lo LIe LIcks ure swILcIed on by Cridvisibie und
Subgridvisibie:
piol(sin(x - y^Z} x = -Z*PT..Z*PT y = -Z..Z #30
|eoder = "The funclion sin(x - y^Z}"
Cridvisibie = TRuE Subgridvisibie = TRuE}
11-q
TT Grophics
WIen sInguIurILIes ure Iound In LIe IuncLIon, un uuLomuLIc cIIppIng Is cuIIed
LryIng Lo resLrIcL LIe verLIcuI vIewIng runge In some wuy Lo obLuIn u reusonubIy
scuIed pIcLure. TIIs Is u IeurIsLIc upproucI LIuL someLImes needs u IeIpIng
udupLIon by Iund. n LIe IoIIowIng exumpIe, LIe uuLomuLIcuIIy cIosen runge
beLween z 0 und z 0.8 In verLIcuI dIrecLIon Is suILubIe Lo represenL LIe poIe uL
x = 1, y = 1, buL IL does noL provIde u good resoIuLIon oI LIe poIe uL x = 1, y = 1:
piol(1/((x+1}^Z + (y-1}^Z}/((x-1}^Z + (y-1}^Z}^5
x = -Z..3 y = -Z..3 Submesh = _3 3] #30}
TIere Is no good vIewIng runge LIuL Is udequuLe Ior boLI poIes becuuse LIey ure oI
dIIIerenL order.
11-o
Eosy Plo||ing: Grophs ol Func|ions
We overrIde LIe uuLomuLIc vIewIng runge suggesLed by piol und requesL u specIIIc
vIewIng runge In LIe verLIcuI dIrecLIon vIu vieWingBoxZRonge:
piol(1/((x+1}^Z + (y-1}^Z}/((x-1}^Z + (y-1}^Z}^5
x = -Z..3 y = -Z..3 Submesh = _3 3]
vieWingBoxZRonge = 0..0.1 #30}
11-1
TT Grophics
TIe vuIues oI LIe IoIIowIng IuncLIon Iuve u Iower bound buL no upper bound. We
use LIe uLLrIbuLe vieWingBoxZRonge=Aulomolic..Z0 Lo IeL piol IInd u Iower
bound Ior LIe vIewIng box by ILseII wIIIsL requesLIng u specIIIc vuIue oI 20 Ior LIe
upper bound:
piol(1/x^Z/y^Z + exp(-x}*sin(PT*y}
x = -Z..Z y = -Z..Z #30
vieWingBoxZRonge = Aulomolic..Z0}
11-
Advonced Plo||ing: Principles ond Firs| Eomples
kdvuated FleIIiag: Friatiples uad lirsI xumples
n LIe prevIous secLIon, we InLroduced LIe piol commund Ior pIoLLIng IuncLIons In
zD und D wILI sImpIe cuIIs In eusy synLux. AILIougI LIere Is u Iurge number oI
uLLrIbuLes Lo conLroI LIe grupIIcuI ouLpuL und LIere Is uIso u Iurge number oI
uddILIonuI possIbIIILIes Ior pIoLLIng poInL IIsLs eLc., LIere remuIns u serIous
resLrIcLIon: LIe uLLrIbuLes ure used Ior uII IuncLIons sImuILuneousIy.
I uLLrIbuLes ollr11 eLc. ure Lo be uppIIed Lo IuncLIons IndIvIduuIIy, one needs Lo
Invoke u (sIIgILIy) more eIuboruLe cuIIIng synLux Lo generuLe LIe pIoL:
piol(
piol..FunclionZd(f1 x1 = o1..b1 ollr11 ollr1Z ...}
piol..FunclionZd(fZ xZ = oZ..bZ ollrZ1 ollrZZ ...}
...
}
n LIIs cuII, eucI cuII oI piol..FunclionZd creuLes u sepuruLe objecL LIuL
represenLs LIe grupI oI LIe IuncLIon pussed us LIe IIrsL urgumenL over LIe pIoLLIng
runge pussed us LIe second urgumenL. An urbILrury number oI pIoL uLLrIbuLes cun
be ussocIuLed wILI eucI IuncLIon grupI. TIe objecLs LIemseIves ure noL dIspIuyed
dIrecLIy. TIe piol commund LrIggers LIe evuIuuLIon oI LIe IuncLIons on some
suILubIe numerIcuI mesI und cuIIs LIe renderer Lo dIspIuy LIese numerIcuI duLu In
LIe Iorm specIIIed by LIe gIven uLLrIbuLes.
n IucL, piol cuIIed on u pIuIn expressIon does precIseIy LIe sume: InLernuIIy, LIe
uLIIILy IuncLIon piol..eosy generuLes objecLs oI Lype piol..FunclionZd or
piol..Funclion3d, respecLIveIy, und LIese ure rendered.
Generul Principles
n generuI, grupIIcuI scenes ure coIIecLIons oI grupIIcuI prImILIves. TIere ure
sImpIe prImILIves sucI us poInLs, IIne segmenLs, poIygons, recLungIes und boxes,
cIrcIes und spIeres, IIsLogrum pIoLs, pIe cIurLs eLc. An exumpIe oI u more
udvunced prImILIve Is piol..veclorFieidZd LIuL represenLs u coIIecLIon oI urrows
uLLucIed Lo u reguIur mesI vIsuuIIzIng u vecLor IIeId over u recLunguIur regIon In
R
2
. YeL more udvunced prImILIves ure IuncLIon grupIs und purumeLrIzed curves
LIuL come equIpped wILI some InLernuI InLeIIIgence, e.g., knowIng Iow Lo evuIuuLe
11-
TT Grophics
LIemseIves numerIcuIIy on udupLIve mesIes und Iow Lo cIIp LIemseIves In cuse oI
sInguIurILIes. As exumpIes Ior IIgIIy udvunced prImILIves In LIe piol IIbrury, we
menLIon piol..0deZd, piol..0de3d, piol..SlreomiinesZd, und
piol..TmpiicilZd, piol..Tmpiicil3d. TIe IIrsL uuLomuLIcuIIy soIve sysLems oI
ordInury dIIIerenLIuI equuLIons numerIcuIIy und dIspIuy LIe soIuLIons grupIIcuIIy.
TIe IuLLer dIspIuy LIe soIuLIon curves or surIuces oI equuLIons f(x, y) = 0 or
f(x, y, z) = 0, respecLIveIy, by soIvIng LIese equuLIons numerIcuIIy, u LypIcuI Lusk
In (reuI) uIgebruIc geomeLry.
AII LIese prImILIves ure jusL objecLs represenLIng some grupIIcuI enLILIes. TIey
ure noL rendered dIrecLIy wIen LIey ure creuLed, buL jusL serve us duLu sLrucLures
encodIng LIe grupIIcuI meunIng, coIIecLIng uLLrIbuLes deIInIng LIe presenLuLIon
sLyIe und provIdIng numerIcuI rouLInes Lo converL LIe InpuL purumeLers Lo some
numerIcuI duLu LIuL ure Lo be senL Lo LIe renderer.
An urbILrury number oI sucI prImILIves cun be coIIecLed Lo Iorm u grupIIcuI scene.
InuIIy, u cuII Lo piol pussIng u sequence oI uII prImILIves In LIe scene Invokes LIe
renderer Lo druw LIe pIoL. TIe IoIIowIng exumpIe sIows LIe grupI oI LIe IuncLIon
f(x) = x sIn(x). AL LIe poInL (x
0
, f(x
0
)), u grupIIcuI poInL Is InserLed und LIe
LungenL Lo LIe grupI LIrougI LIIs poInL Is udded:
f .= x -> x*sin(x}.
x0.= 1.Z. dx .= 1.
g .= piol..FunclionZd(f(x} x = 0..Z*PT}.
p .= piol..PoinlZd(x0 f(x0} PoinlSize = 3.0*unil..mm}.
l .= piol..LineZd(_x0 - dx f(x0} - f(x0}*dx]
_x0 + dx f(x0} + f(x0}*dx]}.
11-q
Advonced Plo||ing: Principles ond Firs| Eomples
TIe pIcLure Is druwn by cuIIIng piol:
piol(g l p}
EucI prImILIve uccepLs u vurIeLy oI pIoL uLLrIbuLes LIuL muy be pussed us u
sequence oI equuLIons AllribuleWome=Allribulevoiue Lo LIe generuLIng cuII.
MosL promInenLIy, uImosL every prImILIve uIIows Lo seL LIe coIor expIIcILIy:
g .= piol..FunclionZd(f(x} x = 0..Z*PT
Coior = RCB..Biue}.
AILernuLIveIy, LIe generuLed objecLs uIIow Lo seL uLLrIbuLes vIu sIoL ussIgnmenLs oI
LIe Iorm obgecl..AllribuleWome.=Allribulevoiue us In
p..Coior .= RCB..Biock.
p..PoinlSize .= 4.0*unil..mm.
l..Coior .= RCB..Red.
l..Linenidlh .= 1.0*unil..mm.
TIe IeIp puge oI eucI prImILIve provIdes u IIsL oI uII uLLrIbuLes LIe prImILIve Is
reucLIng Lo.
11-g
TT Grophics
CerLuIn uLLrIbuLes, sucI us uxes sLyIe, LIe vIsIbIIILy oI grId IInes In LIe buckground
eLc. ure ussocIuLed wILI LIe wIoIe scene ruLIer LIun wILI LIe IndIvIduuI prImILIves.
TIese uLLrIbuLes muy be IncIuded In LIe piol cuII:
piol(g l p Cridvisibie = TRuE}
As expIuIned In deLuII In SecLIon TIe uII PIcLure on puge 11-q6, LIe piol
commund uuLomuLIcuIIy embeds LIe grupIIcuI prImILIves In u coordInuLe sysLem,
wIIcI In Lurn Is embedded In u grupIIcuI scene, wIIcI Is druwn InsIde u cunvus.
TIe vurIous uLLrIbuLes ussocIuLed wILI LIe generuI uppeurunce oI LIe wIoIe pIcLure
ure ussocIuLed wILI LIese groupIng sLrucLures. A concIse IIsL oI uII sucI
uLLrIbuLes Is provIded on LIe IeIp puges oI LIe correspondIng prImILIves:
piol..Convos, piol..SceneZd, piol..Scene3d, piol..CoordinoleSyslemZd, und
piol..CoordinoleSyslem3d, respecLIveIy.
TIe MuPAD

objecL browser uIIows Lo seIecL eucI prImILIve In LIe pIoL. AILer


seIecLIon, LIe uLLrIbuLes oI LIe prImILIve cun be cIunged InLerucLIveIy In LIe
properLy InspecLor (see puge 11-o).
NexL, we wIsI Lo demonsLruLe un unImuLIon. L Is remurkubIy sImpIe Lo generuLe
un unImuLed pIcLure. GoIng buck Lo our prevIous exumpIe wILI LIe LungenL Lo LIe
IuncLIon grupI, we wunL Lo IeL LIe poInL x
0
uL wIIcI LIe LungenL Is udded move
uIong LIe grupI oI LIe IuncLIon. n MuPAD, you do noL need Lo creuLe un
unImuLIon Irume by Irume. nsLeud, eucI prImILIve cun be LoId Lo unImuLe ILseII by
11-6
Advonced Plo||ing: Principles ond Firs| Eomples
sImpIy deIInIng IL wILI u symboIIc unImuLIon purumeLer und uddIng un unImuLIon
runge Ior LIIs purumeLer. SLuLIc und unImuLed objecLs cun be mIxed und rendered
LogeLIer. TIe sLuLIc IuncLIon grupI oI f(x) used In LIe prevIous pIoL Is recycIed Ior
LIe unImuLIon. TIe grupIIcuI poInL uL (x
0
, f(x
0
)) und LIe LungenL LIrougI LIIs
poInL sIuII be unImuLed usIng LIe coordInuLe x0 us LIe unImuLIon purumeLer.
DeIeLIng ILs vuIue seL ubove, we cun use LIe sume deIInILIons us beIore, now wILI u
symboIIc x0. We jusL Iuve Lo udd LIe runge specIIIcuLIon x0=0..Z*PT Ior LIIs
purumeLer:
deiele x0.
dx .= Z/sqrl(1 + f(x0}^Z}.
p .= piol..PoinlZd(x0 f(x0} x0 = 0..Z*PT
Coior = RCB..Biock
PoinlSize = Z.0*unil..mm}.
l .= piol..LineZd(_x0 - dx f(x0} - f(x0}*dx]
_x0 + dx f(x0} + f(x0}*dx]
x0 = 0..Z*PT Coior = RCB..Red
Linenidlh = 1.0*unil..mm}.
piol(g p l Cridvisibie = TRuE}
DeLuIIs on unImuLIons und IurLIer exumpIes ure provIded sLurLIng on puge 11-;1.
11-,
TT Grophics
We summurIze LIe consLrucLIon prIncIpIes Ior grupIIcs wILI MuPAD`s piol
IIbrury:

Grcphiccl scenes cre built jrom rcphiccl primitites. The section


stcrtin on pce ::-( protides c surte oj the primitites thct cre
ctcilcble in the piol librcr.
Primitites enercted b the piol librcr cre sm-
bolic objects thct cre not rendered directl. The ccll
piol(Primilive1PrimiliveZ.} enerctes the pictures.
Grcphi ccl cttri butes cre speci j i ed cs equcti ons
AllribuleWome=voiue. Attributes jor c rcphiccl primitite
mc be pcssed in the ccll thct enerctes the primitite. The help
pce oj ecch primitite protides c complete list oj cll cttributes the
primitite reccts to.
Attributes determinin the enercl cppecrcnce oj the pic-
ture mc be iten in the piol ccll. The help pces oj
piol..CoordinoleSyslemZd, piol..CoordinoleSyslem3d,
piol..SceneZd, piol..Scene3d, cnd piol..Convos, respectitel,
protide c complete list oj cll cttributes determinin the enercl
cppecrcnce.
Almost cll cttributes ccn be chcned intercctitel in the tieuer.
Presentl, zD cnd D plots cre strictl sepcrcted. Dbjects oj dijjer-
ent dimension ccnnot be rendered in the scme plot.
Animctions cre not crected jrcme b jrcme but per object (see clso
Section ::.p). An object is cnimcted b enerctin it uith c smbolic
cnimction pcrcmeter cnd protidin c rcne jor this pcrcmeter in
the enerctin ccll. The section stcrtin on pce ::-;: protides jur-
ther detcils on cnimctions.
PresenLIy, IL Is noL possIbIe Lo udd objecLs Lo un exIsLIng pIoL. However, usIng
unImuLIons, IL Is possIbIe Lo IeL prImILIves uppeur one uILer unoLIer In LIe
unImuLed pIcLure.
11-S
Advonced Plo||ing: Principles ond Firs| Eomples
Some Ixumples
Ixumple 1: We wIsI Lo vIsuuIIze LIe InLerpoIuLIon oI u dIscreLe duLu sumpIe by
cubIc spIInes. IrsL, we deIIne LIe duLu sumpIe, consIsLIng oI u IIsL oI poInLs
[[x
1
, y
1
], [x
2
, y
2
], . . . ]. Suppose LIey ure equIdIsLunL sumpIe poInLs Irom LIe grupI
oI LIe IuncLIon f(x) = x e
x
sIn(5 x):
f .= x -> x*exp(-x}*sin(5*x}.
dolo .= __i f(i}] S i = 0..3 slep 1/3].
We use numeric..cubicSpiine Lo deIIne LIe cubIc spIIne InLerpoIunL LIrougI
LIese duLu:
S .= numeric..cubicSpiine(op(dolo}}.
TIe pIoL sIuII consIsL oI LIe IuncLIon f(x) LIuL provIdes LIe duLu oI LIe sumpIe
poInLs und oI LIe spIIne InLerpoIunL S(x). TIe grupIs oI f(x) und S(x) ure
generuLed vIu piol..FunclionZd. TIe duLu poInLs ure pIoLLed us u
piol..PoinlLislZd:
11-q
TT Grophics
piol(piol..FunclionZd(f(x} x = 0..3 Coior = RCB..Red
LegendTexl = exprZlexl(f(x}}}
piol..FunclionZd(S(x} x = 0..3 Coior = RCB..Biue
LegendTexl = "spiine inlerpoionl"}
piol..PoinlLislZd(dolo Coior = RCB..Biock}
Cridvisibie = TRuE Subgridvisibie = TRuE
Legendvisibie = TRuE}
11-qo
Advonced Plo||ing: Principles ond Firs| Eomples
Ixumple : A cycIoId Is LIe curve LIuL you geL wIen IoIIowIng u poInL IIxed Lo u
wIeeI roIIIng uIong u sLruIgIL IIne. We vIsuuIIze LIIs consLrucLIon by un unImuLIon
In wIIcI we use LIe x coordInuLe oI LIe Iub us LIe unImuLIon purumeLer. TIe
wIeeI Is reuIIzed us u cIrcIe. TIere ure poInLs IIxed Lo LIe wIeeI: u green poInL on
LIe rIm, u red poInL InsIde LIe wIeeI und u bIue poInL ouLsIde LIe wIeeI:
nheeiRodius .= 1.
r .= _1.5*nheeiRodius 1.0*nheeiRodius 0.5*nheeiRodius].
nheeiCenler .= _x nheeiRodius].
nheeiRim .= piol..CircieZd(nheeiRodius nheeiCenler
x = 0..4*PT
LineCoior = RCB..Biock}.
nheei|ub .= piol..PoinlZd(nheeiCenler x = 0..4*PT
PoinlCoior = RCB..Biock}.
nheeiSpoke .= piol..LineZd(nheeiCenler
_nheeiCenler_1] + mox(r}*sin(x}
nheeiCenler_Z] + mox(r}*cos(x}]
x = 0..4*PT LineCoior = RCB..Biock}.
coior.= _RCB..Red RCB..Creen RCB..Biue].
for i from 1 lo 3 do
Poinl_i] .= piol..PoinlZd(_nheeiCenler_1] + r_i]*sin(x}
nheeiCenler_Z] + r_i]*cos(x}]
x = 0..4*PT
PoinlCoior = coior_i]
PoinlSize = Z.0*unil..mm}.
Cycioid_i] .= piol..CurveZd(_y + r_i]*sin(y}
nheeiRodius + r_i]*cos(y}]
y = 0..x x = 0..4*PT
LineCoior = coior_i]}.
endfor.
11-q1
TT Grophics
piol(nheeiRim nheei|ub nheeiSpoke Poinl_i] S i = 1..3
Cycioid_i] S i = 1..3 Scoiing = Conslroined
nidlh = 1Z0*unil..mm |eighl = 35*unil..mm}
11-q
Advonced Plo||ing: Principles ond Firs| Eomples
Ixumple : We wIsI Lo vIsuuIIze LIe soIuLIon oI LIe ordInury dIIIerenLIuI
equuLIon (ODE) y

(x) = y(x)
3
+cos(x) wILI LIe InILIuI condILIon y(0) = 0. TIe
soIuLIon sIuII be druwn LogeLIer wILI LIe vecLor IIeId v(x, y) = (1, y
3
+cos(x))
ussocIuLed wILI LIIs ODE (uIong LIe soIuLIon curve, LIe vecLors oI LIIs IIeId ure
LungenLs oI LIe curve). We use numeric..odesoiveZ Lo generuLe LIe soIuLIon us u
IuncLIon pIoL. SInce LIe numerIcuI InLegruLor reLurns LIe resuIL us u IIsL oI one
IIouLIng poInL vuIue, one Ius Lo puss LIe sIngIe IIsL enLry us Y (x)[1] Lo
piol..FunclionZd. TIe vecLor IIeId Is generuLed vIu piol..veclorFieidZd:
f .= (x y} -> -y^3 + cos(x}.
Y .= numeric..odesoiveZ(
numeric..odeZveclorfieid({y(x} = f(x y}
y(0} = 0] _y(x}]}}.
piol(
piol..veclorFieidZd(_1 f(x y}] x = 0..6 y = -1..1
Coior = RCB..Biue Mesh = _Z5 Z5]}
piol..FunclionZd(Y(x}_1] x = 0..6 Coior = RCB..Red
Linenidlh = 0.7*unil..mm}
Cridvisibie = TRuE Subgridvisibie = TRuE Axes = Frome}
11-q
TT Grophics
Ixumple q: TIe rudIus r oI un objecL wILI roLuLIonuI symmeLry uround LIe
x-uxIs Is meusured uL vurIous x posILIons:
x o.oo o.1o o.zo o.o o.qo o.o o.6o o.;o o.8o o.qo o.q 1.oo
r(x) o.6o o.8 o. o.1 o.q6 o.qo o.o o.1 o.z o.zq o.zo o.oo
A spIIne InLerpoIuLIon Is used Lo deIIne u smooLI IuncLIon r(x) Irom LIe
meusuremenLs:
sompiepoinls .=
_0.00 0.60] _0.10 0.5] _0.Z0 0.55] _0.30 0.51]
_0.40 0.46] _0.50 0.40] _0.60 0.30] _0.70 0.15]
_0.0 0.Z3] _0.90 0.Z4] _0.95 0.Z0] _1.00 0.00].
r .= numeric..cubicSpiine(sompiepoinls}.
We reconsLrucL LIe objecL us u surIuce oI revoIuLIon vIu piol..XRolole. TIe
roLuLIon ungIe Is resLrIcLed Lo u runge LIuL Ieuves u gup In LIe surIuce. TIe spIIne
curve und LIe sumpIe poInLs ure udded us u piol..Curve3d und u
piol..PoinlLisl3d, respecLIveIy, und dIspIuyed In LIIs gup:
11-qq
Advonced Plo||ing: Principles ond Firs| Eomples
piol(
piol..XRolole(r(x} x = 0..1
AngieRonge = 0.6*PT..Z.4*PT
Coior = RCB..MuPA0Coid}
piol..Curve3d(_x 0 r(x}] x = 0..1
Linenidlh = 0.5*unil..mm
Coior = RCB..Biock}
piol..PoinlLisl3d(__p_1] 0 p_Z]] S p in sompiepoinls]
PoinlSize = Z.0*unil..mm
Coior = RCB..Red}
Comero0ireclion = _70 -70 40]}
11-qg
TT Grophics
he lull FitIure: 6ruphitul rees
or u IuII undersLundIng oI LIe InLerucLIve IeuLures oI LIe vIewer Lo be dIscussed In
LIe nexL secLIon, we need Lo know LIe sLrucLure oI u MuPAD

pIoL us u grupIIcuI
Lree.
TIe rooL Is LIe cunvus; LIIs Is LIe druwIng ureu InLo wIIcI uII purLs oI LIe pIoL ure
rendered. TIe Lype oI LIe cunvus objecL Is piol..Convos. Ls pIysIcuI sIze muy be
specIIIed vIu LIe uLLrIbuLes nidlh und |eighl.
nsIde LIe cunvus, one or more grupIIcuI scenes cun be dIspIuyed. AII oI LIem
musL be oI LIe sume dImensIon, I.e., objecLs oI Lype piol..SceneZd or
piol..Scene3d, respecLIveIy. TIe IoIIowIng commund dIspIuys Iour dIIIerenL D
scenes. We seL LIe Bordernidlh Ior uII objecLs oI Lype piol..Scene3d Lo some
posILIve vuIue so LIuL LIe druwIng ureus oI LIe scenes become vIsIbIe more cIeurIy:
S1 .= piol..Scene3d(piol..Sphere(1 _0 0 0]
Coior = RCB..Red}
BockgroundSlyie = LeflRighl}.
SZ .= piol..Scene3d(piol..Box(-1..1 -1..1 -1..1
Coior = RCB..Creen}
BockgroundSlyie = TopBollom}.
S3 .= piol..Scene3d(piol..Cone(1 _0 0 0] _0 0 1]
Coior = RCB..Biue}
BockgroundSlyie = Pyromid}.
S4 .= piol..Scene3d(piol..Cone(1 _0 0 1] _0 0 0]
Coior = RCB..0ronge}
BockgroundSlyie = Fiol
BockgroundCoior = RCB..Croy}.
11-q6
The Full Pic|ure: Grophicol Trees
piol(piol..Convos(
S1 SZ S3 S4
nidlh = 0*unil..mm |eighl = 0*unil..mm
Axes = Wone Bordernidlh = 0.5*unil..mm
piol..Scene3d..Bordernidlh = 0.5*unil..mm}}
See SecLIon uyouL oI Cunvus und Scenes oI LIe onIIne piol documenLuLIon Ior
deLuIIs on Iow LIe IuyouL oI u cunvus conLuInIng severuI scenes Is seL.
CoordInuLe sysLems exIsL InsIde u zD scene or u D scene und ure oI Lype
piol..CoordinoleSyslemZd or piol..CoordinoleSyslem3d, respecLIveIy. TIere
muy be one or more coordInuLe sysLems In u scene. nsIde LIe coordInuLe sysLems,
un urbILrury number oI prImILIves (oI LIe upproprIuLe dImensIon) cun be
dIspIuyed. TIus, we uIwuys Iuve u cunvus, conLuInIng one or more scenes, wILI
eucI scene conLuInIng one or more coordInuLe sysLems. TIe grupIIcuI prImILIves
(or groups oI sucI prImILIves) ure conLuIned In LIe coordInuLe sysLems.
11-q,
TT Grophics
Hence, uny MuPAD pIoL Ius LIe IoIIowIng generuI sLrucLure:
Cunvus
Scene 1
CoordInuLeSysLem 1
PrImILIve 1
PrImILIve z
.
CoordInuLeSysLem z
PrImILIve
.
.
Scene z
CoordInuLeSysLem
PrImILIve
.
.
.
TIIs Is LIe grupIIcuI Lree LIuL Is dIspIuyed by LIe objecL browser (see
puge 11-o).
Shortcots: or sImpIe pIoLs conLuInIng prImILIves InsIde one coordInuLe sysLem
onIy LIuL resIdes In u sIngIe scene oI LIe cunvus, IL wouId be ruLIer cumbersome Lo
generuLe LIe pIcLure by u commund sucI us
piol(
piol..Convos(
piol..SceneZd(
piol..CoordinoleSyslemZd(Primilive1 PrimiliveZ ...}}}}
n IucL, LIe commund
piol(Primilive1 PrimiliveZ ...}
suIIIces: L Is u sIorLcuL oI LIe ubove commund. L uuLomuLIcuIIy generuLes u
coordInuLe sysLem LIuL conLuIns LIe prImILIves, embedded In u scene wIIcI Is
uuLomuLIcuIIy pIuced InsIde u cunvus objecL.
11-qS
The Full Pic|ure: Grophicol Trees
TIus, LIIs commund ImpIIcILIy creuLes LIe grupIIcuI Lree
Cunvus
Scene
CoordInuLeSysLem
PrImILIve 1
PrImILIve z
.
LIuL Is dIspIuyed In LIe objecL browser.
11-qq
TT Grophics
iewer, 8rewser, uad laspetIer: laIerutIive MuaipuluIiea
AILer u pIoL commund Is execuLed In u noLebook, LIe pIoL wIII LypIcuIIy uppeur
beIow LIe InpuL regIon, embedded In LIe noLebook. To ucLIvuLe LIe pIoL, cIIck on
IL wILI LIe IeIL mouse buLLon. TIIs Ieuves LIe pIoL embedded In LIe noLebook, buL
LIe noLebook menus ure repIuced by LIe grupIIcs menus.
Muke sure LIuL LIe ILem 'ObjecL Browser` Is enubIed under LIe 'VIew` menu. A
pune LILIed 'ObjecL Browser` Is vIsIbIe conLuInIng Lwo sub-wIndows, wIIcI we wIII
reIer Lo us LIe 'objecL browser` und LIe 'properLy InspecLor.`
n LIe objecL browser, LIe grupIIcuI Lree oI LIe pIoL us InLroduced In LIe precedIng
secLIon Is vIsIbIe. L uIIows Lo seIecL uny node oI LIe grupIIcuI Lree by u mouse cIIck.
AILer seIecLIng un objecL In LIe objecL browser, LIe correspondIng purL oI LIe pIoL
Is IIgIIIgILed In some wuy uIIowIng Lo IdenLIIy LIe seIecLed objecL vIsuuIIy. TIe
properLy InspecLor LIen dIspIuys LIe uLLrIbuLes LIe seIecLed objecL reucLs Lo. or
exumpIe, Ior un objecL oI Lype FunclionZd, LIe uLLrIbuLes vIsIbIe In LIe properLy
InspecLor ure cuLegorIzed us 'DeIInILIon,` 'AnImuLIon,` 'AnnoLuLIon,` 'CuIcuIuLIon,`
und 'SLyIe` wILI LIe IuLLer spIIL InLo LIe sub-cuLegorIes (SLyIe oI) 'Ines,` (SLyIe oI)
'PoInLs,` (SLyIe oI) 'AsympLoLes.` OpenIng one oI LIese cuLegorIes, one IInds LIe
uLLrIbuLes und LIeIr currenL vuIues LIuL uppIy Lo LIe currenLIy seIecLed objecL.
11-go
Viewer, rowser, ond Inspec|or: In|eroc|ive Nonipulo|ion
AILer seIecLIon oI un uLLrIbuLe wILI LIe mouse, ILs vuIue cun be cIunged:
TIere Is u sopIIsLIcuLed wuy oI seLLIng deIuuILs (see SecLIon 11.; und SecLIon 11.;
Ior un expIunuLIon) Ior LIe uLLrIbuLes vIu LIe objecL browser und LIe properLy
InspecLor. TIe 'VIew` menu provIdes un ILem 'HIde DeIuuILs.` DIsubIIng 'HIde
DeIuuILs,` LIe objecL browser sIows enLrIes Ior deIuuILs:
11-g1
TT Grophics
AL eucI node oI LIe grupIIcuI Lree, deIuuIL vuIues Ior LIe InIerILubIe uLLrIbuLes cun
be seL vIu LIe properLy InspecLor. TIese deIuuILs ure vuIId Ior uII prImILIves LIuL
exIsL beIow LIIs node, unIess LIese deIuuILs ure re-deIIned uL some oLIer node
IurLIer down In LIe Lree IIerurcIy.
TIIs mecIunIsm Is purLIcuIurIy useIuI wIen LIere ure muny prImILIves oI LIe sume
kInd In LIe pIoL. mugIne u pIcLure consIsLIng oI 1ooo poInLs. I you wIsI Lo
cIunge LIe coIor oI uII poInLs Lo green, IL wouId be quILe cumbersome Lo seL
PoinlCoior=RCB..Creen In uII 1ooo poInLs. nsLeud, you cun seL
PoinlCoior=RCB..Creen In LIe PoinlCoior deIuuILs enLry uL some Lree node LIuL
conLuIns uII LIe poInLs (e.g., LIe cunvus), eILIer dIrecLIy In LIe piol cuII or vIu LIe
objecL browserJproperLy InspecLor. SImIIurIy, II LIere ure 1ooo poInLs In one scene
und unoLIer 1ooo poInLs In u second scene, you cun cIunge LIe coIor oI uII poInLs
In LIe IIrsL scene by un upproprIuLe deIuuIL enLry In LIe IIrsL scene, wIIIsL LIe
deIuuIL enLry Ior LIe second scene cun be seL Lo u dIIIerenL vuIue. See puge 11-8
Ior un exumpIe.
11-g
Viewer, rowser, ond Inspec|or: In|eroc|ive Nonipulo|ion
A D pIoL cun be roLuLed und sIIILed by LIe mouse. AIso zoomIng In und ouL Is
possIbIe. n IucL, LIese operuLIons ure reuIIzed by movIng LIe cumeru uround,
cIoser Lo, or IurLIer uwuy Irom LIe scene, respecLIveIy. TIere Is u cumeru conLroI
LIuL muy be swILcIed on und oII vIu LIe 'Cumeru ConLroI` ILem oI LIe 'VIew` menu
or LIe cumeru Icon In LIe LooIbur. L provIdes LIe currenL vIewIng purumeLers sucI
us cumeru posILIon, IocuI poInL und LIe ungIe oI LIe cumeru Iens:
TIe secLIon sLurLIng on puge 11-11z provIdes more InIormuLIon on cumerus.
11-g
TT Grophics
FrimiIives
n LIIs secLIon, we gIve u brIeI survey oI LIe grupIIcuI prImILIves, groupIng
consLrucLs, LrunsIormuLIons eLc. provIded by LIe piol IIbrury.
TIe IoIIowIng LubIe IIsLs LIe 'Iow-IeveI` prImILIves:

ArcZd, Arc3d cIrcuIur urc,


ArroWZd, ArroW3d urrow,
Box recLunguIur box In D,
CircieZd, Circie3d cIrcIe,
Cone coneJconIcuI IrusLum In D,
Cyiinder cyIInder In D,
EiiipseZd, Eiiipse3d eIIIpse,
Eiiipsoid eIIIpsoId In D,
LineZd, Line3d (IInILe or InIInILe) IIne,
PoroiieiogromZd, Poroiieiogrom3d puruIIeIogrum,
Pione InIInLe pIune In D,
PoinlZd, Poinl3d poInL,
PoinlLislZd, PoinlLisl3d IIsL oI poInLs,
PoiygonZd, Poiygon3d IIne segmenLs IormIng u poIygon,
Reclongie recLungIe In zD,
Sphere spIere In D,
SurfoceSel surIuce In D
(us u coIIecLIon oI LrIungIes),
SurfoceSTL ImporL oI D sLI surIuces,
TexlZd, Texl3d LexL objecL.
n uddILIon, LIere ure prImILIves piol..Telrohedron, piol..|exohedron,
piol..0clohedron, piol..0odecohedron, und piol..Tcosohedron Ior PIuLo`s
reguIur poIyIedru und piol..nolermon Ior WuLermun poIyIedru.
TIe IoIIowIng LubIe IIsLs LIe 'IIgI-IeveI` prImILIves und 'specIuI purpose`
prImILIves:
11-gq
Primi|ives

BorsZd, Bors3d (sLuLIsLIcuI) duLu pIoL,


Boxpiol (sLuLIsLIcuI) box pIoL,
Conformoi pIoL oI conIormuI IuncLIons In zD,
CurveZd, Curve3d purumeLerIzed curve,
Cyiindricoi surIuce In cyIIndrIcuI coordInuLes In D,
0ensily densILy pIoL In zD,
FunclionZd, Funclion3d IuncLIon grupI,
|olch IuLcIed regIon In zD,
|islogromZd (sLuLIsLIcuI) IIsLogrum pIoL In zD,
TmpiicilZd ImpIIcILIy deIIned curves In zD,
Tmpiicil3d ImpIIcILIy deIIned surIuces In D,
Tnequoiily vIsuuIIzuLIon oI InequuIILIes In zD,
Tlerolion vIsuuIIzuLIon oI ILeruLIons In zD,
Lislpiol IInILe IIsL oI poInLs,
Lsys Indenmuyer sysLem In zD,
Molrixpiol vIsuuIIzuLIon oI muLrIces In D,
0deZd, 0de3d grupIIcuI soIuLIon oI un ODE,
PiechorlZd, Piechorl3d (sLuLIsLIcuI) pIe cIurL,
Poior curve In poIur coordInuLes In zD,
Prism prIsm In D,
Pyromid pyrumIds und LIeIr IrusLrums In D,
Piol (sLuLIsLIcuI) quunLIIe-quunLIIe pIoLs,
Rosler rusLer und bILmup pIoLs In zD,
Rooliocus dependency oI ruLIonuI rooL on purumeLer,
Scollerpiol (sLuLIsLIcuI) scuLLer pIoL In zD,
Sequence sequence (gIven by IormuIu) In zD,
SporseMolrixpiol spursILy puLLern oI u muLrIx, zD,
Sphericoi surIuce In spIerIcuI coordInuLes In D,
SlreomiinesZd vecLor IIeId vIsuuIIzuLIon In zD,
Sum vIsuuIIzuLIon oI symboIIc sums In zD,
SWeep sweep surIuce spunned by Lwo curves In D,
Tube Lube pIoL In D,
Turlie LurLIe pIoL In zD,
veclorFieidZd, veclorFieid3d vecLor IIeId pIoL,
Surfoce purumeLerIzed surIuce In D,
XRolole surIuce oI revoIuLIon In D,
ZRolole surIuce oI revoIuLIon In D.
11-gg
TT Grophics
TIe IoIIowIng LubIe IIsLs LIe vurIous IIgIL sources uvuIIubIe Lo IIIumInuLe D pIoLs:

AmbienlLighl umbIenL (undIrecLed) IIgIL,


0islonlLighl dIrecLed IIgIL (sun IIgIL),
PoinlLighl (undIrecLed) poInL IIgIL,
SpolLighl (dIrecLed) spoL IIgIL.
TIe IoIIowIng LubIe IIsLs vurIous groupIng consLrucLs:

Convos druwIng ureu,


SceneZd conLuIner Ior zD coordInuLe sysLems,
Scene3d conLuIner Ior D coordInuLe sysLems,
CoordinoleSyslemZd conLuIner Ior zD prImILIves,
CoordinoleSyslem3d conLuIner Ior D prImILIves,
CroupZd group oI prImILIves In zD,
Croup3d group oI prImILIves In D.
PrImILIves or groups oI prImILIves cun be LrunsIormed by LIe IoIIowIng objecLs:

ScoieZd, Scoie3d scuIIng,


RefieclZd, Refiecl3d reIIecLIon,
RololeZd, Rolole3d roLuLIon,
TronsioleZd, Tronsiole3d LrunsIuLIon,
TronsformZd, Tronsform3d generuI IIneur LrunsIormuLIon.
AddILIonuIIy, LIere ure:

Comero cumeru In D,
CiippingBox cIIppIng box In D.
11-g6
A||ribu|es
kIIribuIes
TIe piol IIbrury provIdes more LIun qoo uLLrIbuLes Ior IIne-LunIng oI LIe
grupIIcuI ouLpuL. Becuuse oI LIIs Iurge number, LIe uLLrIbuLes ure grouped InLo
vurIous cuLegorIes In LIe objecL browser (see puge 11-o) und LIe documenLuLIon:

cuLegory meunIng
AnImuLIon purumeLers reIevunL Ior unImuLIons
AnnoLuLIon IooLer, Ieuder, LILIes, und Iegends
Axes uxes sLyIe und uxes LILIes
CuIcuIuLIon numerIcuI evuIuuLIon
DeIInILIon purumeLers LIuL cIunge LIe objecL ILseII
GrId Ines grId IInes In LIe buckground (ruIIngs)
uyouL IuyouL purumeLers Ior cunvus und scenes
SLyIe purumeLers LIuL do noL cIunge LIe objecLs buL LIeIr
presenLuLIon (vIsIbIIILy, coIor, IIne wIdLI, poInL sIze eLc.)
Arrows sLyIe purumeLers Ior urrows
Ines sLyIe purumeLers Ior IIne objecLs
PoInLs sLyIe purumeLers Ior poInL objecLs
SurIuce sLyIe purumeLers Ior surIuce objecLs In D
und IIIIed ureus In zD
TIck Murks uxes LIck murks: sLyIe und IubeIs
On LIe IeIp puge Ior eucI prImILIve, LIere Is u compIeLe IIsL oI uII uLLrIbuLes LIe
prImILIve reucLs Lo. CIIckIng on un uLLrIbuLe, you ure Ieud Lo LIe IeIp puge Ior LIIs
uLLrIbuLe wIIcI provIdes uII LIe necessury InIormuLIon concernIng ILs semunLIcs
und udmIssIbIe vuIues. TIe exumpIes on LIe IeIp puge demonsLruLe LIe LypIcuI use
oI LIe uLLrIbuLe.
eIuolt Vuloes
MosL uLLrIbuLes Iuve u deIuuIL vuIue LIuL Is used II no vuIue Is specIIIed expIIcILIy.
As un exumpIe, we consIder LIe uLLrIbuLe Linesvisibie LIuL Is used by severuI
prImILIves sucI us piol..Box, piol..CircieZd, piol..Cone, piol..CurveZd,
piol..Rosler eLc. AILIougI LIey uII use LIe sume uLLrIbuLe numed Linesvisibie,
ILs deIuuIL vuIue dIIIers umong LIe dIIIerenL prImILIve Lypes. TIe specIIIc deIuuILs
11-g,
TT Grophics
ure uccessIbIe by pussIng LIe sIoLs piol..Box..Linesvisibie,
piol..CircieZd..Linesvisibie eLc. Lo piol..gel0efouil:
piol..gel0efouil(piol..Box..Linesvisibie}
piol..gel0efouil(piol..CircieZd..Linesvisibie}
piol..gel0efouil(piol..Cone..Linesvisibie}
piol..gel0efouil(piol..Rosler..Linesvisibie}
TRUE, TRUE, TRUE, ASE
I uny oI LIe deIuuIL vuIues provIded by LIe MuPAD

sysLem do noL seem


upproprIuLe Ior your uppIIcuLIons, cIunge LIese deIuuILs vIu piol..sel0efouil:
piol..sel0efouil(piol..Box..Linesvisibie = FALSE}
TRUE
(TIe reLurn vuIue Is LIe prevIousIy vuIId deIuuIL vuIue.) SeveruI deIuuILs cun be
cIunged sImuILuneousIy:
piol..sel0efouil(piol..Box..Linesvisibie = FALSE
piol..CircieZd..Linesvisibie = FALSE
piol..CircieZd..Fiiied = TRuE}
ASE, TRUE, ASE
piol..gel0efouil(piol..Box..Linesvisibie}
ASE
Inheritunce oI Attribotes
TIe seLLIng oI deIuuIL vuIues Ior uLLrIbuLes Is quILe sopIIsLIcuLed. Assume LIuL you
Iuve Lwo scenes LIuL ure Lo be dIspIuyed In one sIngIe cunvus. BoLI scenes consIsL
oI 1 grupIIcuI poInLs, eucI:
poinls1 .= piol..PoinlZd(i/50*PT sin(i/50*PT}} S i=0..50.
poinlsZ .= piol..PoinlZd(i/50*PT cos(i/50*PT}} S i=0..50.
S1 .= piol..SceneZd(poinls1}.
SZ .= piol..SceneZd(poinlsZ}.
11-gS
A||ribu|es
piol(S1 SZ}
I we wIsI Lo coIor uII poInLs In boLI scenes red, we cun seL u deIuuIL Ior LIe poInL
coIor In LIe piol commund:
piol(S1 SZ PoinlCoior = RCB..Red}
I we wIsI Lo coIor uII poInLs In LIe IIrsL scene red und uII poInLs In LIe second
scene bIue, we cun gIve eucI oI LIe poInLs LIe desIred coIor In LIe generuLIng cuII
Lo piol..PoinlZd. AILernuLIveIy, we cun seL sepuruLe deIuuILs Ior LIe poInL coIor
InsIde LIe scenes:
S1 .= piol..SceneZd(poinls1 PoinlCoior = RCB..Red}.
SZ .= piol..SceneZd(poinlsZ PoinlCoior = RCB..Biue}.
piol(S1 SZ}
Here Is LIe generuI ruIe Ior seLLIng deIuuILs InsIde u grupIIcuI Lree (see puge 11-q6):

WIen un uLLrIbuLe Is specIIIed In u node oI LIe grupIIcuI Lree, LIe specIIIed vuIue
serves us LIe deIuuIL vuIue Ior LIe uLLrIbuLe Ior uII prImILIves LIuL exIsL In LIe
subLree sLurLIng Irom LIuL node.
TIe deIuuIL vuIue cun be overwrILLen by unoLIer vuIue uL eucI node IurLIer down
In LIe subLree (e.g., IInuIIy, by u specIIIc vuIue In LIe prImILIves). n LIe IoIIowIng
cuII, LIe deIuuIL coIor 'red` Is seL In LIe cunvus. TIIs vuIue Is uccepLed und used In
11-gq
TT Grophics
LIe IIrsL scene. TIe second scene seLs LIe deIuuIL coIor 'bIue` overrIdIng LIe deIuuIL
vuIue 'red` seL In LIe cunvus. AddILIonuIIy, LIere Is un exLru poInL wILI u coIor
expIIcILIy seL Lo 'bIuck`. TIIs poInL Ignores LIe deIuuILs seL IurLIer up In LIe Lree
IIerurcIy:
exlropoinl .= piol..PoinlZd(1.4 0.5
PoinlSize = 3*unil..mm
PoinlCoior = RCB..Biock}.
S1 .= piol..SceneZd(poinls1 exlropoinl}.
SZ .= piol..SceneZd(poinlsZ exlropoinl
PoinlCoior = RCB..Biue}.
piol(piol..Convos(S1 SZ PoinlCoior = RCB..Red}}
TIe IoIIowIng cuII generuLes LIe sume resuIL. NoLe LIuL LIe piol commund
uuLomuLIcuIIy creuLes u cunvus objecL und pusses LIe uLLrIbuLe
PoinlCoior=RCB..Red Lo LIe cunvus:
piol(S1 SZ PoinlCoior = RCB..Red}
We noLe LIuL LIere ure dIIIerenL prImILIves LIuL reucL Lo LIe sume uLLrIbuLe. We
used Linesvisibie In LIe prevIous secLIon Lo demonsLruLe LIIs IucL. One oI LIe
ruIes Ior InIerILIng uLLrIbuLes In u grupIIcuI Lree Is:

I un uLLrIbuLe sucI us Linesvisibie=TRuE Is specIIIed In some node oI LIe


grupIIcuI Lree, cll prImILIves beIow LIIs node LIuL reucL Lo LIIs uLLrIbuLe use LIe
specIIIed vuIue us LIe deIuuIL vuIue.
I u Lype specIIIc uLLrIbuLe (usIng LIe IuIIy quuIIIIed synLux) sucI us
piol..CircieZd..Linesvisibie=TRuE Is specIIIed, LIe new deIuuIL vuIue Is
vuIId onIy Ior prImILIves oI LIuL specIIIc Lype.
n LIe IoIIowIng exumpIe, we consIder 1oo rundomIy pIuced cIrcIes wILI u
recLungIe IndIcuLIng LIe ureu InLo wIIcI uII cIrcIe cenLers ure pIuced:
reclongie .= piol..Reclongie(0..1 0 ..1}.
circies .= piol..CircieZd(0.05 _frondom(} frondom(}]}
S i = 1..100.
11-6o
A||ribu|es
piol(reclongie circies Axes = Frome}
We wIsI Lo Lurn LIe cIrcIes InLo IIIIed cIrcIes by seLLIng Fiiied=TRuE und
Linesvisibie=FALSE:
piol(reclongie circies
Fiiied = TRuE FiiiPollern = Soiid
Linesvisibie = FALSE Axes = Frome}
11-61
TT Grophics
TIIs Is noL quILe wIuL we wunLed: NoL onIy LIe cIrcIes, buL uIso LIe recLungIe
reucLs Lo LIe uLLrIbuLes Fiiied, FiiiPollern, und Linesvisibie. TIe IoIIowIng
commund resLrIcLs LIese uLLrIbuLes Lo LIe cIrcIes:
piol(reclongie circies
piol..CircieZd..Fiiied = TRuE
piol..CircieZd..FiiiPollern = Soiid
piol..CircieZd..Linesvisibie = FALSE
Axes = Frome}
Primitives Reqoesting Speciul Scene Attribotes: "Hints
TIe deIuuIL vuIues Ior LIe uLLrIbuLes ure cIosen In sucI u wuy LIuL LIey produce
reusonubIe pIcLures In LypIcuI pIoL communds. or exumpIe, LIe deIuuIL uxes
Lype In D scenes Is Axes=Boxed, becuuse LIIs Is LIe mosL upproprIuLe uxes Lype In
LIe mujorILy oI D pIoLs:
piol..gel0efouil(piol..CoordinoleSyslem3d..Axes}
Boxed
However, LIere ure excepLIons. E.g., u pIoL conLuInIng u D pIe cIurL sIouId
probubIy Iuve no uxes uL uII. SInce IL Is noL desIrubIe Lo use Axes=Wone us LIe
deIuuIL seLLIng Ior uII pIoLs, excepLIonuI prImILIves sucI us piol..Piechorl3d ure
11-6
A||ribu|es
gIven u cIunce Lo overrIde LIe deIuuIL uxes uuLomuLIcuIIy. n u pIe cIurL pIoL, no
uxes ure used by deIuuIL:
piol(piol..Piechorl3d(_Z0 30 10 7 Z0 13]
Tilies = _1 = "Z0x" Z = "30x"
3 = "10x" 4 = "7x"
5 = "Z0x" 6 = "13x"]}}
NoLe LIuL LIe uLLrIbuLe Axes LIuL Is In cIurge oI swILcIIng uxes on und oII Is u
scene uLLrIbuLe und Ience cunnoL be processed by pIe cIurL objecLs dIrecLIy.
Hence, u sepuruLe mecIunIsm Ior requesLIng specIuI scene uLLrIbuLes by prImILIves
Is ImpIemenLed: so-cuIIed IInLs.
A IInL Is un uLLrIbuLe oI one oI LIe superordInuLe nodes In LIe grupIIcuI Lree, I.e.,
un uLLrIbuLe oI u coordInuLe sysLem, u scene, or LIe cunvus. TIe IeIp puges oI LIe
prImILIves gIve InIormuLIon on wIuL IInLs ure senL by LIe prImILIve. I severuI
prImILIves send conIIIcLIng IInLs, LIe IIrsL IInL Is used.
HInLs ure ImpIemenLed InLernuIIy und cunnoL be swILcIed oII by LIe user. NoLe,
Iowever, LIuL LIe IInLs concepL onIy concerns dejcult tclues Ior uLLrIbuLes. You
cun uIwuys specIIy LIe uLLrIbuLe expIIcILIy II you LIInk LIuL u deIuuIL vuIue or u IInL
Is noL upproprIuLe.
11-6
TT Grophics
As un exumpIe, we expIIcILIy requesL Axes=Boxed In LIe IoIIowIng cuII:
piol(piol..Piechorl3d(_Z0 30 10 7 Z0 13]
Tilies = _1 = "Z0x" Z = "30x"
3 = "10x" 4 = "7x"
5 = "Z0x" 6 = "13x"]}
Axes = Boxed}
11-6q
A||ribu|es
The Help Puges oI Attribotes
We Iuve u brIeI Iook uL u LypIcuI IeIp puge Ior u pIoL uLLrIbuLe Lo expIuIn LIe
InIormuLIon provIded LIere:

uMesh vMesh uSubmesh vSubmesh - nomber oI sumple


points
TIe uLLrIbuLes uMesh eLc. deLermIne LIe number oI sumpIe poInLs used Ior LIe
numerIcuI upproxImuLIon oI purumeLerIzed pIoL objecLs sucI us curves und
surIuces.
Ixumples
ALLrIbuLe Type VuIue
USubmesI, VSubmesI InIerILed non-neguLIve InLeger
UMesI, VMesI InIerILed posILIve InLeger
See Also
AdopliveMesh, Mesh, Submesh, XMesh, YMesh, ZMesh
Objects reucting to uMesh, vMesh, uSubmesh, vSubmesh
piol..Surfoce, piol..Cyiindricoi,
piol..XRolole, piol..Sphericoi,
piol..ZRolole
z (uMesh, vMesh)
o (uSubmesh,
vSubmesh)
piol..Tube 6o (uMesh)
11 (vMesh)
o (uSubmesh)
1 (VSubmesI)
.
etuil
Muny pIoL objecLs Iuve Lo be evuIuuLed numerIcuIIy on u dIscreLe mesI.
.
Ixumple 1 .
11-6g
TT Grophics
n LIese IeIp puges,
LIe LubIe enLry Type (InIerILed) sLuLes LIuL LIese uLLrIbuLes muy noL onIy
be specIIIed In LIe generuLIng cuII oI grupIIcuI prImILIves. TIey cun uIso be
specIIIed uL IIgIer nodes oI u grupIIcuI Lree Lo be InIerILed by LIe prImILIves
In LIe correspondIng subLree (see puge 11-8).
LIe LubIe enLry Vuloe sLuLes LIe Lype oI LIe number n LIuL Is udmIssIbIe
wIen pussIng LIe uLLrIbuLes uMesh=n, vMesh=n eLc.
LIe secLIons Object types reucting to uMesh eLc. provIde compIeLe
IIsLIngs oI uII prImILIves reucLIng Lo LIe uLLrIbuLe(s) LogeLIer wILI LIe specIIIc
deIuuIL vuIues.
LIe etuils secLIon gIves IurLIer InIormuLIon on LIe semunLIcs oI LIe
uLLrIbuLe(s). InuIIy, LIere ure Ixumples oI pIoL communds usIng LIe
descrIbed uLLrIbuLe(s).
11-66
Colors
felers
TIe mosL promInenL pIoL uLLrIbuLe, uvuIIubIe Ior uImosL uII prImILIves, Is Coior,
seLLIng LIe 'prImury` coIor oI un objecL. MuPAD

`s piol IIbrury knows dIIIerenL


Lypes oI prImury coIors:
TIe uLLrIbuLe PoinlCoior reIers Lo LIe coIor oI poInLs In zD und D (oI Lype
piol..PoinlZd und piol..Poinl3d, respecLIveIy).
TIe uLLrIbuLe LineCoior reIers Lo LIe coIor oI IIne objecLs In zD und D. TIIs
IncIudes LIe coIor oI IuncLIon grupIs In zD, curves In zD und D, poIygon
IInes In zD und D eLc. AIso D objecLs sucI us IuncLIon grupIs In D,
purumeLrIzed surIuces eLc. reucL Lo LIe uLLrIbuLe LineCoior; IL deIInes LIe
coIor oI LIe coordInuLe mesI IInes LIuL ure dIspIuyed on LIe surIuce.
TIe uLLrIbuLe FiiiCoior reIers Lo LIe coIor oI cIosed und IIIIed poIygons In
zD und D us weII us IuLcIed regIons In zD. urLIer, IL seLs LIe surIuce coIor
oI IuncLIon grupIs In D, purumeLrIzed surIuces eLc. TIIs IncIudes spIeres,
cones eLc.
TIe prImILIves uIso uccepL LIe uLLrIbuLe Coior us u sIorLcuL Ior one oI LIese coIors.
DependIng on LIe prImILIve, eILIer PoinlCoior, LineCoior, or FiiiCoior Is seL
wILI LIe Coior uLLrIbuLe.
RGB Colors
MuPAD

uses LIe RGB coIor modeI, I.e., coIors ure specIIIed by IIsLs _rgb] oI
red, green, und bIue vuIues beLween 0 und 1, or In HTM synLux us u IusI murk
IoIIowed by u sIx-dIgIL IexudecImuI number, us In #cc0099. BIuck und wIILe
correspond Lo _000] (#000000) und _111] (#ffffff), respecLIveIy. TIe
IIbrury RCB conLuIns numerous coIor numes wILI correspondIng RGB vuIues:
RCB..Biock RCB..nhile RCB..Red RCB..SkyBiue
[0.0, 0.0, 0.0] , [1.0, 1.0, 1.0] , [1.0, 0.0, 0.0] , [0.0, 0.8, 1.0]
IsL uII coIor numes uvuIIubIe In LIe RCB IIbrury vIu info(RCB}. AILernuLIveIy, LIere
Is LIe commund RCB..CoiorWomes(} reLurnIng u compIeLe IIsL oI numes. WILI
11-6,
TT Grophics
RCB..CoiorWomes(Red}
_CodmiumRed0eep CodmiumRedLighl CordinoiRed
CormineRed 0orkRed EngiishRed TndionRed
0rongeRed PermonenlRedvioiel Red venelionRed
vioielRed vioielRedMedium vioielRedPoie]
one seurcIes Ior uII coIor numes LIuL conLuIn 'Red.` To ucLuuIIy see LIe coIors
Iound, use RCB..piolCoiorPoielle:
RCB..piolCoiorPoielle("red"}
AILer exporLIng LIe coIor IIbrury vIu use(RCB}, you cun use LIe coIor numes In LIe
sIorL Iorm Biock, nhile, TndionRed eLc. NoLe, Iowever, LIuL LIIs commund wIII
ussIgn vuIues Lo u IILLIe over 350 IdenLIIIers, precIudIng LIeIr use In oLIer meunIngs.
RGBu coIor vuIues consIsL oI IIsLs _rgbo] conLuInIng u IourLI enLry: LIe
opucILy vuIue a beLween 0 und 1. (n HTM-IIke noLuLIon, LIe IexudecImuI
specIIIcuLIon Ius eIgIL cIurucLers.) or a = 0, u surIuce puLcI puInLed wILI LIIs
RGBu coIor Is IuIIy LrunspurenL (I.e., InvIsIbIe). or a = 1, LIe surIuce puLcI Is
opuque, I.e., IL IIdes pIoL objecLs LIuL ure beIInd IL. or 0 < a < 1, LIe surIuce
puLcI Is semI-LrunspurenL, I.e., pIoL objecLs beIInd IL sIIne LIrougI.
RGBu coIor vuIues cun be consLrucLed eusIIy vIu LIe RCB IIbrury. One onIy Ius Lo
uppend u IourLI enLry Lo LIe [r, g, b] IIsLs provIded by LIe coIor numes. TIe eusIesL
11-6S
Colors
wuy Lo do LIIs Is Lo uppend LIe IIsL [a] Lo LIe RGB IIsL vIu LIe concuLenuLIon
operuLor '.`. We creuLe u semI-LrunspurenL gruy:
RCB..Croy._0.5]
[0.752907, 0.752907, 0.752907, 0.5]
TIe IoIIowIng commund pIoLs u IIgIIy LrunspurenL red box, conLuInIng u
somewIuL Iess LrunspurenL green box wILI un opuque bIue box InsIde:
piol(piol..Box(-3..3 -3..3 -3..3
FiiiCoior = RCB..Red._0.Z]}
piol..Box(-Z..Z -Z..Z -Z..Z
FiiiCoior = RCB..Creen._0.3]}
piol..Box(-1..1 -1..1 -1..1
FiiiCoior = RCB..Biue}
Linesvisibie = TRuE LineCoior = RCB..Biock
Scoiing = Conslroined}
HSV Colors
BesIdes LIe RGB modeI, LIere ure vurIous oLIer popuIur coIor IormuLs used In
compuLer grupIIcs. One Is LIe HSV modeI (Hue, SuLuruLIon, VuIue). TIe RCB
IIbrury provIdes LIe rouLInes RCB..from|Sv und RCB..lo|Sv Lo converL HSV
11-6q
TT Grophics
coIors Lo RGB coIors und vIce versu:
hsv .= RCB..lo|Sv(RCB..0ronge}
[24.0, 1.0, 1.0]
RCB..from|Sv(hsv} = RCB..0ronge
[1.0, 0.4, 0.0] = [1.0, 0.4, 0.0]
WILI LIe RCB..from|Sv uLIIILy, uII coIors In u MuPAD pIoL cun be specIIIed eusIIy
us HSV coIors. or exumpIe, LIe coIor 'vIoIeL` Is gIven by LIe HSV vuIues
_Z900.40.6], wIereus 'durk green` Is gIven by LIe HSV specIIIcuLIon
_1Z010.4] (1zo Ior 'green,` o.q Ior 'durk`). Hence, u semI-LrunspurenL vIoIeL
spIere InLersecLed by un opuque durk green pIune muy be specIIIed us IoIIows:
piol(piol..Sphere(1 _0 0 0]
Coior = RCB..from|Sv(_Z90 0.4 0.6 0.5]}}
piol..Surfoce(_x y 0.5] x = -1..1 y = -1..1
Mesh = _Z Z]
Coior = RCB..from|Sv(_1Z0 1 0.4]}}}
11-,o
Animo|ions
kaimuIieas
Generuting Simple Animutions
EucI prImILIve oI LIe piol IIbrury knows Iow muny specIIIcuLIons oI Lype runge
IL Ius Lo expecL.

Wheneter c rcphiccl primitite receites c surplus rcne specijicction b


cn equction such cs o=omin..omox, the pcrcmeter o is interpreted cs cn cn-
imction pcrcmeter cssumin tclues jrom omin to omox.
WIuL Is u surpIus runge? TIIs Is u specIIIcuLIon LIuL Is noL necessury Ior
generuLIng u sLuLIc objecL. or exumpIe, u sLuLIc unIvurIuLe IuncLIon grupI In zD
sucI us
piol..FunclionZd(sin(x} x = 0..Z*PT}.
expecLs one pIoL runge Ior LIe x coordInuLe, wIereus u sLuLIc bI-vurIuLe IuncLIon
grupI In D expecLs Lwo pIoL runges Ior LIe x und y coordInuLe:
piol..Funclion3d(sin(x^Z + y^Z} x = 0..Z y = 0..Z}.
A sLuLIc conLour pIoL In zD expecLs z runges Ior LIe x und y coordInuLe:
piol..TmpiicilZd(x^Z + y^Z - 1 x = -Z..Z y = -Z..Z}.
A sLuLIc conLour pIoL In D expecLs runges Ior LIe x, y, und z coordInuLe:
piol..Tmpiicil3d(x^Z + y^Z + z^Z - 1 x = -Z..Z
y = - Z..Z z = - Z..Z}.
Any uddILIonuI equuLIon InvoIvIng u runge mukes LIe prImILIve creuLe un
unImuLIon. SInce u sLuLIc zD IuncLIon grupI expecLs onIy one runge (Ior LIe
IndependenL vurIubIe), LIe IoIIowIng cuII Is InLerpreLed us un InsLrucLIon Lo
generuLe un unImuLed zD IuncLIon grupI:
piol..FunclionZd(sin(x - o} x = 0..Z*PT o = 0..Z*PT}.
TIus, IL Is very eusy Indeed Lo creuLe unImuLed objecLs: jusL puss u surpIus runge
equuLIon o=omin..omox Lo LIe generuLIng cuII oI LIe prImILIve. TIe nume o oI LIe
unImuLIon purumeLer Is IrreIevunL; uny symboIIc nume muy be used. AII oLIer
11-,1
TT Grophics
enLrIes und uLLrIbuLes oI LIe prImILIve LIuL ure symboIIc expressIons oI LIe
unImuLIon purumeLer wIII be unImuLed. n LIe IoIIowIng cuII, boLI LIe IuncLIon
expressIon us weII us LIe x runge oI LIe IuncLIon grupI depend on LIe unImuLIon
purumeLer. AIso, LIe runges deIInIng LIe wIdLI und LIe IeIgIL oI LIe recLungIe us
weII us LIe end poInL oI LIe IIne depend on IL:
piol(piol..FunclionZd(o*sin(x} x = 0..o*PT o = 0.5..1}
piol..Reclongie(0..o*PT 0..o o = 0.5..1
LineCoior = RCB..Biock}
piol..LineZd(_0 0] _PT*o o] o = 0.5 ..1
LineCoior = RCB..Biock}}
11-,
Animo|ions
Here Is un unImuLed urc wIose rudIus und ungIe runge depend on LIe unImuLIon
purumeLer:
piol(piol..ArcZd(1 + o _0 0] AngieRonge = 0..o*PT
o = 0..1}}
Here, un uddILIonuI runge specIIIcuLIon Ior LIe uLLrIbuLe AngieRonge Is used.
However, LIe uLLrIbuLe Is IdenLIIIed by ILs nume us un udmIssIbIe uLLrIbuLe Ior LIe
prImILIve und LIus noL ussumed Lo be LIe specIIIcuLIon oI un unImuLIon purumeLer.

Bewure! Do mcle sure thct cttributes cre specijied b their correct ncmes.
Ij cn incorrect cttribute ncme is used, it mc be mistclen jor cn cnimction
pcrcmeterl
n LIe IoIIowIng exumpIes, we wIsI Lo deIIne u sLuLIc semI-cIrcIe, usIng
piol..ArcZd wILI AngieRonge=0..PT. However, AngieRonge Is speIIed
IncorrecLIy. A pIoL Is creuLed. L Is un unImuLed IuII cIrcIe wILI LIe unImuLIon
purumeLer AngeiRonge!
piol(piol..ArcZd(1 _0 0] AngeiRonge = 0..PT}}
TIe unImuLIon purumeLer muy be uny symboIIc purumeLer (IdenLIIIer or Indexed
IdenLIIIer) LIuL Is dIIIerenL Irom LIe symboIs used Ior LIe munduLory runge
11-,
TT Grophics
specIIIcuLIons (sucI us LIe numes oI LIe IndependenL vurIubIes In IuncLIon
grupIs). TIe purumeLer musL uIso be dIIIerenL Irom uny oI LIe proLecLed numes oI
LIe pIoL uLLrIbuLes.

Animctions cre crected object b object. The ncmes oj the cnimction pcrcm-
eters in dijjerent objects need not coincide.
n LIe IoIIowIng exumpIe, dIIIerenL numes o und b ure used Ior LIe unImuLIon
purumeLers oI LIe Lwo IuncLIons:
piol(piol..FunclionZd(4*o*x x = 0..1 o = 0..1}
piol..FunclionZd(b*x^Z x = 0..1 b = 1..4}}
An unImuLIon purumeLer Is u gIobuI symboIIc nume. L cun be used us u gIobuI
vurIubIe In procedures deIInIng LIe grupIIcuI objecL. TIe IoIIowIng exumpIe
IeuLures LIe D grupI oI u bI-vurIuLe IuncLIon LIuL Is deIIned by u procedure usIng
LIe gIobuIIy deIIned unImuLIon purumeLer. urLIer, u IIII coIor IuncLIon mycoior Is
deIIned LIuL cIunges LIe coIor In LIe course oI LIe unImuLIon. L couId use LIe
unImuLIon purumeLer us u gIobuI purumeLer, jusL IIke LIe IuncLIon f does.
AILernuLIveIy, LIe unImuLIon purumeLer muy be decIured us un uddILIonuI InpuL
purumeLer. ReIer Lo LIe IeIp puge oI FiiiCoiorFunclion Lo IInd ouL Iow muny
InpuL purumeLers LIe IIII coIor IuncLIon expecLs und wIIcI oI LIe InpuL purumeLers
11-,q
Animo|ions
receIves LIe unImuLIon purumeLer. One IInds LIuL Ior Funclion3d, LIe IIII coIor
IuncLIon Is cuIIed wILI LIe coordInuLes x, y, z oI LIe poInLs on LIe grupI. TIe nexL
InpuL purumeLer (LIe qLI urgumenL oI mycoior) Is LIe unImuLIon purumeLer:
f .= (x y} -> 4 - (x - o}^Z - (y - o}^Z.
mycoior .= proc(x y z o}
iocoi l
begin
l .= sqrl((x - o}^Z + (y - o}^Z}.
if l < 0.1 lhen relurn(RCB..Red}
eiif l < 0.4 lhen relurn(RCB..0ronge}
eiif l < 0.7 lhen relurn(RCB..Creen}
eise relurn(RCB..Biue}
endif
end.
piol(piol..Funclion3d(f x = -1..1 y = -1..1 o = -1..1
FiiiCoiorFunclion = mycoior}}
Pluying Animutions
WIen un unImuLed pIoL Is creuLed In u MuPAD

noLebook, LIe IIrsL Irume oI LIe


unImuLIon uppeurs us u sLuLIc pIcLure beIow LIe InpuL regIon. To sLurL LIe
11-,g
TT Grophics
unImuLIon, cIIck on LIe pIoL. An Icon Ior sLoppIng und re-sLurLIng LIe unImuLIon
wIII uppeur (muke sure LIe ILem 'AnImuLIon Bur` oI LIe 'VIew` menu Is enubIed):
One cun uIso use LIe sIIder Lo unImuLe LIe pIcLure by Iund.
The Nomber oI Irumes und the Time Runge
By deIuuIL, un unImuLIon consIsLs oI o Irumes. TIe number oI Irumes cun be seL
Lo be uny posILIve number n by specIIyIng LIe uLLrIbuLe Fromes=n. TIIs uLLrIbuLe
cun be seL In LIe generuLIng cuII oI LIe unImuLed prImILIves, or uL some IIgIer
node oI LIe grupIIcuI Lree. n LIe IuLLer cuse, LIIs uLLrIbuLe Is InIerILed by uII
prImILIves LIuL exIsL beIow LIe node. WILI o=omin..omox, Fromes=n, LIe i-LI
Irume consIsLs oI u snupsIoL oI LIe prImILIve wILI
a = a
mIn
+
i 1
n 1
(a
mux
a
mIn
), i = 1, . . . , n.
ncreusIng LIe number oI Irumes does noL meun LIuL LIe unImuLIon runs Ionger;
LIe renderer does noL work wILI u IIxed number oI Irumes per second buL
processes uII Irumes wILIIn u IIxed LIme InLervuI.
11-,6
Animo|ions
n LIe buckground, LIere Is u reuI LIme cIock used Lo syncIronIze LIe unImuLIon
oI dIIIerenL unImuLed objecLs. An unImuLIon Ius u LIme runge meusured by LIIs
cIock. TIe LIme runge Is seL by LIe uLLrIbuLes TimeBegin=l0, TimeEnd=l1 or,
equIvuIenLIy, TimeRonge=l0..l1, wIere l0, l1 ure reuI numerIcuI vuIues
represenLIng pIysIcuI LImes In seconds. TIese uLLrIbuLe cun be seL In LIe
generuLIng cuII oI LIe unImuLed prImILIves, or uL some IIgIer node oI LIe grupIIcuI
Lree. n LIe IuLLer cuse, LIese uLLrIbuLes ure InIerILed by uII prImILIves LIuL exIsL
beIow LIe node.
TIe ubsoIuLe vuIue oI l0 Is IrreIevunL II uII unImuLed objecLs sIure LIe sume LIme
runge. OnIy LIe LIme dIIIerence l1-l0 muLLers. L Is (un upproxImuLIon oI) LIe
pIysIcuI LIme In seconds LIuL LIe unImuLIon wIII IusL.

The pcrcmeter rcne omin..omox in the specijicction oj the cnimction pcrcm-


eter o=omin..omox toether uith Fromes=n dejines cn equidistcnt time mesh
in the time intertcl set b TimeBegin=l0 cnd TimeEnd=l1. The jrcme uith
o=omin is tisible ct the time l0, the jrcme uith o=omox is tisible ct the time
l1.

With the dejcult TimeBegin=0, the tclue oj the cttribute TimeEnd ites the
phsiccl time oj the cnimction in seconds. The dejcult tclue is TimeEnd=10,
i.e., cn cnimction usin the dejcult tclues uill lcst cbout :o seconds. The
number oj jrcmes set b Fromes=n does not injluence the time intertcl, but
chcnes the number oj jrcmes displced in this time intertcl.
Here Is u sImpIe exumpIe:
piol(piol..PoinlZd(_o sin(o}] o = 0..Z*PT
Fromes = 50 TimeRonge = 0..5}}
TIe poInL wIII be unImuLed Ior ubouL pIysIcuI seconds In wIIcI IL moves uIong
one perIod oI LIe sIne grupI. EucI Irume Is dIspIuyed Ior ubouL o.1 seconds. AILer
IncreusIng LIe number oI Irumes by u IucLor oI z, eucI Irume Is dIspIuyed Ior ubouL
o.o seconds, mukIng LIe unImuLIon somewIuL smooLIer:
piol(piol..PoinlZd(_o sin(o}] o = 0..Z*PT
Fromes = 100 TimeRonge = 0..5}}
11-,,
TT Grophics
NoLe LIuL LIe Iumun eye cunnoL dIsLInguIsI beLween dIIIerenL Irumes II LIey
cIunge wILI u ruLe oI more LIun z Irumes per second. TIus, LIe number oI
Irumes n seL Ior LIe unImuLIon sIouId suLIsIy
n < 25 (t
1
t
0
).
Hence, wILI LIe deIuuIL LIme runge TimeBegin=0, TimeEnd=10 (seconds), IL does
noL muke sense Lo specIIy Fromes=n wILI n > 250. I u IIgIer Irume number Is
requIred Lo obLuIn u suIIIcIenL resoIuLIon oI LIe unImuLed objecL, one sIouId uIso
Increuse LIe LIme Ior LIe unImuLIon by u suIIIcIenLIy IIgI vuIue oI TimeEnd.
Whut Cun Be Animuted?
We muy regurd u grupIIcuI prImILIve us u coIIecLIon oI pIoL uLLrIbuLes. (TIIs Is
ucLuuIIy wIuL LIey ure InLernuIIy. ndeed, even LIe IuncLIon expressIon sin(x} In
piol..FunclionZd(sin(x}x=0..Z*PT} Is reuIIzed us LIe uLLrIbuLe
Funclion=sin(x}.) So, LIe quesLIon Is:
Which cttributes ccn be cnimcted?
TIe unswer Is: Almost cn cttribute ccn be cnimctedl nsLeud oI IIsLIng LIe
uLLrIbuLes LIuL uIIow unImuLIon, IL Is mucI eusIer Lo cIurucLerIze LIe uLLrIbuLes
LIuL cunnoL be unImuLed:
None oI LIe cunvus uLLrIbuLes cun be unImuLed. TIIs IncIudes IuyouL
purumeLers sucI us LIe pIysIcuI sIze oI LIe pIcLure. See LIe IeIp puge oI
piol..Convos Ior u compIeLe IIsL oI uII cunvus uLLrIbuLes.
None oI LIe uLLrIbuLes oI zD scenes und D scenes cun be unImuLed. TIIs
IncIudes IuyouL purumeLers, buckground coIor und sLyIe, uuLomuLIc cumeru
posILIonIng In D eLc. See LIe IeIp puges oI piol..SceneZd und
piol..Scene3d Ior u compIeLe IIsL oI uII scene uLLrIbuLes.
NoLe LIuL LIere ure cumeru objecLs oI Lype piol..Comero LIuL cun be pIuced
In u D scene. TIese cumeru objecLs cun be unImuLed und uIIow Lo reuIIze u
IIIgIL LIrougI u D scene. See SecLIon 11.16 Ior deLuIIs.
None oI LIe uLLrIbuLes oI zD coordInuLe sysLems und D coordInuLe sysLems
cun be unImuLed. TIIs IncIudes vIewIng boxes, uxes, uxes LIcks, und grId
11-,S
Animo|ions
IInes (ruIIngs) In LIe buckground. See LIe IeIp puges oI
piol..CoordinoleSyslemZd und piol..CoordinoleSyslem3d Ior u
compIeLe IIsL oI uII uLLrIbuLes Ior coordInuLe sysLems.
AILIougI LIe vieWingBox uLLrIbuLe oI u coordInuLe sysLem cunnoL be
unImuLed, LIe user cun sLIII ucIIeve unImuLed vIsIbIIILy eIIecLs In D by
cIIppIng box objecLs oI Lype piol..CiippingBox.
None oI LIe uLLrIbuLes LIuL ure decIured us Attribote Type: inherited
on LIeIr IeIp puge cun be unImuLed. TIIs IncIudes sIze specIIIcuLIons sucI us
PoinlSize, Linenidlh eLc.
RGB und RGBu vuIues cunnoL be unImuLed. However, IL Is possIbIe Lo
unImuLe LIe coIorIng oI IInes und surIuces vIu user deIIned procedures. See
LIe IeIp puges oI LineCoiorFunclion und FiiiCoiorFunclion Ior deLuIIs.
TIe LexLs oI unnoLuLIons sucI us Fooler, |eoder, Tilie, Iegend enLrIes eLc.
cunnoL be unImuLed. TIe posILIon oI LILIes, Iowever, cun be unImuLed.
TIere ure specIuI LexL objecLs piol..TexlZd und piol..Texl3d LIuL uIIow Lo
unImuLe LIe LexL us weII us LIeIr posILIon.
onLs cunnoL be unImuLed.
ALLrIbuLes sucI us 0isconlinuilySeorch=TRuE or FiiiPollern=Soiid LIuL
cun ussume onIy IInILeIy muny vuIues Irom u IIxed dIscreLe seL cunnoL be
unImuLed.
NeurIy uII uLLrIbuLes noL IuIIIng InLo one oI LIese cuLegorIes cun be unImuLed. You
wIII IInd deLuIIed InIormuLIon on LIIs Issue on LIe correspondIng IeIp puges oI
prImILIves und uLLrIbuLes.
Advunced Animutions: The Synchronizution Model
As uIreudy expIuIned on puge 11-;6, LIere Is u reuI LIme cIock runnIng In LIe
buckground LIuL syncIronIzes LIe unImuLIon oI dIIIerenL unImuLed objecLs.
EucI unImuLed objecL Ius ILs own sepuruLe reuI LIme IIIe spun seL by LIe
uLLrIbuLes TimeBegin=l0, TimeEnd=l1 or, equIvuIenLIy, TimeRonge=l0..l1. TIe
vuIues l0, l1 represenL seconds meusured by LIe reuI LIme cIock.
11-,q
TT Grophics
n mosL cuses, LIere Is no need Lo boLIer ubouL specIIyIng LIe IIIe spun. I
TimeBegin und TimeEnd ure noL specIIIed, LIe deIuuIL vuIues TimeBegin=0 und
TimeEnd=10 ure used, I.e., LIe unImuLIon wIII IusL ubouL 1o seconds. TIese vuIues
onIy need Lo be modIIIed
II u sIorLer or Ionger reuI LIme perIod Ior LIe unImuLIon Is desIred, or
II LIe unImuLIon conLuIns severuI unImuLed objecLs, wIere some oI LIe
unImuLed objecLs ure Lo remuIn sLuLIc wIIIe oLIers cIunge.
Here Is un exumpIe Ior LIe second sILuuLIon. TIe pIoL consIsLs oI jumpIng poInLs.
or LIe IIrsL seconds, LIe IeIL poInL jumps up und down, wIIIe LIe oLIer poInLs
remuIn uL LIeIr InILIuI posILIon. TIen, uII poInLs sLuy sLuLIc Ior 1 second. AILer u
LoLuI oI 6 seconds, LIe mIddIe poInL sLurLs ILs unImuLIon by jumpIng up und down,
wIIIe LIe IeIL poInL remuIns sLuLIc In ILs IInuI posILIon und LIe rIgIL poInLs sLuys
sLuLIc In ILs InILIuI posILIon. AILer q seconds, LIe rIgIL poInL begIns Lo move us weII.
TIe overuII LIme spun Ior LIe unImuLIon Is LIe IuII oI LIe LIme runges oI uII
unImuLed objecLs, I.e., 1 seconds In LIIs exumpIe:
p1 .= piol..PoinlZd(-1 sin(o} o = 0..PT
Coior = RCB..Red
TimeBegin = 0 TimeEnd = 5}.
pZ .= piol..PoinlZd(0 sin(o} o = 0..PT
Coior = RCB..Biock
TimeBegin = 6 TimeEnd = 1Z}.
p3 .= piol..PoinlZd(1 sin(o} o = 0..PT
Coior = RCB..Biue
TimeBegin = 9 TimeEnd = 15}.
11-So
Animo|ions
piol(p1 pZ p3 PoinlSize = .0*unil..mm
YAxisvisibie = FALSE}
Here, uII poInLs use LIe deIuuIL seLLIngs visibieBeforeBegin=TRuE und
visibieAflerEnd=TRuE wIIcI muke LIem vIsIbIe us sLuLIc objecLs ouLsIde LIe
LIme runge oI LIeIr unImuLIon. We seL visibieAflerEnd=FALSE Ior LIe mIddIe
poInL, so LIuL IL dIsuppeurs uILer LIe end oI ILs unImuLIon. WILI
visibieBeforeBegin=FALSE, LIe rIgIL poInL Is noL vIsIbIe unLII ILs unImuLIon
sLurLs:
pZ..visibieAflerEnd .= FALSE.
p3..visibieBeforeBegin .= FALSE.
11-S1
TT Grophics
piol(p1 pZ p3 PoinlSize = .0*unil..mm
YAxisvisibie = FALSE}
We summurIze LIe syncIronIzuLIon modeI oI unImuLIons:

The totcl recl time spcn oj cn cnimcted plot is the phsiccl recl time iten b
the minimum oj the TimeBegin tclues oj cll cnimcted objects in the plot to the
mcximum oj the TimeEnd tclues oj cll the cnimcted objects.
WIen u pIoL conLuInIng unImuLed objecLs Is creuLed, LIe reuI LIme cIock Is seL
Lo LIe mInImum oI LIe TimeBegin vuIues oI uII unImuLed objecLs In LIe pIoL.
TIe reuI LIme cIock Is sLurLed wIen pusIIng LIe 'pIuy` buLLon Ior unImuLIons
In LIe grupIIcuI user InLerIuce.
BeIore LIe reuI LIme reucIes LIe TimeBegin vuIue l0 oI un unImuLed objecL,
LIIs objecL Is sLuLIc In LIe sLuLe correspondIng Lo LIe begIn oI ILs unImuLIon.
DependIng on LIe uLLrIbuLe visibieBeforeBegin, IL muy be vIsIbIe or
InvIsIbIe beIore l0.
DurIng LIe LIme Irom l0 Lo l1, LIe objecL cIunges Irom ILs orIgInuI Lo ILs IInuI
sLuLe.
11-S
Animo|ions
AILer LIe reuI LIme reucIes LIe TimeEnd vuIue l1, LIe objecL sLuys sLuLIc In LIe
sLuLe correspondIng Lo LIe end oI ILs unImuLIon. DependIng on LIe vuIue oI
LIe uLLrIbuLe visibieAflerEnd, IL muy sLuy vIsIbIe or become InvIsIbIe uILer
l1.
TIe unImuLIon oI LIe enLIre pIoL ends wILI LIe pIysIcuI LIme gIven by LIe
muxImum oI LIe TimeEnd vuIues oI uII unImuLed objecLs In LIe pIoL.
Irume by Irume Animutions
TIere ure some specIuI uLLrIbuLes sucI us visibieAfler LIuL ure very useIuI Lo
buIId unImuLIons Irom pureIy sLuLIc objecLs:

With visibieAfler=l0, cn object is intisible jrom the stcrt oj the cnimction


until time l0. Then it uill cppecr cnd remcin tisible jor the rest oj the cnimc-
tion.

With visibieBefore=l1, cn object is tisible jrom the stcrt oj the cnimction


until time l1. Then it uill discppecr cnd remcin intisible jor the rest oj the
cnimction.
TIese uLLrIbuLes sIouId noL be combIned Lo deIIne u vIsIbIIILy runge Irom l0 Lo
l1. Use LIe uLLrIbuLe visibieFromTo InsLeud:

With visibieFromTo=l0..l1, cn object is intisible jrom the stcrt oj the cn-


imction until time l0. Then it uill cppecr cnd remcin tisible until time l1,
uhen it uill discppecr cnd remcin intisible jor the rest oj the cnimction.
We conLInue LIe exumpIe oI LIe prevIous secLIon In wIIcI we deIIned LIe
IoIIowIng unImuLed poInLs:
11-S
TT Grophics
p1 .= piol..PoinlZd(-1 sin(o} o = 0..PT
Coior = RCB..Red
TimeBegin = 0 TimeEnd = 5}.
pZ .= piol..PoinlZd(0 sin(o} o = 0..PT
Coior = RCB..Biock
TimeBegin = 6 TimeEnd = 1Z}.
p3 .= piol..PoinlZd(1 sin(o} o = 0..PT
Coior = RCB..Biue
TimeBegin = 9 TimeEnd = 15}.
pZ..visibieAflerEnd .= FALSE.
p3..visibieBeforeBegin .= FALSE.
We udd u IurLIer poInL p4 LIuL Is noL unImuLed. We muke IL InvIsIbIe uL LIe sLurL oI
LIe unImuLIon vIu LIe uLLrIbuLe visibieFromTo. L Is mude vIsIbIe uILer ; seconds
Lo dIsuppeur uguIn uILer 1 seconds:
p4 .= piol..PoinlZd(0.5 0.5 Coior = RCB..Biock
visibieFromTo = 7..13}.
TIe sLurL oI LIe unImuLIon Is deLermIned by p1 wIIcI beurs LIe uLLrIbuLe
TimeBegin=0, LIe end oI LIe unImuLIon Is deLermIned by p3 wIIcI Ius seL
TimeEnd=15:
piol(p1 pZ p3 p4 PoinlSize = .0*unil..mm
YAxisvisibie = FALSE}
11-Sq
Animo|ions
AILIougI u LypIcuI MuPAD unImuLIon Is generuLed objecL by objecL, eucI unImuLed
objecL LukIng cure oI ILs own unImuLIon, we cun uIso use LIe uLLrIbuLes
visibieAfler, visibieBefore, visibieFromTo Lo buIId up un unImuLIon Irume by
Irume:

"Irume by Irume unimutions: Choose c collection oj (tpiccll stctic)


rcphiccl primitites thct cre to be tisible in the i-th jrcme oj the cnimction.
Set visibieFromTo=l_i]..l_i+1] jor these primitites, uhere l_i]..l_i+1]
is the recl time lije spcn oj the i-th jrcme (in seconds). Iincll, plot cll jrcmes
in c sinle piol commcnd.
Here Is un exumpIe. We IeL Lwo poInLs wunder uIong LIe grupIs oI LIe sIne und LIe
cosIne IuncLIon, respecLIveIy. EucI Irume Is Lo consIsL oI u pIcLure oI Lwo poInLs.
We use piol..CroupZd Lo deIIne LIe Irume; LIe group Iorwurds LIe uLLrIbuLe
visibieFromTo Lo uII ILs eIemenLs:
for i from 0 lo 101 do
l_i] .= i/10
endfor.
for i from 0 lo 100 do
x .= i/100*PT
myfrome_i] .= piol..CroupZd(
piol..PoinlZd(_x sin(x}] Coior = RCB..Red}
piol..PoinlZd(_x cos(x}] Coior = RCB..Biue}
visibieFromTo = l_i]..l_i + 1]}
endfor.
11-Sg
TT Grophics
piol(myfrome_i] S i = 0..100 PoinlSize = 7.0*unil..mm}
TIIs Irume by Irume unImuLIon cerLuInIy needs u IILLIe bIL more codIng eIIorL
LIun LIe equIvuIenL objecL-wIse unImuLIon, wIere eucI oI LIe poInLs Is unImuLed.
11-S6
Animo|ions
Compure:
deiele i.
piol(piol..PoinlZd(_i/100*PT sin(i/100*PT}]
i = 0..100 Coior = RCB..Red}
piol..PoinlZd(_i/100*PT cos(i/100*PT}]
i = 0..100 Coior = RCB..Biue}
Fromes = 101 PoinlSize = 7.0*unil..mm}
TIere Is u specIuI kInd oI pIoL wIere Irume by Irume unImuLIons ure very useIuI.
NoLe LIuL In LIe presenL versIon oI LIe grupIIcs, new pIoL objecLs cunnoL be udded
Lo u scene LIuL Is uIreudy rendered. WILI LIe specIuI vIsIbIIILy unImuLIons Ior
sLuLIc objecLs, Iowever, one cun eusIIy sImuIuLe u pIoL LIuL gruduuIIy buIIds up: IIII
LIe Irumes oI LIe unImuLIon wILI sLuLIc objecLs LIuL ure vIsIbIe Ior u IImILed LIme
onIy. TIe vIsIbIIILy cun be cIosen very IIexIbIy by LIe user. or exumpIe, LIe sLuLIc
objecLs cun be mude vIsIbIe onIy Ior one Irume (visibieFromTo) wIIcI uIIows Lo
sImuIuLe movIng objecLs.
11-S,
TT Grophics
n LIe IoIIowIng exumpIe, we use visibieAfler Lo IIII up LIe pIoL gruduuIIy. We
demonsLruLe LIe cuusLIcs generuLed by sunIIgIL In u Leu cup. TIe rIm oI LIe cup,
regurded us u mIrror, Is gIven by LIe IuncLIon f(x) =

1 x
2
, x [1, 1] (u
semI-cIrcIe). Sun ruys puruIIeI Lo LIe y-uxIs ure reIIecLed by LIe rIm. AILer
reIIecLIon uL LIe poInL (x, f(x)) oI LIe rIm, u ruy Ieuds InLo LIe dIrecLIon
(1, (f

(x) 1/f

(x))/2) II x Is posILIve. L Ieuds InLo LIe dIrecLIon


(1, (f

(x) 1/f

(x))/2) II x Is neguLIve. SweepIng LIrougI LIe mIrror Irom IeIL Lo


rIgIL, LIe IncomIng ruys us weII us LIe reIIecLed ruys ure vIsuuIIzed us IInes. n LIe
unImuLIon, LIey become vIsIbIe uILer LIe LIme 5 x, wIere x Is LIe coordInuLe oI LIe
rIm poInL uL wIIcI LIe ruy Is reIIecLed:
11-SS
Animo|ions
f .= x -> -sqrl(1 - x^Z}.
piol(// The slolic rim.
piol..FunclionZd(f(x} x = -1..1
Coior = RCB..Biock}
// The incoming roys.
piol..LineZd(_x Z] _x f(x}]
Coior = RCB..0ronge
visibieAfler = 5*x
} S x in _-1 + i/Z0 S i = 1..39]
// The refiecled roys ieoving lo lhe righl.
piol..LineZd(_x f(x}]
_1 f(x}+(1-x}*(f(x} - 1/f(x}}/Z]
Coior = RCB..0ronge
visibieAfler = 5*x
} S x in _-1 + i/Z0 S i = 1..19]
// The refiecled roys ieoving lo lhe iefl.
piol..LineZd(_x f(x}]
_-1 f(x} - (x+1}*(f(x} - 1/f(x}}/Z]
Coior = RCB..0ronge
visibieAfler = 5*x
} S x in _-1 + i/Z0 S i = Z1..39]
vieWingBox = _-1..1 -1..1]}
11-Sq
TT Grophics
Ixumples
Ixumple 1: We buIId u zD unImuLIon LIuL dIspIuys u IuncLIon f(x) LogeLIer wILI
LIe InLegruI F(x) =
_
x
0
f(y) dy. TIe ureu beLween LIe grupI oI f und LIe x-uxIs Is
dIspIuyed us un unImuLed IuLcI objecL. TIe currenL vuIue oI F(x) Is dIspIuyed by
un unImuLed LexL:
0TCTTS .= Z.
// lhe funclion f(x}.
f .= x -> cos(x^Z}.
// lhe onli-derivolive F(x}.
F .= x -> numeric..inl(f(y} y = 0..x}.
// lhe groph of f(x}.
g .= piol..FunclionZd(f(x} x = 0..6
Coior = RCB..Biue}.
// lhe groph of F(x}.
C .= piol..FunclionZd(F(x} x = 0..6
Coior = RCB..Biock}.
// o poinl moving oiong lhe groph of F(x}.
p .= piol..PoinlZd(_o F(o}] o = 0..6
Coior = RCB..Biock}.
// holched region belWeen lhe origin ond
// lhe moving poinl p.
h .= piol..|olch(g 0 0..o o = 0..6
Coior = RCB..Red}.
// lhe righl border iine of lhe holched region.
i .= piol..LineZd(_o 0] _o f(o}] o = 0..6
Coior = RCB..Red}.
// o doshed verlicoi iine from f(x} lo F(x}.
L1 .= piol..LineZd(_o f(o}] _o F(o}]
o = 0..6 Coior = RCB..Biock
LineSlyie = 0oshed}.
// o doshed horizonloi iine from lhe y oxis lo F(x}.
LZ .= piol..LineZd(_-0.1 F(o}] _o F(o}]
o = 0..6 Coior = RCB..Biock
LineSlyie = 0oshed}.
// lhe currenl voiue of F ol lhe moving poinl p.
l .= piol..TexlZd(o -> F(o} _-0.Z F(o}] o = 0..6
|orizonloiAiignmenl = Righl}.
11-qo
Animo|ions
piol(g C p h i L1 LZ l
YTicksWumber = Wone YTicksAl = _-1 1]}.
deiele 0TCTTS.
Ixumple : We buIId Lwo D unImuLIons. TIe IIrsL one sLurLs wILI u recLunguIur
sLrIp LIuL Is deIormed Lo un unnuIus In LIe x, y pIune:
c .= o -> 1/Z *(1 - 1/sin(PT/Z*o}}.
mycoior .= (u v x y z} ->
_(u - 0.}/0.4 0 (1.Z - u}/0.4].
reclongieZonnuius .= piol..Surfoce(
_c(o} + (u-c(o}}*cos(PT*v} (u-c(o}}*sin(PT*v} 0]
u = 0...1.Z v = -o..o o = 1/10^10..1
FiiiCoiorFunclion = mycoior Mesh = _3 40]
Fromes = 40}.
11-q1
TT Grophics
piol(reclongieZonnuius Axes = Wone
Comero0ireclion = _-11 -3 3]}
TIe second unImuLIon LwIsLs LIe unnuIus Lo become u MoebIus sLrIp:
onnuiusZmoebius .= piol..Surfoce(
_((u - 1}*cos(o*v*PT/Z} + 1}*cos(PT*v}
((u - 1}*cos(o*v*PT/Z} + 1}*sin(PT*v}
(u - 1}*sin(o*v*PT/Z}]
u = 0...1.Z v = -1..1 o = 0..1 Mesh = _3 40]
FiiiCoiorFunclion = mycoior Fromes = Z0}.
11-q
Animo|ions
piol(onnuiusZmoebius Axes = Wone
Comero0ireclion = _-11 -3 3]}
NoLe LIuL LIe IInuI Irume oI LIe IIrsL unImuLIon coIncIdes wILI LIe IIrsL Irume oI LIe
second unImuLIon. To joIn LIe Lwo sepuruLe unImuLIons, we cun seL upproprIuLe
vIsIbIIILy runges und pIoL LIem LogeLIer. AILer seconds, LIe IIrsL unImuLIon
objecL vunIsIes und LIe second Lukes over:
reclongieZonnuius..visibieFromTo .= 0..5.
onnuiusZmoebius..visibieFromTo .= 5..7.
11-q
TT Grophics
piol(reclongieZonnuius onnuiusZmoebius
Axes = Wone Comero0ireclion = _-11 -3 3]}
11-qq
Groups ol Primi|ives
6reups el FrimiIives
An urbILrury number oI grupIIcuI prImILIves In zD or D cun be coIIecLed In
groups oI Lype piol..CroupZd or piol..Croup3d, respecLIveIy. TIIs Is useIuI Ior
IundIng down uLLrIbuLe vuIues Lo uII eIemenLs In u group.
n LIe IoIIowIng exumpIe, we vIsuuIIze rundom generuLors wILI dIIIerenL
dIsLrIbuLIons by usIng LIem Lo posILIon rundom poInLs:
r1 .= slols..normoiRondom(0 1}.
group1 .= piol..CroupZd(piol..PoinlZd(r1(} r1(}}
S i = 1..Z00}.
rZ .= slols..uniformRondom(-3 3}.
groupZ .= piol..CroupZd(piol..PoinlZd(rZ(} rZ(}}
S i = 1..500}.
piol(group1 groupZ Axes = Frome}
We cunnoL dIsLInguIsI beLween LIe Lwo kInds oI poInLs. Due Lo LIe groupIng, IL Is
very eusy Lo cIunge LIeIr coIor, sIze, und sLyIe by seLLIng LIe upproprIuLe uLLrIbuLes
In LIe groups. Now, LIe Lwo kInds oI poInLs cun be dIsLInguIsIed eusIIy:
11-qg
TT Grophics
group1..PoinlCoior .= RCB..Red.
group1..PoinlSlyie .= XCrosses.
groupZ..PoinlCoior .= RCB..Biue.
groupZ..PoinlSize .= 0.7*unil..mm.
piol(group1 groupZ Axes = Frome}
11-q6
Tronslormo|ions
ruaslermuIieas
AIIIne IIneur LrunsIormuLIons x A x +

b wILI u vecLor

b und u muLrIx A cun be


uppIIed Lo grupIIcuI objecLs vIu LrunsIormuLIon objecLs. TIere ure specIuI
LrunsIormuLIons sucI us LrunsIuLIons, scuIIng, und roLuLIons us weII us generuI
uIIIne IIneur LrunsIormuLIons:
piol..TronsioleZd(_b1bZ]Primilive1PrimiliveZ...} uppIIes LIe
LrunsIuLIon x x+

b by LIe vecLor

b = (b
1
, b
2
)
T
Lo uII poInLs oI zDprImILIves.
piol..Tronsiole3d(_b1bZb3]Primilive1...} uppIIes LIe LrunsIuLIon
x x +

b by LIe vecLor b = (b
1
, b
2
, b
3
)
T
Lo uII poInLs oI D prImILIves.
piol..RefieclZd(_x1y1]_xZyZ]Primilive1...} reIIecLs uII zD
prImILIves ubouL LIe IIne LIrougI LIe poInLs _x1y1] und _xZyZ].
piol..Refiecl3d(_xyz]_nxnynz]Primilive1...} reIIecLs uII D
prImILIves ubouL LIe pIune LIrougI LIe poInL _xyz] wILI LIe normuI _nx
nynz].
piol..RololeZd(ongie_c1cZ]Primilive1...} roLuLes uII poInLs oI
zD prImILIves counLer cIockwIse by LIe gIven ungIe ubouL LIe pIvoL poInL
(c
1
, c
2
)
T
.
piol..Rolole3d(ongie_c1cZc3]_d1dZd3]Primilive1...}
roLuLes uII poInLs oI D prImILIves by LIe gIven ungIe uround LIe roLuLIon
uxIs specIIIed by LIe pIvoL poInL (c
1
, c
2
, c
3
)
T
und LIe dIrecLIon (d
1
, d
2
, d
3
)
T
.
piol..ScoieZd(_s1sZ]Primilive1...} uppIIes LIe dIugonuI scuIIng
muLrIx dIug(s
1
, s
2
) Lo uII poInLs oI zD prImILIves.
piol..Scoie3d(_s1sZs3]Primilive1...} uppIIes LIe dIugonuI
scuIIng muLrIx dIug(s
1
, s
2
, s
3
) Lo uII poInLs oI D prImILIves.
piol..TronsformZd(_b1bZ]APrimilive1...} uppIIes LIe generuI
uIIIne IIneur LrunsIormuLIon x A x +

b wILI u 2 2 muLrIx A und u vecLor

b = (b
1
, b
2
)
T
Lo uII poInLs oI zD prImILIves.
piol..Tronsform3d(_b1bZb3]APrimilive1...} uppIIes LIe generuI
uIIIne IIneur LrunsIormuLIon x A x +

b wILI u 3 3 muLrIx A und u vecLor

b = (b
1
, b
2
, b
3
)
T
Lo uII poInLs oI D prImILIves.
11-q,
TT Grophics
TIe eIIIpses piol..EiiipseZd provIded by LIe piol IIbrury Iuve uxes puruIIeI Lo
LIe coordInuLe uxes. We use u roLuLIon Lo creuLe un eIIIpse wILI u dIIIerenL
orIenLuLIon:
cenler .= _1 Z].
eiiipse .= piol..EiiipseZd(Z 1 cenler}.
piol(piol..RololeZd(PT/4 cenler eiiipse}}
TrunsIorm objecLs cun be unImuLed. We buIId u group consIsLIng oI LIe eIIIpse und
ILs symmeLry uxes. An unImuLed roLuLIon Is uppIIed Lo LIe group:
g .= piol..CroupZd(eiiipse
piol..LineZd(_cenler_1] + Z cenler_Z]]
_cenler_1] - Z cenler_Z]]}
piol..LineZd(_cenler_1] cenler_Z] + 1]
_cenler_1] cenler_Z] - 1]}}.
11-qS
Tronslormo|ions
piol(piol..RololeZd(o cenler o = 0..Z*PT g}}
11-qq
TT Grophics
legeads
TIe unnoLuLIons oI u MuPAD

pIoL muy IncIude u Iegend. A Iegend Is u smuII LubIe


LIuL reIuLes LIe coIor oI un objecL wILI some LexL expIuInIng LIe objecL:
f .= 3*x*sin(Z*x}.
g .= 4*x^Z*cos(x}.
h .= sin(4*x}/x.
piolfuncZd(f g h x = 0..PT/Z}.
By deIuuIL, Iegends ure provIded onIy by piolfuncZd und piolfunc3d. TIese
rouLInes deIIne LIe Iegend LexLs us LIe expressIons wILI wIIcI LIe IuncLIons ure
pussed Lo piolfuncZd or piolfunc3d, respecLIveIy.
11-1oo
Iegends
A correspondIng pIoL commund usIng prImILIves oI LIe piol IIbrury does noL
generuLe LIe Iegend uuLomuLIcuIIy:
piol(piol..FunclionZd(f x = 0..PT/Z Coior = RCB..Red}
piol..FunclionZd(g x = 0..PT/Z Coior = RCB..Creen}
piol..FunclionZd(h x = 0..PT/Z Coior = RCB..Biue}}
11-1o1
TT Grophics
However, Iegends cun be requesLed expIIcILIy:
piol(piol..FunclionZd(f x = 0..PT/Z Coior = RCB..Red
Legend = "Funclion 1. ".exprZlexl(f}}
piol..FunclionZd(g x = 0..PT/Z Coior = RCB..Creen
Legend = "Funclion Z. ".exprZlexl(g}}
piol..FunclionZd(h x = 0..PT/Z Coior = RCB..Biue
Legend = "Funclion 3. ".exprZlexl(h}}}
EucI grupIIcuI prImILIve uccepLs LIe uLLrIbuLe Legend. PussIng LIIs uLLrIbuLe Lo un
objecL LrIggers severuI ucLIons:
TIe objecL uLLrIbuLe LegendTexl Is seL Lo LIe gIven sLrIng.
TIe objecL uLLrIbuLe LegendEnlry Is seL Lo TRuE.
A IInL Is senL Lo LIe scene conLuInIng LIe objecL udvIsIng IL Lo use LIe scene
uLLrIbuLe Legendvisibie=TRuE.
TIe uLLrIbuLes LegendTexl und LegendEnlry ure vIsIbIe In LIe objecL InspecLor oI
LIe InLerucLIve vIewer (puge 11-o) und cun be munIpuIuLed InLerucLIveIy Ior eucI
sIngIe prImILIve uILer seIecLIon In LIe objecL browser. TIe uLLrIbuLe
Legendvisibie Is ussocIuLed wILI LIe scene objecL uccessIbIe vIu LIe objecL
browser.
11-1o
Iegends
AL mosL zo enLrIes cun be dIspIuyed In u Iegend. I more enLrIes ure specIIIed In u
pIoL commund, LIe surpIus enLrIes ure Ignored. urLIer, LIe Iegend muy noL cover
more LIun o% oI LIe IeIgIL oI LIe druwIng ureu oI u scene. OnIy LIose Iegend
enLrIes IILLIng InLo LIIs spuce ure dIspIuyed; remuInIng enLrIes ure Ignored.
I LIe uLLrIbuLe LegendEnlry=TRuE Is seL Ior u prImILIve, ILs Iegend enLry Is
deLermIned us IoIIows:
I LIe uLLrIbuLe LegendTexl Is specIIIed, ILs vuIue Is used Ior LIe Iegend LexL.
I no LegendTexl Is specIIIed, buL LIe Wome uLLrIbuLe Is seL, LIe nume Is used
Ior LIe Iegend LexL.
I no Wome uLLrIbuLe Is specIIIed eILIer, LIe Lype oI LIe objecL sucI us
FunclionZd, CurveZd eLc. Is used Ior LIe Iegend LexL.
Here ure uII uLLrIbuLes reIevunL Ior Iegends:

uLLrIbuLe nume possIbIe vuIues meunIng deIuuIL


Legend sLrIng seLs LegendTexl Lo
LIe gIven sLrIng,
LegendEnlry Lo
TRuE, und
Legendvisibie Lo
TRuE.
LegendEnlry TRuE, FALSE udd LIIs objecL Lo LIe
Iegend?
TRuE Ior IuncLIon
grupIs, curves, und
surIuces, FALSE
oLIerwIse
LegendTexl sLrIng Iegend LexL
Legendvisibie TRuE, FALSE Iegend onJoII TRuE Ior
piolfuncZd/3d
pIoLLIng more LIun
one IuncLIon, FALSE
oLIerwIse
LegendPiocemenl Top, Bollom verLIcuI pIucemenL Bollom
LegendAiignmenl Lefl, Cenler, Righl IorIzonLuI uIIgnmenL Cenler
LegendFonl see puge 11-1oq IonL Ior LIe Iegend
LexL
Suns-SerII 8
TubIe 11.1o: ALLrIbuLes Ior LIe Iegend
11-1o
TT Grophics
leaIs
TIe pIoL uLLrIbuLes Ior specIIyIng IonLs ure AxesTilieFonl, FoolerFonl,
|eoderFonl, LegendFonl, TexlFonl, TicksLobeiFonl, und TilieFonl. EucI sucI
IonL Is specIIIed by u MuPAD

IIsL conLuInIng uny oI LIe IoIIowIng:


A sLrIng denoLIng LIe IonL IumIIy: LIe uvuIIubIe IonL IumIIIes depend on LIe
IonLs LIuL ure InsLuIIed on your mucIIne. TypIcuI IonL IumIIIes uvuIIubIe on
WIndows sysLems ure "Times WeW Romon" (oI Lype "serif"), "Arioi" (oI
Lype "sons-serif"), or "Courier WeW" (oI Lype "monospoce").
To IInd ouL wIIcI IonLs ure uvuIIubIe on your mucIIne, open LIe menu
'ormuL,` submenu 'onL` In your MuPAD noLebook. TIe IIrsL coIumn In LIe
IonL dIuIog provIdes LIe numes oI LIe IonL IumIIIes LIuL you muy specIIy.
TIe mosL porLubIe wuy oI deIInIng IonLs Is Lo use one LIe LIree generIc
IumIIy numes "serif", "sons-serif", or "monospoce". TIe sysLem wIII
uuLomuLIcuIIy cIoose one oI LIe uvuIIubIe IonL IumIIIes oI LIe specIIIed Lype
Ior you.
A posILIve InLeger specIIyIng LIe sIze oI LIe IonL In poInLs.
WIen LIe purumeLer Boid Is specIIIed, LIe IonL Is boId.
WIen LIe purumeLer Tloiic Is specIIIed, LIe IonL Is ILuIIc.
A coIor specIIIcuLIon.
An uIIgnmenL specIIIcuLIon: IL musL be one oI LIe IIugs Lefl, Cenler, or
Righl.
11-1oq
Fon|s
n LIe IoIIowIng exumpIe, we specIIy LIe IonL Ior LIe cunvus Ieuder und IooLer:
piol(piol..FunclionZd(sin(x} x = 0..Z*PT}
|eoder = "The sine funclion"
|eoderFonl = _"monospoce" 1Z Boid]
Fooler = "The sine funclion"
FoolerFonl = _"Times WeW Romon" 14 Tloiic]}
11-1og
TT Grophics
AII IonL purumeLers ure opLIonuI; some deIuuIL vuIues ure cIosen Ior enLrIes LIuL
ure noL specIIIed. or exumpIe, II you do noL cure ubouL LIe IooLer IonL IumIIy Ior
your pIoL, buL you InsIsL on u specIIIc IonL sIze, you muy specIIy u 1qpL IonL us
IoIIows:
piol(piol..FunclionZd(sin(x} x = 0..Z*PT}
Fooler = "The sine funclion" FoolerFonl = _14]}
11-1o6
5oving ond Epor|ing Pic|ures
$uviag uad xperIiag FitIures
Inteructive Suving und Ixporting
TIe MuPAD

kerneI uses un xmI IormuL Lo communIcuLe wILI LIe renderer.


UsuuIIy, u piol commund sends u sLreum oI xmI duLu dIrecLIy Lo LIe vIewer wIIcI
renders LIe pIcLure.
AILer cIIckIng on LIe pIcLure, LIe noLebook provIdes u menu ILem 'IIeJExporL
GrupIIcs.` LIuL opens u dIuIog uIIowIng Lo suve LIe pIcLure In u vurIeLy oI
grupIIcuI IormuLs:
TIe Imuge muy uIso be sLored In vurIous sLundurd bILmup IormuLs sucI us
png, jpg eLc.
GrupIIcs cun be exporLed In eps (encupsuIuLed posLscrIpL) IormuL. SInce eps
does noL supporL Lrunspurency, Iowever, grupIIcs mukIng use oI
Lrunspurency wIII degrude In quuIILy In LIIs sLep. TIIs IncIudes mosL D
pIoLs.
MuPAD`s nuLIve IormuL Is IndIcuLed by LIe IIIe exLensIon 'xvz` Ior LIe
compressed und 'xvc` Ior LIe uncompressed versIon.
One cun use MuPAD Lo open sucI IIIes und dIspIuy und munIpuIuLe LIe pIoLs
conLuIned LIereIn.
urLIer, LIere Is jvx exporL (JuvuVIew).
MuPAD unImuLIons cun be suved us unImuLed gII IIIes.
On WIndows

und MucInLosI

sysLems, MuPAD unImuLIons cun uIso be


suved us uvI IIIes.
n u Muc OS

sysLem, MuPAD unImuLIons cun IurLIermore be suved us


QuIckLIme

movIe IIIes.
11-1o,
TT Grophics
Butch Mode
MuPAD pIoLs cun uIso be suved In buLcI mode by specIIyIng LIe uLLrIbuLe
0ulpulFiie=fiienome In u piol cuII:
piol(Primilive1 PrimiliveZ ...
0ulpulFiie = "mypiclure.xvz"}
Here, LIe exLensIon xvz oI LIe IIIe nume IndIcuLes LIuL MuPAD`s xmI duLu ure Lo be
wrILLen In compressed IormuL. AILernuLIveIy, LIe exLensIon xvc muy be used Lo
wrILe LIe xmI duLu wILIouL compressIon oI LIe IIIe (LIe resuILIng uscII IIIe cun be
reud wILI uny LexL edILor). IIes In boLI IormuLs cun be opened by MuPAD Lo
generuLe LIe pIoL encoded by LIe xmI duLu.
I LIe MuPAD envIronmenL vurIubIe nRTTEPAT| does noL Iuve u vuIue, LIe
prevIous cuII creuLes LIe IIIe In LIe dIrecLory wIere MuPAD Is InsLuIIed. An
ubsoIuLe puLInume cun be specIIIed Lo pIuce LIe IIIe unywIere eIse:
piol(Primilive1 PrimiliveZ ...
0ulpulFiie = "C.``0ocumenls``mypiclure.xvz"}
AILernuLIveIy, LIe envIronmenL vurIubIe nRTTEPAT| cun be seL:
nRTTEPAT| .= "C.``0ocumenls".
piol(Primilive1 PrimiliveZ ...
0ulpulFiie = "mypiclure.xvz"}
Now, LIe pIoL duLu ure sLored In LIe IIIe 'C.\0ocumenls\mypiclure.xvz`.
ApurL Irom suvIng IIIes us xmI duLu, MuPAD pIcLures cun uIso be suved In u vurIeLy
oI sLundurd grupIIcuI IormuLs sucI us jpg, eps, svg, bmp eLc. n buLcI mode, LIe
exporL Is LrIggered by LIe 0ulpulFiie uLLrIbuLe In LIe sume wuy us Ior suvIng In
xmI IormuL. JusL use un upproprIuLe exLensIon oI LIe IIIenume IndIcuLIng LIe
IormuL. TIe IoIIowIng communds suve LIe pIoL In Iour dIIIerenL IIIes In jpg, eps,
svg, und bmp IormuL, respecLIveIy:
piol(Primilive1 ... 0ulpulFiie = "mypiclure.gpg"}.
piol(Primilive1 ... 0ulpulFiie = "mypiclure.eps"}.
piol(Primilive1 ... 0ulpulFiie = "mypiclure.svg"}.
piol(Primilive1 ... 0ulpulFiie = "mypiclure.bmp"}.
11-1oS
5oving ond Epor|ing Pic|ures
An unImuLed MuPAD pIoL cun be exporLed Lo uvI IormuL:
piol(piol..FunclionZd(exp(o*x} x = 0..1 o = -1..1}
0ulpulFiie = "myonimolion.ovi"}
I no IIIe exLensIon Is specIIIed by LIe IIIe nume, LIe deIuuIL exLensIon xvc Is used,
I.e., uncompressed xmI duLu ure wrILLen.
I u noLebook Is suved Lo u IIIe, ILs IocuLIon In LIe IIIe sysLem Is uvuIIubIe InsIde LIe
noLebook us LIe vuIue oI LIe envIronmenL vurIubIe W0TEB00KPAT|. I you wIsI Lo
suve your pIoL In LIe sume IoIder us LIe noLebook, you muy cuII
piol(Primilive1 PrimiliveZ ...
0ulpulFiie = W0TEB00KPAT|."mypiclure.xvz"}
n uddILIon Lo 0ulpulFiie, LIere Is LIe uLLrIbuLe 0ulpul0plions Lo specIIy
purumeLers Ior some oI LIe exporL IormuLs. TIe IeIp puge oI LIIs uLLrIbuLe
provIdes deLuIIed InIormuLIon.
11-1oq
TT Grophics
lmperIiag FitIures
MuPAD

does noL provIde Ior muny LooIs Lo ImporL sLundurd grupIIcuI tector
IormuLs, yeL. PresenLIy, LIe onIy supporLed vecLor Lype Is LIe sLI IormuL, popuIur In
sLereo IILIogrupIy, wIIcI encodes D surIuces. L cun be ImporLed vIu LIe rouLIne
piol..SurfoceSTL.
n conLrusL Lo grupIIcuI tector IormuLs, LIere ure muny sLundurd bitmcp IormuLs
sucI us bmp, gII, jpg, ppm eLc. LIuL cun be ImporLed. One cun reud sucI u IIIe vIu
imporl..reodbilmop, LIus creuLIng u MuPAD urruy oI RGB coIor vuIues or un
equIvuIenL LIree-dImensIonuI Iurdwure IIouL urruy LIuL cun be munIpuIuLed uL
wIII. n purLIcuIur, IL cun be Ied InLo LIe rouLIne piol..Rosler wIIcI creuLes un
objecL LIuL cun be used In uny zD MuPAD pIoL. NoLe, Iowever, LIuL LIe ImporL oI
bILmup duLu consumes u IoL oI memory, I.e., onIy reusonubIy smuII bILmups (up Lo
u Iew Iundred pIxeIs In eucI dIrecLIon) sIouId be processed. Memory
consumpLIon Is mucI smuIIer wILI Iurdwure IIouLIng poInL urruys, wIIcI Is wIy
imporl..reosonobiy uses LIem by deIuuIL.
n LIe IoIIowIng exumpIe, we pIoL LIe probubIIILy densILy IuncLIon und LIe
cumuIuLIve densILy IuncLIon oI LIe sLundurd normuI (GuussIun) dIsLrIbuLIon.
PuyIng LrIbuLe Lo CurI rIedrIcI Guuss, we wIsI Lo dIspIuy <<<<<<< .mIne IIs
pIcLure In LIIs pIoL. Assume LIuL we Iuve IIs pIcLure us u png bILmup IIIe
Guuss.png. We ImporL LIe IIIe vIu imporl..reodbilmop LIuL provIdes us wILI
LIe wIdLI und IeIgIL In pIxeIs und LIe coIor duLu: ======= IIs pIcLure In LIIs
pIoL. Assume LIuL we Iuve IIs pIcLure us u png bILmup IIIe Guuss.png. We
ImporL LIe IIIe vIu imporl..reodbilmop LIuL provIdes us wILI LIe wIdLI und
IeIgIL In pIxeIs und LIe coIor duLu: >>>>>>> .rzq8
_Widlh heighl gouss] .= imporl..reodbilmop("Couss.png"}.
NoLe LIe coIon uL LIe end oI LIe ubove commund! WILIouL IL, MuPAD wIII prInL
LIe coIor InIormuLIon on LIe screen, und IormuLLIng sucI u Iuge ouLpuL Lukes LIme.
We Iuve Lo use Scoiing=Conslroined Lo preserve LIe uspecL ruLIo oI LIe Imuge.
UnIorLunuLeIy, LIIs seLLIng Is noL upproprIuLe Ior LIe IuncLIon pIoLs. So we use Lwo
dIIIerenL scenes LIuL ure posILIoned vIu Loyoul=Reiolive. See SecLIon 'uyouL oI
Cunvus und Scenes` oI LIe onIIne piol documenLuLIon Ior deLuIIs on Iow LIe
IuyouL oI u cunvus conLuInIng severuI scenes Is seL.
11-11o
Impor|ing Pic|ures
pdf .= slols..normoiP0F(0 1}.
cdf .= slols..normoiC0F(0 1}.
piol(piol..SceneZd(piol..FunclionZd(pdf(x} x = -4..7}
piol..FunclionZd(cdf(x} x = -4..7}
nidlh = 1 |eighl = 1}
piol..SceneZd(piol..Rosler(gouss}
Scoiing = Conslroined
nidlh = 0.3 |eighl = 0.6
Bollom = 0.Z5 Lefl = 0.6
Bordernidlh = 0.5*unil..mm
Fooler = "C.F. Couss"
FoolerFonl = _]}
Loyoul = Reiolive}
11-111
TT Grophics
fumerus ia 30
TIe MuPAD

D grupIIcs modeI IncIudes un observer uL u specIIIc posILIon,


poInLIng u cumeru wILI u Iens oI u specIIIc openIng ungIe Lo some specIIIc IocuI
poInL. TIe specIIIc purumeLers posILIon, ungIe, und IocuI poInL deLermIne LIe
pIcLure LIuL LIe cumeru wIII Luke.
WIen u D pIcLure Is creuLed,u cumeru wILI un upproprIuLe deIuuIL Iens Is
posILIoned uuLomuLIcuIIy. Ls IocuI poInL Is cIosen us LIe cenLer oI LIe grupIIcuI
scene. TIe InLerucLIve vIewer uIIows Lo roLuLe LIe scene wIIcI, In IucL, Is
ImpIemenLed InLernuIIy us u cIunge oI LIe cumeru posILIon. AIso InLerucLIve
zoomIng In und zoomIng ouL Is reuIIzed by movIng LIe cumeru cIoser Lo or IurLIer
uwuy Irom LIe scene.
ApurL Irom InLerucLIve cumeru moLIons, LIe perspecLIve oI u D pIcLure cun uIso be
seL In LIe cuIIs generuLIng LIe pIoL. One wuy Is Lo specIIy LIe dIrecLIon Irom wIIcI
LIe cumeru Is poInLIng Lowurds LIe scene. TIIs Is done vIu LIe uLLrIbuLe
Comero0ireclion:
piol(piol..Funclion3d(sin(x + y^3} x = -1..1 y = -1..1}
Comero0ireclion = _-Z5 Z0 30]}
11-11
Comeros in 3D
piol(piol..Funclion3d(sin(x + y^3} x = -1..1 y = -1..1}
Comero0ireclion = _10 -40 10]}
n LIese cuIIs, Comero0ireclion does noL IuIIy specIIy LIe posILIon oI LIe cumeru.
TIIs uLLrIbuLe jusL requesLs LIe cumeru Lo be pIuced uL some Iurge dIsLunce Irom
LIe scene uIong LIe ruy In LIe dIrecLIon gIven by LIe uLLrIbuLe. TIe ucLuuI dIsLunce
Irom LIe scene Is deLermIned uuLomuLIcuIIy Lo IeL LIe grupIIcuI scene IIII LIe
pIcLure opLImuIIy.
or u IuII specIIIcuLIon oI LIe perspecLIve, LIere ure cumeru objecLs oI Lype
piol..Comero LIuL uIIow Lo specIIy LIe posILIon oI LIe cumeru, ILs IocuI poInL und
LIe openIng ungIe oI ILs Iens:
posilion .= _-5 -10 5].
focoipoinl .= _0 0 0].
ongie .= PT/1Z.
comero .= piol..Comero(posilion focoipoinl ongie}.
TIIs cumeru cun be pussed IIke uny grupIIcuI objecL Lo LIe piol commund
generuLIng LIe scene.
11-11
TT Grophics
Once u cumeru objecL Is specIIIed In u grupIIcuI scene, IL deLermInes LIe vIew. No
uuLomuLIc cumeru Is used uny more:
piol(piol..Funclion3d(sin(x + y^3} x = -1..1 y = -1..1}
comero}
11-11q
Comeros in 3D
Cumeru objecLs cun be unImuLed:
comero .= piol..Comero(_3*cos(o} 3*sin(o} 1 + cos(Z*o}]
_0 0 0] PT/3 o = 0..Z*PT
Fromes = 100}.
nserLIng LIe unImuLed cumeru In u grupIIcuI scene, we obLuIn un unImuLed pIoL
sImuIuLIng u IIIgIL uround LIe scene:
piol(piol..Funclion3d(sin(x + y^3} x = -1..1 y = -1..1}
comero}
n IucL, severuI cumerus cun be InsLuIIed sImuILuneousIy In u scene. Per deIuuIL,
LIe IIrsL cumeru produces LIe vIew rendered. AILer cIIckIng on unoLIer cumeru In
LIe objecL browser oI LIe vIewer (puge 11-o), LIe seIecLed cumeru Lukes over und
LIe new vIew Is sIown.
11-11g
TT Grophics
NexL, we Iuve u Iook uL u more uppeuIIng exumpIe: LIe so-cuIIed orenz
uLLrucLor. TIe orenz ODE Is LIe sysLem
d
dt
_
_
x
y
z
_
_
=
_
_
p (y x)
x z +r x y
x y b z
_
_
wILI IIxed purumeLers p, r, b. As u dynumIcuI sysLem Ior Y = [x, y, z], we Iuve Lo
soIve LIe ODE dY /dt = f(t, Y ) wILI LIe IoIIowIng vecLor IIeId:
f .= proc(l Y}
iocoi x y z
begin
_x y z] .= Y.
_p*(y - x} -x*z + r*x - y x*y - b*z]
endproc.
ConsIder LIe IoIIowIng purumeLers und LIe IoIIowIng InILIuI condILIon Y0:
p .= 10. r .= Z. b .= 1. Y0 .= _1 1 1].
TIe rouLIne piol..0de3d serves Ior generuLIng u grupIIcuI D soIuLIon oI u
dynumIcuI sysLem. L soIves LIe ODE numerIcuIIy und generuLes grupIIcuI duLu
Irom LIe numerIcuI mesI. TIe pIoL duLu ure specIIIed by LIe user vIu generuLors
(procedures) LIuL mup u soIuLIon poInL (t, Y ) Lo u poInL (x, y, z) In D.
TIe IoIIowIng generuLor Cxyz produces u D pIuse pIoL oI LIe soIuLIon. TIe
generuLor Cyz projecLs LIe soIuLIon curve Lo LIe (y, z) pIune wILI x = 20; LIe
generuLor Cxz projecLs LIe soIuLIon curve Lo LIe (x, z) pIune wILI y = 20; LIe
generuLor Cxy projecLs LIe soIuLIon curve Lo LIe (x, y) pIune wILI z = 0:
Cxyz .= (l Y} -> Y.
Cyz .= (l Y} -> _-Z0 Y_Z] Y_3]].
Cxz .= (l Y} -> _Y_1] -Z0 Y_3]].
Cxy .= (l Y} -> _Y_1] Y_Z] 0].
WILI LIese generuLors, we creuLe u D pIoL objecL consIsLIng oI LIe pIuse curve
und ILs projecLIons:
obgecl .= piol..0de3d(f _S 1..50 slep 1/10] Y0
_Cxyz Slyie = Spiines Coior = RCB..Red]
_Cyz Slyie = Spiines Coior = RCB..LighlCroy]
_Cxz Slyie = Spiines Coior = RCB..LighlCroy]
_Cxy Slyie = Spiines Coior = RCB..LighlCroy]}.
11-116
Comeros in 3D
We deIIne un unImuLed cumeru movIng uround LIe scene:
comero .= piol..Comero(
_-1 + 100*cos(o} 6 + 100*sin(o} 1Z0]
_-1 6 Z5] PT/6 o = 0..Z*PT Fromes = Z50}.
TIe IoIIowIng piol cuII Lukes ubouL IuII u mInuLe on u GHz compuLer:
piol(obgecl comero Axes = Boxed TicksWumber = LoW}
NexL, we wIsI Lo IIy clon the Lorenz cttrcctor. We cunnoL use piol..0de3d,
becuuse we need uccess Lo LIe numerIcuI duLu oI LIe uLLrucLor Lo buIId u suILubIe
unImuLed cumeru objecL. We use LIe numerIcuI ODE soIver numeric..odesoiveZ
und compuLe u IIsL oI numerIcuI sumpIe poInLs on LIe orenz uLLrucLor. TIIs Lukes
ubouL LwenLy seconds on u GHz compuLer:
Y .= numeric..odesoiveZ(f 0 Y0 RememberLosl}.
limemesh .= _S 0..500 slep 1/50].
Y .= _Y(l} S l in limemesh].
11-11,
TT Grophics
SImIIur Lo LIe pIcLure ubove, we deIIne u box uround LIe uLLrucLor wILI LIe
projecLIons oI LIe soIuLIon curve:
box .= _-15 Z0 -Z0 Z6 1 50].
Yyz .= mop(Y pl -> _box_1] pl_Z] pl_3]]}.
Yxy .= mop(Y pl -> _pl_1] pl_Z] box_5]]}.
Yxz .= mop(Y pl -> _pl_1] box_3] pl_3]]}.
We creuLe un unImuLed cumeru usIng un unImuLIon purumeLer o LIuL corresponds
Lo LIe Index oI LIe IIsL oI numerIcuI sumpIe poInLs. TIe IoIIowIng procedure
reLurns LIe i-LI coordInuLe (i = 1, 2, 3) oI LIe a-LI poInL In LIe IIsL oI sumpIe poInLs
(see CIupLer 1;, especIuIIy LIe secLIon sLurLIng on puge 1;-; Ior deLuIIs):
Poinl .= proc(o i}
begin
if domlype(fiool(o}} <> 00MFL0AT lhen
procnome(orgs(}}
eise Y_round(o}]_i]
endif
endproc.
n LIe a-LI Irume oI LIe unImuLIon, LIe cumeru Is posILIoned uL LIe a-LI sumpIe
poInL oI LIe orenz uLLrucLor, poInLIng Lowurd LIe nexL sumpIe poInL. SeLLIng
TimeRonge=0..n/10, LIe cumeru vIsILs ubouL 1o poInLs per second:
11-11S
Comeros in 3D
n .= nops(limemesh} - 1.
piol(piol..Scene3d(
piol..Comero(_Poinl(o i} S i = 1..3]
_Poinl(o + 1 i} S i = 1..3]
PT/4 o = 1..n Fromes = n
TimeRonge = 0..n/10}
piol..Poiygon3d(Y LineCoior = RCB..Red
Poinlsvisibie = TRuE}
piol..Poiygon3d(Yxy LineCoior = RCB..0imCroy}
piol..Poiygon3d(Yxz LineCoior = RCB..0imCroy}
piol..Poiygon3d(Yyz LineCoior = RCB..0imCroy}
piol..Box(box_1]..box_Z] box_3]..box_4]
box_5]..box_6] Fiiied = TRuE
LineCoior = RCB..Biock
FiiiCoior = RCB..Croy._0.1]}
BockgroundSlyie = Fiol}}
11-11q
TT Grophics
$Iruage lletIs ia 30? ktteleruIed 0pea6l

librury?
TIe renderIng engIne Ior D pIoLs uses LIe OpenG

IIbrury. OpenG IIbrury Is u


wIdeIy used grupIIcs sLundurd und (uImosL) uny compuLer Ius upproprIuLe drIvers
InsLuIIed In ILs sysLem.
By deIuuIL, MuPAD

under WIndows

uses u soILwure OpenG drIver provIded by


LIe WIndows operuLIng sysLem. DependIng on LIe grupIIcs curd oI your mucIIne,
you muy uIso Iuve IurLIer OpenG drIvers on your sysLem, muybe usIng Iurdwure
supporL Lo ucceIeruLe your OpenG IIbrury.
TIe MuPAD D grupIIcs wus wrILLen und LesLed usIng cerLuIn sLundurd OpenG
drIvers. TIe numerous drIvers uvuIIubIe on LIe murkeL Iuve dIIIerenL renderIng
quuIILy und dIIIer sIIgILIy. TIIs muy, In rure cuses, Ieud Lo some unexpecLed
grupIIcuI eIIecLs on your mucIIne.
AILer doubIe cIIckIng on u D pIoL, LIe 'HeIp` menu conLuIns un enLry 'OpenG
nIo .` provIdIng LIe InIormuLIon wIIcI OpenG drIver you ure currenLIy usIng.
You uIso geL LIe InIormuLIon Iow muny IIgIL sources und Iow muny cIIppIng
pIunes LIIs drIver supporLs.
TIe enLry 'ConIIgure .` oI LIe 'VIew` menu opens u dIuIog, wIIcI conLuIns u
secLIon 'User nLerIuce.` TIIs secLIon conLuIns Lwo cIeck boxes IubeIed 'AcceIeruLe
OpenG` und 'DIsubIe OpenG,` wILI LIe IIrsL one seIecLIng beLween LIe dIvers
opLImIzed Ior LIe Iurdwure InsLuIIed (wIIcI, us ouLIIned ubove, muy cuuse
probIems due Lo bud drIvers). TIe second cIeckbox sIouId onIy be used In LIe
exLremeIy unIIkeIy evenL LIuL D grupIIcs do noL work uL uII; on some sysLems,
openIng uny OpenG progrum Ireezes LIe compuLer. CIeckIng LIIs box dIsubIes
MuPAD D grupIIcs.
TIus, II you encounLer sLrunge grupIIcuI eIIecLs In D, we recommend Lo use LIIs
conIIguruLIon dIuIog Lo LoggIe Iurdwure ucceIeruLIon.
Ixercise 11.1: Ind uILernuLIve dIspIuy sLyIes Ior LIe pIoLs In LIIs cIupLer.
EspecIuIIy, modIIy LIe exumpIe Irom puge 11-q Lo use piol..0deZd undJor
piol..SlreomiinesZd.
11-1o
T2
Inpot und Ootpot
0uIpuI el xpressieas
MuPAD

does noL dIspIuy uII compuLed resuILs on LIe screen. TypIcuI exumpIes
ure LIe communds wILIIn for Ioops (CIupLer 1) or procedures (CIupLer 1;): onIy
LIe IInuI resuIL (I.e., LIe resuIL oI LIe IusL commund) Is prInLed und LIe ouLpuL oI
InLermedIuLe resuILs Is suppressed. NeverLIeIess, you cun IeL MuPAD prInL
InLermedIuLe resuILs or cIunge LIe ouLpuL IormuL.
Printing Ixpressions on the Screen
TIe IuncLIon prinl ouLpuLs MuPAD objecLs on LIe screen:
for i from 4 lo 5 do
prinl("The " i "lh prime is " ilhprime(i}}
endfor
"The " 4 "lh prime is " 7
"The " 5 "lh prime is " 11
We recuII LIuL ilhprime(i} compuLes LIe i-LI prIme. MuPAD encIoses LIe LexL In
doubIe quoLes. Use LIe opLIon unquoled Lo suppress LIIs:
T2 Inpu| ond Cu|pu|
for i from 4 lo 5 do
prinl(unquoled
"The " i "lh prime is " ilhprime(i}}
endfor
The 4 lh prime is 7
The 5 lh prime is 11
NoLe LIuL LIe opLIon unquoled breuks LypeseLLIng:
prinl(x^Z} prinl(unquoled x^Z}
x
2
Z
x
urLIermore, you cun eIImInuLe LIe commus Irom LIe ouLpuL by meuns oI LIe
LooIs Ior munIpuIuLIng sLrIngs LIuL ure presenLed In SecLIon q.11:
for i from 4 lo 5 do
prinl(unquoled
"The " . exprZlexl(i} . "lh prime is " .
exprZlexl(ilhprime(i}} . "."}
endfor
The 4lh prime is 7.
The 5lh prime is 11.
Here, LIe IuncLIon exprZlexl Is used Lo converL LIe vuIue oI i und LIe prIme
reLurned by ilhprime(i} Lo sLrIngs. TIen, LIe concuLenuLIon operuLor . combInes
LIem wILI LIe oLIer sLrIngs Lo u sIngIe sLrIng. NoLe LIuL converLIng un expressIon
Lo u sLrIng breuks LypeseLLIng us weII us LIe preLLy prInL IormuL expIuIned beIow:
prinl(unquoled exprZlexl(x^Z}}
x^Z
AILernuLIveIy you cun use LIe IuncLIon fprinl, wIIcI wrILes duLu Lo u IIIe or on LIe
screen. n conLrusL Lo prinl, IL does noL ouLpuL ILs urgumenLs us IndIvIduuI
expressIons. nsLeud, fprinl combInes LIem Lo u sIngIe sLrIng (II you use LIe
opLIon unquoled):
o .= one. b .= slring.
1-
Cu|pu| ol Epressions
fprinl(unquoled 0 "This is " o " " b}
This is one slring
TIe second urgumenL 0 LeIIs fprinl Lo dIrecL ILs ouLpuL Lo LIe screen.
ModiIying the Ootpot Iormut
UsuuIIy, MuPAD wIII IormuL ouLpuLs In u wuy sImIIur Lo Iow muLIemuLIcuI
IormuIus ure usuuIIy wrILLen In books or on u bIuckbourd (LypeseL expressIons):
InLegruI sIgns ure dIspIuyed us
_
, symboIIc sums uppeur us

eLc. TIIs Is LIe


IormuL used In mosL resuIL regIons oI LIIs book. TIere ure Lwo oLIer ouLpuL
IormuLs uvuIIubIe. TIe IoIIowIng LexL reIers Lo LIese ASC-bused ouLpuL onIy,
wIIcI ure used II LIe LypeseLLIng Is swILcIed oII vIu LIe correspondIng menu oI LIe
noLebook InLerIuce or wIen prinl wILI LIe opLIon Pioin Is used.
WILIouL LypeseLLIng, MuPAD usuuIIy prInLs expressIons In u Lwo-dImensIonuI
Iorm wILI sImpIe (uscII) cIurucLers:
diff(sin(x}/cos(x} x}
Z
sin(x}
------- + 1
Z
cos(x}
TIIs IormuL Is known us prett print. L resembIes LIe usuuI muLIemuLIcuI
noLuLIon. TIereIore, IL Is oILen eusIer Lo reud LIun u sIngIe IIne ouLpuL. However,
MuPAD onIy uses preLLy prInL Ior ouLpuL und IL Is noL u vuIId InpuL IormuL: In u
grupIIcuI user InLerIuce you cunnoL copy some ouLpuL LexL wILI LIe mouse und
pusLe IL us InpuL somewIere eIse. (TIIs Is possIbIe wILI LypeseL IormuIus, uILIougI
noL Ior purLs oI u Iurger IormuIu.)
TIe envIronmenL vurIubIe PRETTYPRTWT conLroIs LIe ouLpuL IormuL. TIe deIuuIL
vuIue oI LIe vurIubIe Is TRuE, I.e., LIe preLLy prInL IormuL Is used Ior LIe ouLpuL. I
you seL LIIs vurIubIe Lo FALSE, you obLuIn u one-dImensIonuI ouLpuL Iorm wIIcI
cun oILen uIso be used us InpuL:
PRETTYPRTWT .= FALSE. diff(sin(x}/cos(x} x}
1/cos(x}^Z*sin(x}^Z + 1
1-
T2 Inpu| ond Cu|pu|
I un ouLpuL wouId exceed LIe IIne wIdLI, LIe sysLem uuLomuLIcuIIy breuks LIe
IInes:
PRETTYPRTWT .= TRuE. loyior(sin(x} x = 0 16}
3 5 7 9 11
x x x x x
x - -- + --- - ---- + ------ - -------- +
6 1Z0 5040 36Z0 3991600
13 15
x x 17
---------- - ------------- + 0(x }
6ZZ70Z000 130767436000
You cun seL LIe envIronmenL vurIubIe TEXTnT0T| Lo LIe desIred IIne wIdLI. Ls
deIuuIL vuIue Is 75 (cIurucLers), und you cun ussIgn uny InLeger beLween 10 und
2
31
1 Lo IL. or exumpIe, II you compuLe (InInx)

, LIen you obLuIn LIe IoIIowIng


ouLpuL:
diff(in(in(x}} x x}
1 1
- -------- - ---------
Z Z Z
x in(x} x in(x}
I you reduce LIe vuIue oI TEXTnT0T|, LIe sysLem breuks LIe ouLpuL ucross Lwo
IInes:
TEXTnT0T| .= Z0. diff(in(in(x}}xx}
1
- -------- -
Z
x in(x}
1
---------
Z Z
x in(x}
TIe deIuuIL vuIue Is resLored by deIeLIng TEXTnT0T|:
deiele TEXTnT0T|.
You cun uIso conLroI LIe ouLpuL by user-deIIned preIerences. TIIs Is dIscussed In
LIe secLIon sLurLIng on puge 1-z.
1-q
keoding ond Wri|ing Files
keudiag uad NriIiag liles
You cun suve LIe vuIues oI IdenLIIIers or u compIeLe MuPAD

sessIon Lo u IIIe und


reud LIe IIIe IuLer InLo unoLIer MuPAD sessIon.
The Ionctions Wrile und reod
TIe IuncLIon Wrile sLores LIe vuIues oI IdenLIIIers In u IIIe, so LIuL you cun reuse
LIe compuLed resuILs In unoLIer MuPAD sessIon. n LIe IoIIowIng exumpIe, we
suve LIe vuIues oI LIe IdenLIIIers o und b Lo LIe IIIe ob.mb:
o .= Z/3. b .= diff(sin(cos(x}} x}.
Wrile("ob.mb" o b}
You puss LIe IIIe nume us u sLrIng (SecLIon q.11) encIosed In doubIe quoLes ". TIe
sysLem LIen creuLes u IIIe wILI LIIs nume (wILIouL "). I you reud LIIs IIIe InLo
unoLIer MuPAD sessIon vIu LIe IuncLIon reod, you cun uccess LIe vuIues oI LIe
IdenLIIIers o und b wILIouL recompuLIng LIem:
resel(}.
reod("ob.mb"}. o b
2
3
, cos(cos(x)) sIn(x)
I you use LIe IuncLIon Wrile us In LIe ubove exumpIe, IL creuLes u IIIe In LIe
MuPAD bInury IormuL. By convenLIon, u IIIe In LIIs IormuL sIouId Iuve LIe IIIe
nume exLensIon .mb. You cun cuII LIe IuncLIon Wrile wILI LIe opLIon Texl. TIIs
generuLes u IIIe In u reudubIe LexL IormuL:
1
o .= Z/3. b .= exp(x+1}.
Wrile(Texl "ob.mu" o b}
1
UsuuIIy LIe IIIe nume exLensIon Ior MuPAD LexL IIIes sIouId be .mu. TIe MuPAD edILor uIIows
edILIng sucI IIIes In u comIorLubIe wuy.
1-g
T2 Inpu| ond Cu|pu|
TIe IIIe ob.mu now conLuIns LIe IoIIowIng Lwo synLucLIcuIIy correcL MuPAD
communds:
o .= Z/3.
b .= hoid(exp}(hoid(pius}(hoid(x} 1}}.
You cun use LIe IuncLIon reod Lo reud LIIs IIIe:
o .= 1. b .= Z. reod("ob.mu"}. o b
2
3
, e
x+1
TIe LexL IormuL IIIes generuLed by Wrile conLuIn vuIId MuPAD communds. OI
course, you cun use uny edILor Lo generuLe sucI u LexL IIIe by Iund und reud IL
InLo u MuPAD sessIon, usIng LIe commund reod or LIe enLry 'Reud Communds .`
Irom LIe 'NoLebook` menu. n IucL LIIs Is u nuLuruI wuy Lo proceed wIen you
deveIop more compIex MuPAD procedures.
Suving u MoPA

Session
I you cuII LIe IuncLIon Wrile wILIouL suppIyIng uny IdenLIIIers us urgumenLs, LIe
sysLem wrILes LIe vuIues oI cll IdenLIIIers IuvIng u vuIue Lo u IIIe, excepL Ior LIose
deIIned by LIe MuPADsysLem ILseII. TIus, IL Is possIbIe Lo resLore LIe sLuLe oI LIe
currenL sessIon vIu reod uL u IuLer LIme:
resuil1 .= ... resuilZ .= ... ...
Wrile("resuils.mb"}
Reuding utu Irom u Text Iile
OILen you wunL Lo use duLu In MuPAD LIuL ure generuLed by oLIer soILwure (Ior
exumpIe, you mIgIL wunL Lo reud In sLuLIsLIcuI vuIues Ior IurLIer processIng), or
uccess uII IIIes In some dIrecLory uuLomuLIcuIIy. TIIs Is possIbIe wILI LIe IeIp oI
LIe IuncLIon imporl..reoddolo Irom LIe IIbrury imporl. TIIs IuncLIon converLs
LIe conLenLs oI u IIIe Lo u nesLed MuPAD IIsL. You muy regurd LIe IIIe us u muLrIx
wILI IIne breuks IndIcuLIng LIe begInnIng oI u new row. NoLe LIuL LIe rows muy
1-6
keoding ond Wri|ing Files
Iuve dIIIerenL IengLI. You muy puss un urbILrury cIurucLer Lo imporl..reoddolo
us u coIumn sepuruLor.
Suppose you Iuve u IIIe numericoi0olo wILI LIe IoIIowIng 4 IInes:
1 1.Z 1Z
Z.34 Z34
34 345.6
4 44 444
By deIuuIL, bIunk cIurucLers ure ussumed us coIumn sepuruLors. So you cun reud
LIIs IIIe InLo u MuPAD sessIon us IoIIows:
dolo .= imporl..reoddolo("numericoi0olo"}.
dolo_1] dolo_Z] dolo_3] dolo_4]
[1, 1.2, 12]
[2.34, 234]
[34, 345.6]
[4, 44, 444]
TIe IeIp puge Ior imporl..reoddolo provIdes IurLIer InIormuLIon. AIso see
imporl..csv Ior unoLIer ImporLunL duLu excIunge IormuL.
1-,
T3
Ltilities
n LIIs cIupLer we presenL some useIuI IuncLIons. Due Lo spuce IImILuLIons, we do
noL expIuIn LIeIr compIeLe IuncLIonuIILy und reIer Lo LIe IeIp puges Ior more
deLuIIed InIormuLIon.
T3 U|ili|ies
ser-0ehaed Frelereates
You cun cusLomIze MuPAD

`s beIuvIor by usIng prejerences. TIe IoIIowIng


commund IIsLs uII preIerences:
Pref(}
Pref..oiios . TRuE
Pref..ouloExponsionLimil. 1000
Pref..ouloPiol . FALSE
Pref..coiiBock . WTL
Pref..coii0nExil . WTL
Pref..dbgAulo0ispioy . TRuE
Pref..dbgAuloLisl . TRuE
Pref..fioolFormol . "g"
Pref..ignoreWo0ebug . FALSE
Pref..keep0rder . 0omoins0niy
Pref..kernei . _5 0 0]
Pref..moxMem . 0
Pref..moxTime . 0
Pref..oulpul . WTL
Pref..poslTnpul . WTL
Pref..posl0ulpul . WTL
Pref..reporl . 0
Pref..lroiiingZeroes . FALSE
Pref..lypeCheck . Tnleroclive
Pref..unioodobieModuies . FALSE
Pref..user0plions . ""
Pref..verboseReod . 0
Pref..Worn0eodProcEnv . FALSE
We reIer Lo LIe IeIp puge ?Pref Ior u compIeLe descrIpLIon oI uII preIerences. OnIy
u Iew opLIons ure dIscussed beIow.
You cun use LIe reporl preIerence Lo requesL reguIur InIormuLIon on MuPAD`s
uIIocuLed memory, LIe memory reuIIy used, und LIe eIupsed compuLIng LIme.
VuIId urgumenLs Ior reporl ure InLegers beLween 0 und 9. TIe deIuuIL vuIue 0
meuns LIuL no InIormuLIon Is dIspIuyed. I you cIoose LIe vuIue 9, you
permunenLIy obLuIn InIormuLIon ubouL MuPAD`s currenL sLuLe. You uIso geL LIIs
InIormuLIon In LIe sLuLus bur oI LIe noLebook, buL LIe ouLpuL oI Pref..reporl wIII
sLuy In LIe ouLpuL, uIIowIng you Lo revIew LIe deveIopmenL over LIme.
1-
UserDehned Prelerences
Pref..reporl(9}. inl(sin(x}^Z/x x = 0..1}
_used=Z0k reserved=341Zk seconds=1]
_used=3955k reserved=4461k seconds=1]
_used=750k reserved=Z03k seconds=Z]

2

CI (2)
2
+
In(2)
2
TIe preIerence fioolFormol conLroIs LIe ouLpuL oI IIouLIng-poInL numbers. or
exumpIe, II you suppIy LIe urgumenL "e", IIouLIng-poInL numbers ure prInLed wILI
munLIssu und exponenL (e.g., 1.Z34e-7 = 1.234 10
7
). I you use LIe urgumenL
"f", MuPAD prInLs LIem In IIxed poInL represenLuLIon:
Pref..fioolFormol("e"}. fiool(exp(-50}}
1.928749848 10
22
Pref..fioolFormol("f"}. fiool(exp(-50}}
0.0000000000000000000001928749848
You cun use preIerences Lo conLroI LIe screen ouLpuL In oLIer wuys us weII. or
exumpIe, uILer cuIIIng Pref..oulpul(F}, MuPAD pusses every resuIL compuLed by
LIe kerneI Lo LIe IuncLIon F beIore prInLIng IL on LIe screen. TIe screen ouLpuL Is
LIen LIe resuIL oI LIe IuncLIon F InsLeud oI LIe resuIL orIgInuIIy compuLed by LIe
kerneI. n LIe IoIIowIng exumpIe, we use LIIs Lo compuLe und ouLpuL LIe
normuIIzuLIon oI every requesLed expressIon. We deIIne u procedure F
(CIupLer 1;) und puss IL Lo Pref..oulpul:
Pref..oulpul(x -> (x normoi(x}}}.
1 + x/(x + 1} - Z/x
x
x + 1

2
x
+ 1,
2 x
2
+x + 2
x
2
+x
TIe IIbrury generole conLuIns IuncLIons Ior converLIng MuPAD expressIons Lo LIe
InpuL IormuL oI oLIer progrummIng Iunguuges (C, orLrun, or T
E
X). n LIe
IoIIowIng exumpIe, LIe MuPAD ouLpuL Is converLed Lo u sLrIng. You mIgIL LIen
wrILe LIIs sLrIng Lo u LexL IIIe Ior IurLIer processIng wILI T
E
X:
Pref..oulpul(generole..TeX}. diff(f(x}x}
\Iruc{\purLIuI]{\purLIuI x] I\!\IeIL(x\rIgIL)
1-
T3 U|ili|ies
TIe IoIIowIng commund reseLs LIe ouLpuL rouLIne Lo ILs orIgInuI sLuLe:
Pref..oulpul(WTL}.
Some users wunL Lo obLuIn InIormuLIon on cerLuIn cIurucLerIsLIcs oI uII
compuLuLIons, sucI us compuLIng LImes. TIIs cun be ucIIeved wILI LIe IuncLIons
Pref..poslTnpul und Pref..posl0ulpul. BoLI Luke MuPAD procedures us
urgumenLs, wIIcI ure LIen cuIIed uILer eucI InpuL or ouLpuL, respecLIveIy. n LIe
IoIIowIng exumpIe, we use u procedure LIuL ussIgns LIe sysLem LIme reLurned by
lime(} Lo LIe gIobuI IdenLIIIer Time. TIIs sLurLs u LImer beIore eucI compuLuLIon:
Pref..poslTnpul(proc(} begin Time .= lime(} endproc}.
We deIIne u procedure myTnformolion wIIcI-umong oLIer LIIngs-uses LIIs
LImer Lo deLermIne LIe LIme Luken by LIe compuLuLIon. L empIoys exprZlexl
(SecLIon q.11) Lo converL LIe numerIcuI LIme vuIue Lo u sLrIng und concuLenuLes IL
wILI some oLIer sLrIngs. Moreover, LIe procedure uses domlype Lo IInd LIe
domuIn Lype oI LIe objecL und converLs IL Lo u sLrIng us weII. InuIIy IL
concuLenuLes LIe LIme InIormuLIon, some bIunks " ", und LIe Lype InIormuLIon vIu
concol. TIe IuncLIon ienglh Is used Lo deLermIne LIe precIse number oI bIunks
so LIuL LIe domuIn Lype uppeurs IIusIed rIgIL on LIe screen:
myTnformolion .= proc(} begin
"domoin lype. ". exprZlexl(domlype(orgs(}}}
"lime. ". exprZlexl(lime(} - Time}. " msec"
concol(x1
" " S TEXTnT0T|-1-ienglh(x1}-ienglh(xZ}
xZ}
endproc.
We puss LIIs procedure us urgumenL Lo Pref..posl0ulpul:
Pref..posl0ulpul(myTnformolion}.
AILer eucI compuLed resuIL, LIe sysLem now prInLs LIe sLrIng generuLed by LIe
procedure myTnformolion on LIe screen:
foclor(x^3 - 1}
(x 1)
_
x +x
2
+ 1
_
lime. 0 msec domoin lype. Foclored
1-q
UserDehned Prelerences
You cun reseL u preIerence Lo ILs deIuuIL vuIue by specIIyIng WTL us urgumenL. or
exumpIe, LIe commund Pref..reporl(WTL} reseLs LIe vuIue oI Pref..reporl Lo
0. SImIIurIy, Pref(WTL} reseLs cll preIerences Lo LIeIr deIuuIL vuIues.
Ixercise 1.1: TIe MuPAD IuncLIon byles reLurns LIe umounL oI IogIcuI und
pIysIcuI memory used by LIe currenL MuPAD sessIon. eL LIIs InIormuLIon uppeur
on LIe screen uILer eucI ouLpuL, usIng Pref..posl0ulpul.
1-g
T3 U|ili|ies
he kisIery Methuaism
Every InpuL Lo MuPAD

yIeIds u resuIL uILer evuIuuLIon by LIe sysLem. TIe


compuLed objecLs ure sLored InLernuIIy In u histor tcble. NoLe LIuL LIe resuIL oI
every sLuLemenL Is sLored, even II IL Is noL prInLed on LIe screen. You cun use IL
IuLer by meuns oI LIe IuncLIon iosl. TIe commund iosl(1} reLurns LIe prevIous
resuIL, iosl(Z} LIe IusL buL one, und so on. nsLeud oI iosl(i}, you muy use LIe
sIorLer noLuLIon xi. Moreover, x Is sIorL Ior x1 or iosl(1}. TIus LIe InpuL
f .= diff(in(in(x}} x}. inl(f x}
cun be pussed Lo LIe sysLem In LIe IoIIowIng equIvuIenL Iorm:
diff(in(in(x}} x}. inl(x x}
TIIs enubIes you Lo uccess InLermedIuLe resuILs LIuL Iuve noL been ussIgned Lo un
IdenLIIIer. L Is remurkubIe LIuL LIe use oI iosl muy speed up cerLuIn InLerucLIve
evuIuuLIons wIen compured Lo LIe use oI IdenLIIIers Lo sLore InLermedIuLe resuILs.
n LIe IoIIowIng exumpIe, we IIrsL Lry Lo compuLe u deIInILe InLegruI symboIIcuIIy.
AILer recognIzIng LIuL MuPAD does noL compuLe u symboIIc vuIue, we usk Ior u
IIouLIng-poInL upproxImuLIon:
f .= inl(sin(x}*exp(x^3}+x^Z*cos(exp(x}} x=0..1}
_
1
0
x
2
cos(e
x
) +e
x
3
sIn(x) dx
slorlingTime .= lime(}.
fiool(f}
(lime(} - slorlingTime}*msec
0.5356260737
750 msec
TIe IuncLIon lime reLurns LIe LoLuI compuLIng LIme (In mIIIIseconds) used by LIe
sysLem sInce LIe begInnIng oI LIe sessIon. TIus LIe prInLed dIIIerence Is LIe LIme
Ior compuLIng LIe IIouLIng-poInL upproxImuLIon.
1-6
The His|ory Nechonism
n LIIs exumpIe, we cun reduce LIe compuLIng LIme drumuLIcuIIy by empIoyIng
iosl:
f .= inl(sin(x}*exp(x^3}+x^Z*cos(exp(x}} x = 0..1}
_
1
0
x
2
cos(e
x
) +e
x
3
sIn(x) dx
slorlingTime .= lime(}.
fiool(xZ}
(lime(} - slorlingTime}*msec
0.5356260737
40 msec
n LIIs cuse, LIe reuson Ior LIe guIn In speed Is LIuL MuPAD does not re-etclucte
LIe objecLs LIuL iosl(i}, xi, or x reIer Lo.
1
TIus cuIIs Lo iosl Iorm un excepLIon Lo
LIe usuuI compIeLe evuIuuLIon uL InLerucLIve IeveI (SecLIon .z):
deiele x. sin(x}. x .= 0. xZ
sIn(x)
You cun enIorce compIeLe evuIuuLIon by usIng evoi:
deiele x. sin(x}. x .= 0. evoi(xZ}
0
PIeuse noLe LIuL LIe vuIue oI iosl(i} muy dIIIer Irom LIe i-LI buL IusL tisible
ouLpuL II you Iuve suppressed LIe screen ouLpuL oI some InLermedIuLe resuILs by
LermInuLIng LIe correspondIng communds wILI u coIon. AIso noLe LIuL LIe vuIue
oI LIe expressIon iosl(i} cIunges permunenLIy durIng u compuLuLIon:
1. iosl(1} + 1 iosl(1} + 1
2
3
1
NoLe LIuL LIIs guIn In speed Is onIy ucIIeved wIen workIng InLerucLIveIy, sInce IdenLIIIers ure evuI-
uuLed wILI IeveI 1 wILIIn procedures unywuy (SecLIon 1;.11).
1-,
T3 U|ili|ies
TIe envIronmenL vurIubIe |TST0RY deLermInes LIe number oI resuILs LIuL MuPAD
sLores In u sessIon und LIuL cun be uccessed vIu iosl:
|TST0RY
20
TIIs deIuuIL meuns LIuL MuPAD sLores LIe prevIous 20 expressIons. OI course you
cun cIunge LIIs deIuuIL by ussIgnIng u dIIIerenL vuIue Lo |TST0RY. TIIs muy be
upproprIuLe wIen MuPAD Ius Lo IundIe Iuge objecLs (sucI us very Iurge
muLrIces) LIuL IIII up u sIgnIIIcunL purL oI LIe muIn memory oI your compuLer.
CopIes oI LIese objecLs ure sLored In LIe IIsLory LubIe, requIrIng uddILIonuI sLoruge
spuce. n LIIs cuse, you wouId reduce LIe memory Ioud by cIoosIng smuII vuIues In
|TST0RY. NoLe LIuL |TST0RY onIy yIeIds LIe vuIue oI LIe InLerucLIve IIsLory
depLI. nsIde u procedure, iosl onIy uccepLs LIe urgumenLs 1, Z und 3.
We sLrongIy recommend Lo use iosl onIy InLerucLIveIy. TIe use oI iosl wILIIn
procedures Is consIdered bud progrummIng sLyIe und sIouId be uvoIded.
1-S
Inlormo|ion on NuPAD

Algori|hms
lalermuIiea ea MuFk0

klgeriIhms
Some MuPAD

sysLem IuncLIons muy provIde runLIme InIormuLIon. TIe IoIIowIng


commund mukes uII sucI procedures produce uddILIonuI InIormuLIon on LIe
screen:
seluserinfo(Any 1}.
As un exumpIe, we InverL LIe IoIIowIng muLrIx (SecLIon q.1) over LIe rIng oI
InLegers moduIo 11:
M .= 0om..Molrix(0om..TnlegerMod(11}}.
A .= M(__1 Z 3] _Z 4 7] _0 7 5]]}.
A^(-1}
Tnfo. using Coussion eiiminolion (LR decomposilion}
_
_
_
1 mod11 0 mod11 6 mod11
3 mod11 4 mod11 8 mod11
9 mod11 1 mod11 0 mod11
_
_
_
You obLuIn more deLuIIed InIormuLIon by IncreusIng LIe second urgumenL oI
seluserinfo (LIe InIormuLIon IeveI):
seluserinfo(Any 3}. A^(-1}
Tnfo. using Coussion eiiminolion (LR decomposilion}
Tnfo. seorching for pivol eiemenl in coiumn 1
Tnfo. choosing pivol eiemenl Z mod 11 (roW Z}
Tnfo. seorching for pivol eiemenl in coiumn Z
Tnfo. choosing pivol eiemenl 7 mod 11 (roW 3}
Tnfo. seorching for pivol eiemenl in coiumn 3
Tnfo. choosing pivol eiemenl 5 mod 11 (roW 3}
_
_
_
1 mod11 0 mod11 6 mod11
3 mod11 4 mod11 8 mod11
9 mod11 1 mod11 0 mod11
_
_
_
1-q
T3 U|ili|ies
I you enLer
seluserinfo(Any 0}.
LIe sysLem sLops prInLIng uddILIonuI InIormuLIon:
A^(-1}
_
_
_
1 mod11 0 mod11 6 mod11
3 mod11 4 mod11 8 mod11
9 mod11 1 mod11 0 mod11
_
_
_
TIe IIrsL urgumenL oI seluserinfo muy be un urbILrury procedure nume or IIbrury
nume. TIen LIe correspondIng procedure(s) provIde uddILIonuI InIormuLIon.
Progrummers oI LIe sysLem IuncLIons Iuve buIIL ouLpuL communds InLo LIe code
vIu userinfo. TIese communds ure ucLIvuLed by seluserinfo. You cun use LIIs In
your own procedures us weII (?userinfo).
1-1o
kes|or|ing o NuPAD

5ession
kesIurIiag u MuFk0

$essiea
TIe commund resel(} reseLs u MuPAD

sessIon Lo ILs InILIuI sLuLe. AILerwurds,


uII IdenLIIIers LIuL you deIIned prevIousIy Iuve no vuIue und uII envIronmenL
vurIubIes ure reseL Lo LIeIr deIuuIL vuIues:
o .= heiio. 0TCTTS .= 100. resel(}. o 0TCTTS
a, 10
1-11
T3 U|ili|ies
xetuIiag femmuads el Ihe 0peruIiag $ysIem
You cun use LIe IuncLIon syslem (or LIe excIumuLIon symboI ! Ior sIorL) Lo
execuLe u commund oI LIe operuLIng sysLem. On UNX

pIuLIorms, LIe IoIIowIng


commund IIsLs LIe conLenLs oI LIe currenL dIrecLory:
!is
bin Conlribulions doc fonls iib mmg
You cun neILIer use LIe ouLpuL oI sucI u commund Ior IurLIer compuLuLIon nor
suve IL Lo u IIIe.
z
syslem reLurns LIe error sLuLus oI LIe operuLIng sysLem Lo LIe
MuPAD

sessIon. WIen cuIIed wILI LIe ! synLux, LIe ouLpuL oI LIIs vuIue Is
suppressed.
z
I LIIs Is desIred, you cun use unoLIer commund oI LIe operuLIng sysLem Lo wrILe LIe ouLpuL Lo u
IIIe und reud LIIs IIIe InLo u MuPAD sessIon vIu imporl..reoddolo.
1-1
T4
Type SpeciIiers
TIe duLu sLrucLure oI u MuPAD

objecL Is ILs domuIn Lype, wIIcI cun be requesLed


by meuns oI LIe IuncLIon domlype. TIe domuIn Lype reIIecLs LIe sLrucLure LIuL LIe
MuPAD kerneI uses InLernuIIy Lo munuge LIe objecLs. TIe Lype concepL uIso Ieuds
Lo u cIussIIIcuLIon oI LIe objecLs uccordIng Lo LIeIr muLIemuLIcuI meunIng:
numbers, seLs, expressIons, serIes expunsIons, poIynomIuIs, eLc.
n LIIs secLIon, we descrIbe Iow Lo obLuIn deLuIIed InIormuLIon ubouL LIe
muLIemuLIcuI sLrucLure oI objecLs. or exumpIe, Iow cun you IInd ouL eIIIcIenLIy
wIeLIer un InLeger oI domuIn Lype 00MTWT Is positite or eten, or wIeLIer uII
eIemenLs oI u seL ure equuLIons?
SucI Lype cIecks ure bureIy reIevunL wIen usIng MuPAD InLerucLIveIy: you cun
conLroI LIe muLIemuLIcuI meunIng oI un objecL by dIrecL InspecLIon. Type cIecks
ure muInIy used Ior ImpIemenLIng muLIemuLIcuI uIgorILIms, I.e., wIen
progrummIng MuPAD procedures (CIupLer 1;). or exumpIe, u procedure Ior
dIIIerenLIuLIng expressIons Ius Lo decIde wIeLIer ILs InpuL Is u producL, u
composILIon oI IuncLIons, u symboIIc cuII oI u known IuncLIon, eLc. EucI cuse
requIres u dIIIerenL ucLIon, sucI us suppIyIng LIe producL ruIe, LIe cIuIn ruIe, eLc.
T4 Type 5pecihers
he luatIieas lype uad lesllype
or mosL MuPAD

objecLs, LIe IuncLIon lype reLurns, IIke domlype, LIe domuIn


Lype:
lype(_o b]} lype({o b]} lype(orroy(1..1}}
DOM_ST, DOM_SET, DOM_ARRAY
or expressIons oI domuIn Lype 00MEXPR, LIe IuncLIon lype yIeIds u IIner
dIsLIncLIon uccordIng Lo LIe muLIemuLIcuI meunIng oI LIe expressIon: sums,
producLs, IuncLIon cuIIs, eLc.:
lype(o + b} lype(o*b} lype(o^b} lype(o(b}}
_pIus, _muIL, _power, IuncLIon
lype(o = b} lype(o < b} lype(o <= b}
_equuI, _Iess, _IeequuI
or mosL oI LIese (wILI LIe excepLIon oI o(b}), LIe resuIL reLurned by lype Is LIe
nume oI LIe IuncLIon LIuL generuLes LIe expressIon (InLernuIIy, u symboIIc sum or
producL Is represenLed by u cuII oI LIe sysLem IuncLIons pius or muil,
respecLIveIy). More generuIIy, LIe resuIL Ior mosL symboIIc cuIIs oI sysLem
IuncLIons Is LIe IdenLIIIer oI LIe IuncLIon us u sLrIng:
lype(in(x}} lype(diff(f(x} x}} lype(focl(x}}
In, dIII, IucL
You cun use boLI LIe domuIn Lypes 00MTWT, 00MEXPR, eLc. und LIe sLrIngs
reLurned by lype us tpe specijiers. TIere exIsLs u vurIeLy oI oLIer Lype specIIIers
In uddILIon Lo LIe sLundurd LypIng oI MuPAD objecLs gIven by lype. An exumpIe
Is Type..Wumeric. TIIs Lype comprIses uII numerIcuI objecLs (oI domuIn Lype
00MTWT, 00MRAT, 00MFL0AT, or 00MC0MPLEX).
TIe cuII lesllype(obgecl lypeSpecifier} cIecks wIeLIer un objecL compIIes
wILI LIe specIIIed Lype. TIe resuIL Is eILIer TRuE or FALSE. SeveruI Lype specIIIers
muy correspond Lo un objecL:
lesllype(Z/3 00MRAT} lesllype(Z/3 Type..Wumeric}
TRUE, TRUE
1q-
The Func|ions lype ond lesllype
lesllype(Z + x "pius"} lesllype(Z + x 00MEXPR}
TRUE, TRUE
lesllype(f(x} "funclion"} lesllype(f(x} 00MEXPR}
TRUE, TRUE
Ixercise 1q.1: ConsIder LIe expressIon
f(i) =
i
5/2
+i
2
i
1/2
1
i
5/2
+i
2
+ 2 i
3/2
+ 2 i +i
1/2
+ 1
How cun MuPAD decIde wIeLIer LIe seL
S .= {f(i} S i = -1000..-Z] union {f(i} S i=0..1000].
conLuIns onIy ruLIonuI numbers? HInL: or u specIIIc InLeger i, use LIe IuncLIon
normoi Lo sImpIIIy subexpressIons oI f(i} conLuInIng squure rooLs.
Ixercise 1q.: ConsIder LIe expressIons sIn(i /200) wILI InLeger vuIues oI i
beLween 0 und 100. WIIcI oI LIem ure sImpIIIIed by LIe MuPAD sin IuncLIon,
wIIcI ure reLurned us symboIIc vuIues sin(}?
1q-
T4 Type 5pecihers
femlerIuble ype fhetkiag: Ihe Type librury
TIe Lype specIIIers presenLed ubove ure useIuI onIy Ior cIeckIng reIuLIveIy sImpIe
sLrucLures. or more udvunced Lype cIeckIng, more IIexIbIe Lype specIIIcuLIons ure
needed. or exumpIe, Iow cun you cIeck wILIouL dIrecL InspecLIon wIeLIer LIe
objecL _1Z3...] Is u IIsL oI posILIve InLegers?
or LIuL purpose, LIe Type IIbrury provIdes IurLIer Lype specIIIers und
consLrucLors. You cun use LIem Lo creuLe your own Lype specIIIers, wIIcI ure
recognIzed by lesllype:
info(Type}
Librory Type. lype expressions ond properlies
-- Tnlerfoce.
Type..AigebroicConslonl Type..AnyType
Type..Arilhmelicoi Type..Booieon
Type..Compiex Type..Condilion
Type..Conslonl Type..ConslonlTdenls
Type..Equolion Type..Even
Type..Funclion Type..Tmoginory
Type..Tndep0f Type..Tndelerminole
Type..Tnleger Type..Tnlerseclion
Type..Tnlervoi Type..Lisl0f
Type..LislProducl Type..WegTnl
Type..WegRol Type..Wegolive
Type..WonWegTnl Type..WonWegRol
Type..WonWegolive Type..WonZero
Type..Wumeric Type..0dd
Type..PoiyExpr Type..Poiy0f
Type..PosTnl Type..PosRol
Type..Posilive Type..Predicole
Type..Prime Type..Producl
Type..Properly Type..RolExpr
Type..Rolionoi Type..Reoi
Type..Reiolion Type..Residue
Type..Sequence0f Type..Series
Type..Sel Type..Sel0f
Type..Singielon Type..Tobie0f
Type..Tobie0fEnlry Type..Tobie0fTndex
Type..union Type..unknoWn
Type..Zero
1q-q
Comlor|oble Type Checking: |he Type Iibrory
or exumpIe, LIe Lype specIIIer Type..PosTnl represenLs LIe seL oI posILIve
InLegers n > 0, Type..WonWegTnl corresponds Lo LIe nonneguLIve InLegers n 0,
Type..Even und Type..0dd represenL LIe even und odd InLegers, respecLIveIy.
TIese Lype specIIIers ure oI domuIn Lype Type:
domlype(Type..Even}
Type
You cun use sucI Lype specIIIers Lo query LIe muLIemuLIcuI sLrucLure oI MuPAD
objecLs vIu lesllype. n LIe IoIIowIng exumpIe, we exLrucL uII even InLegers Irom u
IIsL oI InLegers vIu seiecl (SecLIon q.6):
seiecl(_i S i = 1..Z0] lesllype Type..Even}
[2, 4, 6, 8, 10, 12, 14, 16, 18, 20]
You cun use consLrucLors sucI us Type..Lisl0f or Type..Sel0f Lo perIorm Lype
cIeckIng Ior IIsLs or seLs. or exumpIe, u IIsL oI InLegers Is muLcIed by LIe Lype
Type..Lisl0f(00MTWT}, u seL oI equuLIons corresponds Lo LIe Lype specIIIers
Type..Sel0f(Type..Equolion(}} (or Type..Sel0f("equoi"}), u seL oI odd
InLegers Is muLcIed by LIe Lype Type..Sel0f(Type..0dd}:
T .= Type..Lisl0f(00MTWT}.
lesllype(_-1 1] T} lesllype({-1 1] T}
lesllype(_-1 1.0] T}
TRUE, ASE, ASE
TIe consLrucLor Type..union generuLes Lype specIIIers correspondIng Lo LIe
unIon oI sImpIer Lypes. or exumpIe, LIe IoIIowIng Lype specIIIer
T .= Type..union(00MFL0AT Type..WegTnl Type..Even}.
muLcIes reuI IIouLIng-poInL numbers us weII us neguLIve InLegers us weII us even
InLegers:
lesllype(-0.1Z3 T} lesllype(-3 T}
lesllype(Z T} lesllype(3 T}
TRUE, TRUE, TRUE, ASE
We descrIbe un uppIIcuLIon oI Lype cIeckIng Ior LIe ImpIemenLuLIon oI MuPAD
procedures In SecLIon 1;.;.
1q-g
T4 Type 5pecihers
Ixercise 1q.: How cun you compuLe LIe InLersecLIon oI u seL wILI LIe seL oI
posILIve InLegers?
Ixercise 1q.q: Use ?Type..Lisl0f Lo consuIL LIe IeIp puge Ior LIIs Lype
consLrucLor. ConsLrucL u Lype specIIIer correspondIng Lo u IIsL oI Lwo eIemenLs
sucI LIuL eucI eIemenL Is uguIn u IIsL wILI LIree urbILrury eIemenLs.
1q-6
T5
Loops
oops ure ImporLunL eIemenLs oI LIe MuPAD

progrummIng Iunguuge. TIe


IoIIowIng exumpIe IIIusLruLes LIe sImpIesL Iorm oI u for Ioop:
for i from 1 lo 4 do
x .= i^Z
prinl("The squore of" i "is" x}
endfor.
"The squore of" 1 "is" 1
"The squore of" Z "is" 4
"The squore of" 3 "is" 9
"The squore of" 4 "is" 16
TIe Ioop vurIubIe i uuLomuLIcuIIy runs LIrougI LIe vuIues 1, 2, 3, 4. or eucI vuIue
oI i, uII communds beLween do und endfor ure execuLed. TIere muy be
urbILrurIIy muny communds, sepuruLed by semIcoIons or coIons. The sstem does
not print the results computed in ecch loop iterction on the screen, eten ij ou
termincte the commcnds b semicolons. or LIuL reuson, we used LIe prinl
commund Lo generuLe un ouLpuL In LIe ubove exumpIe.
T5 Ioops
TIe IoIIowIng vurIunL counLs buckwurds. We use LIe LooIs Irom SecLIon q.11 Lo
muke LIe ouLpuL Iook more uppeuIIng:
for g from 4 doWnlo Z do
prinl(unquoled
"The squore of ".exprZlexl(g}." is ".
exprZlexl(g^Z}}
endfor.
The squore of 4 is 16
The squore of 3 is 9
The squore of Z is 4
You cun use LIe keyword slep Lo IncremenL or decremenL LIe Ioop vurIubIe In
bIgger or smuIIer sLeps:
for x from 3 lo slep Z do prinl(x x^Z} endfor.
3 9
5 Z5
7 49
NoLe LIuL uL LIe end oI LIe ILeruLIon wILI x = 7 LIe vuIue oI x Is IncremenLed Lo 9.
TIIs exceeds LIe upper bound 8, und LIe Ioop LermInuLes. Here Is unoLIer vurIunL
oI LIe for Ioop:
for i in _5 Z7 y] do prinl(i i^Z} endfor.
5 Z5
Z7 7Z9
Z
y y
TIe Ioop vurIubIe onIy runs LIrougI LIe vuIues Irom LIe IIsL [5, 27, y]. As you cun
see, sucI u IIsL muy conLuIn symboIIc eIemenLs sucI us LIe vurIubIe y.
1g-
Ioops
n u for Ioop, u Ioop vurIubIe cIunges uccordIng Lo IIxed ruIes (LypIcuIIy, IL Is
IncremenLed or decremenLed). TIe repeol Ioop Is u more IIexIbIe uILernuLIve,
wIere you cun urbILrurIIy modIIy muny vurIubIes In eucI sLep. n LIe IoIIowIng
exumpIe, we compuLe LIe squures oI LIe InLegers i = 2, 2
2
, 2
4
, 2
8
, . . . unLII i
2
> 100
IoIds Ior LIe IIrsL LIme:
x .= Z.
repeol
i .= x x .= i^Z prinl(i x}
unlii x > 100 endrepeol.
Z 4
4 16
16 Z56
TIe sysLem execuLes LIe communds beLween repeol und unlii repeuLedIy. TIe
Ioop LermInuLes wIen LIe condILIon beLween unlii und endrepeol IoIds Lrue. n
LIe ubove exumpIe, we Iuve i = 4 und x = 16 uL LIe end oI LIe second sLep. Hence
LIe LIIrd sLep Is execuLed, und uILerwurds we Iuve i = 16, x = 256. Now LIe
LermInuLIon condILIon x > 100 Is suLIsIIed und LIe Ioop LermInuLes.
AnoLIer Ioop vurIunL Is LIe Whiie Ioop:
x .= Z.
Whiie x <= 100 do
i .= x x .= i^Z prinl(i x}
endWhiie.
Z 4
4 16
16 Z56
n u repeol Ioop, LIe sysLem cIecks LIe LermInuLIon condILIon cjter eucI Ioop
ILeruLIon. n u Whiie Ioop, LIIs condILIon Is cIecked bejore eucI ILeruLIon. As soon
us LIe condILIon evuIuuLes Lo FALSE, LIe sysLem LermInuLes LIe Whiie Ioop.
1g-
T5 Ioops
You cun use breok Lo uborL u Ioop expIIcILIy. TypIcuIIy LIIs Is done wILIIn un if
consLrucLIon (CIupLer 16):
for i from 3 lo 100 do
prinl(i}
if i^Z > Z0 lhen breok endif
endfor.
3
4
5
AILer u cuII Lo nexl, LIe sysLem skIps uII communds up Lo endfor. L reLurns
ImmedIuLeIy Lo LIe begInnIng oI LIe Ioop und sLurLs LIe nexL ILeruLIon wILI LIe
nexL vuIue oI LIe Ioop vurIubIe:
for i from Z lo 5 do
x .= i
if i > 3 lhen nexl endif
y .= i
prinl(x y}
endfor.
Z Z
3 3
or i > 3, onIy LIe IIrsL ussIgnmenL x.=i Is execuLed:
x y
5, 3
1g-q
Ioops
We recuII LIuL every MuPAD commund reLurns un objecL. or u Ioop, LIIs Is LIe
reLurn vuIue oI LIe mosL recenLIy execuLed commund. I you do noL LermInuLe LIe
Ioop commund wILI u coIon us In uII oI LIe ubove exumpIes, LIen MuPAD dIspIuys
LIIs vuIue:
deiele x. for i from 1 lo 3 do x.i .= i^Z endfor
9
You muy process LIIs vuIue IurLIer. n purLIcuIur, you cun ussIgn IL Lo un IdenLIIIer
or use IL us LIe reLurn vuIue oI u MuPAD procedure (CIupLer 1;):
foclorioi .= proc(n}
iocoi resuil
begin
resuil .= 1
for i from Z lo n do
resuil .= resuil * i
endfor
endproc.
TIe reLurn vuIue oI LIe ubove procedure Is LIe reLurn vuIue oI LIe for Ioop, wIIcI
In Lurn Is LIe vuIue oI LIe IusL ussIgnmenL Lo resuil.
nLernuIIy, Ioops ure sysLem IuncLIon cuIIs. or exumpIe, MuPAD processes u for
Ioop by evuIuuLIng LIe IuncLIon for:
for(i firsli iosli incremenl commond}.
TIIs Is equIvuIenL Lo
for i from firsli lo iosli slep incremenl do
commond
endfor.
1g-g
T6
Brunching: if-lhen-eise und cose
rcnchin instructions ure un ImporLunL eIemenL oI every progrummIng
Iunguuge. DependIng on LIe vuIue or LIe meunIng oI vurIubIes, dIIIerenL
communds ure execuLed. TIe sImpIesL vurIunL In MuPAD

Is LIe if sLuLemenL:
for i from Z lo 4 do
if isprime(i}
lhen prinl(exprZlexl(i}." is prime"}
eise prinl(exprZlexl(i}." is nol prime"}
endif
endfor.
"Z is prime"
"3 is prime"
"4 is nol prime"
Here, LIe prImuIILy LesL isprime(i} reLurns eILIer TRuE or FALSE. I LIe vuIue Is
TRuE, LIe sysLem execuLes LIe communds beLween lhen und eise (In LIIs cuse,
onIy one prinl commund). I IL Is FALSE, LIe communds beLween eise und endif
ure execuLed. TIe eise bruncI Is opLIonuI:
for i from Z lo 4 do
if isprime(i}
lhen lexl .= exprZlexl(i}." is prime"
prinl(lexl}
endif
endfor.
"Z is prime"
"3 is prime"
T ronching: if-lhen-eise ond cose
Here, LIe lhen bruncI comprIses Lwo communds sepuruLed by u semIcoIon (or,
uILernuLIveIy, u coIon). You muy nesL communds, Ioops, und bruncIIng sLuLemenLs
urbILrurIIy:
primes .= _]. evenWumbers .= _].
for i from 30 lo 50 do
if isprime(i}
lhen primes .= primes._i]
eise if lesllype(iType..Even}
lhen evenWumbers .= evenWumbers._i]
endif
endif
endfor.
n LIIs exumpIe, we InspecL LIe InLegers beLween 30 und 50. I we encounLer u
prIme, LIen we uppend IL Lo LIe IIsL primes. OLIerwIse, we use lesllype Lo cIeck
wIeLIer i Is even (see SecLIons 1q.1 und 1q.z). n LIuL cuse, we uppend i Lo LIe IIsL
evenWumbers. Upon LermInuLIon, LIe IIsL primes conLuIns uII prIme numbers
beLween 30 und 50, wIIIsL evenWumbers conLuIns uII even InLegers In LIIs runge:
primes evenWumbers
[31, 37, 41, 43, 47] , [30, 32, 34, 36, 38, 40, 42, 44, 46, 48, 50]
You cun creuLe more compIex condILIons Ior LIe if sLuLemenL by usIng LIe
BooIeun operuLors ond, or, und nol (SecLIon q.1o). TIe IoIIowIng for Ioop prInLs
uII prIme LwIns [i, i + 2] wILI i 100. TIe uILernuLIve condILIon nol (i>3} yIeIds
LIe uddILIonuI puIr [2, 4]:
for i from Z lo 100 do
if (isprime(i} ond isprime(i+Z}} or nol (i>3}
lhen prinl(_ii+Z]}
endif
endfor.
_Z 4]
_3 5]
_5 7]
...
16-
ronching: if-lhen-eise ond cose
nLernuIIy, un if sLuLemenL Is jusL u cuII oI LIe sysLem IuncLIon if:
if(condilion commond1 commondZ}.
Is equIvuIenL Lo
if condilion lhen commond1 eise commondZ endif.
TIe reLurn vuIue oI un if sLuLemenL Is, us Ior uny MuPAD procedure, LIe resuIL oI
LIe IusL execuLed commund:
1
x .= -Z. if x > 0 lhen x eise -x endif
2
or exumpIe, you cun use LIe urrow operuLor -> (SecLIon q.1z) Lo ImpIemenL LIe
ubsoIuLe vuIue oI numbers us IoIIows:
Abs .= y -> (if y > 0 lhen y eise -y endif}.
Abs(-Z} Abs(-Z/3} Abs(3.5}
2,
2
3
, 3.5
As you cun see, you cun use if communds boLI uL LIe InLerucLIve IeveI und wILIIn
procedures. TIe LypIcuI uppIIcuLIon Is In progrummIng MuPAD procedures, wIere
if sLuLemenLs und Ioops conLroI LIe IIow oI LIe uIgorILIm. A sImpIe exumpIe Is LIe
ubove IuncLIon Abs. You IInd more exumpIes In CIupLer 1;.
I you Iuve severuI nesLed if . eise if . consLrucLIons, you cun ubbrevIuLe LIIs by
usIng LIe eiif sLuLemenL:
if condilion1 lhen
slolemenls1
eiif condilionZ lhen
slolemenlsZ
eiif ...
eise
slolemenls
endif.
1
I no commund Is execuLed LIen LIe resuIL Is nuii(}.
16-
T ronching: if-lhen-eise ond cose
TIIs Is equIvuIenL Lo LIe IoIIowIng nesLed if sLuLemenL:
if condilion1 lhen
slolemenls1
eise if condilionZ lhen
slolemenlsZ
eise if ...
eise
slolemenls
endif
endif
endif.
A LypIcuI uppIIcuLIon Is Ior Lype cIeckIng wILIIn procedures (CIupLer 1;). TIe
IoIIowIng versIon oI Abs compuLes LIe ubsoIuLe vuIue II LIe InpuL Is un InLeger, u
ruLIonuI number, u reuI IIouLIng-poInL number, or u compIex numberu. OLIerwIse,
IL ruIses un error:
Abs .= proc(y} begin
if (domlype(y} = 00MTWT} or (domlype(y} = 00MRAT}
or (domlype(y} = 00MFL0AT} lhen
if y > 0 lhen y eise -y endif
eiif (domlype(y} = 00MC0MPLEX} lhen
sqrl(Re(y}^Z + Tm(y}^Z}
eise "Tnvoiid orgumenl lype" endif.
endproc.
deiele x. Abs(-3} Abs(5.0} Abs(1+Z*T} Abs(x}
3, 5.0,

5, nvuIId urgumenL Lype


16-q
ronching: if-lhen-eise ond cose
n our exumpIe, we dIsLInguIsI severuI cuses uccordIng Lo LIe evuIuuLIon oI u
sIngIe expressIon. We cun uIso ImpIemenL LIIs by usIng u cose sLuLemenL, wIIcI Is
oILen eusIer Lo reud:
cose domlype(y}
of 00MTWT do
of 00MRAT do
of 00MFL0AT do
if y > 0 lhen y eise -y endif
breok
of 00MC0MPLEX do
sqrl(Re(y}^Z + Tm(y}^Z}
breok
olherWise
"Tnvoiid orgumenl lype"
endcose.
TIe keywords cose und endcose IndIcuLe LIe begInnIng und LIe end oI LIe
sLuLemenL, respecLIveIy. MuPAD evuIuuLes LIe expressIon uILer cose. I LIe resuIL
muLcIes one oI LIe expressIons beLween of und do, LIe sysLem execuLes uII
communds Irom LIe IIrsL muLcIIng of on unLII IL encounLers eILIer u breok or LIe
keyword endcose.
Wurning: NoLe LIuL, II no breok sLuLemenL used In u bruncI, LIe IoIIowIng
bruncIes ure enLered und execuLed, Loo. TIIs Is In LIe sume sLyIe us LIe sWilch
sLuLemenL In LIe C progrummIng Iunguuge. L uIIows severuI bruncIes Lo sIure LIe
sume code.
I none oI LIe of bruncIes uppIIes und LIere Is un olherWise bruncI, LIe code
beLween olherWise und endcose Is execuLed. TIe reLurn vuIue oI u cose
sLuLemenL Is LIe vuIue oI LIe IusL execuLed commund. We reIer Lo LIe
correspondIng IeIp puge ?cose Ior u more deLuIIed descrIpLIon.
16-g
T ronching: if-lhen-eise ond cose
As Ior Ioops und if sLuLemenLs, LIere Is u IuncLIonuI equIvuIenL Ior u cose
sLuLemenL: LIe sysLem IuncLIon cose. nLernuIIy, MuPAD converLs LIe ubove
cose sLuLemenL Lo LIe IoIIowIng equIvuIenL Iorm:
cose(domlype(y}
00MTWT WTL
00MRAT WTL
00MFL0AT
(if y > 0 lhen y eise -y endif breok}
00MC0MPLEX (sqrl(Re(y}^Z + Tm(y}^Z} breok}
"Tnvoiid orgumenl lype"}.
Ixercise 16.1: n if sLuLemenLs or LermInuLIon condILIons oI Whiie und repeol
Ioops, LIe sysLem evuIuuLes composILe condILIons wILI BooIeun operuLors one
uILer LIe oLIer. TIe evuIuuLIon rouLIne sLops premuLureIy II IL cun decIde wIeLIer
LIe IInuI resuIL Is TRuE or FALSE (Iuzy evuIuuLIon). Are LIere probIems wILI LIe
IoIIowIng sLuLemenLs? WIuL Iuppens wIen LIe condILIons ure evuIuuLed?
A .= x/(x - 1} > 0. x .= 1.
(if x <> 1 ond A lhen righl eise Wrong endif}
(if x = 1 or A lhen righl eise Wrong endif}
16-6
T7
MoPA

Procedores
MuPAD

provIdes LIe essenLIuI consLrucLs oI u progrummIng Iunguuge. TIe user


cun ImpIemenL compIex uIgorILIms comIorLubIy In MuPAD. ndeed, mosL oI
MuPAD`s muLIemuLIcuI InLeIIIgence Is noL ImpIemenLed In C or C++ wILIIn LIe
kerneI, buL In LIe MuPAD progrummIng Iunguuge uL LIe IIbrury IeveI. TIe
progrummIng IeuLures ure more exLensIve LIun In oLIer Iunguuges sucI us C,
PuscuI, or orLrun, sInce LIe MuPAD Iunguuge oIIers more generuI und more
IIexIbIe consLrucLs.
We Iuve uIreudy presenLed busIc sLrucLures sucI us Ioops (CIupLer 1), bruncIIng
InsLrucLIons (CIupLer 16), und sImpIe IuncLIons (puge q-z).
n LIIs cIupLer, we regurd progrummIng us wrILIng compIex MuPAD procedures.
n prIncIpIe LIe user recognIzes no dIIIerences beLween sImpIe IuncLIons
generuLed vIu -> (puge q-z) und more compIex procedures us presenLed In LIIs
cIupLer. Procedures, IIke IuncLIons, reLurn vuIues. OnIy LIe wuy oI generuLIng
sucI procedure objecLs vIu proc .endproc Is u IILLIe more compIIcuLed.
Procedures provIde uddILIonuI IuncLIonuIILy: LIere Is u dIsLIncLIon beLween IocuI
und gIobuI vurIubIes, you cun use urbILrurIIy muny communds In u cIeur und
convenIenL wuy eLc.
As soon us u procedure Is ImpIemenLed und ussIgned Lo un IdenLIIIer, you muy cuII
IL In LIe Iorm procedureWome(orgumenls} IIke uny oLIer MuPAD IuncLIon. AILer
execuLIng LIe ImpIemenLed uIgorILIm, IL reLurns un ouLpuL vuIue.
You cun deIIne und use MuPAD procedures wILIIn un InLerucLIve sessIon, IIke uny
oLIer MuPAD objecL. TypIcuIIy, Iowever, you wunL Lo use LIese procedures uguIn
In IuLer sessIons, In purLIcuIur wIen LIey ImpIemenL more compIex uIgorILIms.
TIen IL Is useIuI Lo wrILe LIe procedure deIInILIon InLo u LexL IIIe usIng your
IuvorILe LexL edILor (sucI us, e.g., LIe MuPAD source code edILor), und reud IL InLo
TZ NuPAD

Procedures
u MuPAD sessIon vIu reod (puge 1z-) or wILI LIe enLry 'Reud communds .` Irom
LIe 'NoLebook` menu. ApurL Irom LIe evuIuuLIon IeveI, LIe MuPAD kerneI
processes LIe communds In LIe IIIe exucLIy In LIe sume wuy us II LIey were enLered
InLerucLIveIy. MuPAD IncIudes un edILor wILI synLux IIgIIIgILIng Ior MuPAD
progrums.
1,-
Dehning Procedures
0ehaiag Fretedures
TIe IoIIowIng IuncLIon, wIIcI compures Lwo numbers und reLurns LIeIr
muxImum, Is un exumpIe oI u procedure deIInILIon vIu proc .endproc:
moximum .= proc(o b} /* commenl. moximum of o ond b */
begin
if o<b lhen relurn(b} eise relurn(o} endif
endproc.
TIe LexL encIosed beLween /* und */ Is u commenL
1
und compIeLeIy Ignored by LIe
sysLem. TIIs Is u useIuI LooI Ior documenLIng LIe source code wIen you wrILe LIe
procedure deIInILIon In u LexL IIIe.
TIe ubove sumpIe procedure conLuIns un if sLuLemenL us LIe onIy commund.
More reuIIsLIc procedures conLuIn muny communds (sepuruLed by coIons or
semIcoIons). TIe commund relurn LermInuLes u procedure und pusses ILs
urgumenL us ouLpuL vuIue Lo LIe sysLem.
A MuPAD

objecL generuLed vIu proc .endproc Is oI domuIn Lype 00MPR0C:


domlype(moximum}
DOM_PROC
You cun decompose und munIpuIuLe u procedure IIke uny oLIer MuPAD objecL. n
purLIcuIur, you muy ussIgn IL Lo un IdenLIIIer, us ubove. TIe synLux oI LIe IuncLIon
cuII Is LIe sume us Ior oLIer MuPAD IuncLIons:
moximum(3/7 0.4}
3
7
TIe sLuLemenLs beLween begin und endproc muy be urbILrury MuPAD
communds. n purLIcuIur, you muy cuII sysLem IuncLIons or oLIer procedures Irom
wILIIn u procedure. A procedure muy even cuII ILseII, wIIcI Is IeIpIuI Ior
ImpIemenLIng recursIve uIgorILIms.
1
AILernuLIveIy, you cun sLurL u commenL by //. A commenL sLurLed wILI // uuLomuLIcuIIy ends uL LIe
end oI LIe IIne.
1,-
TZ NuPAD

Procedures
TIe IuvorILe exumpIe Ior u recursIve uIgorILIm Is LIe compuLuLIon oI LIe IucLorIuI
n! = 1 2 n oI u nonneguLIve InLeger, wIIcI muy be deIIned by LIe ruIe
n! = n (n 1)! LogeLIer wILI LIe InILIuI condILIon 0! = 1. TIe reuIIzuLIon us u
recursIve procedure mIgIL Iook us IoIIows:
foclorioi .= proc(n} begin
if n = 0 lhen
relurn(1}
eise relurn(n*foclorioi(n - 1}}
endif
endproc.
foclorioi(10}
3628800
TIe envIronmenL vurIubIe MAX0EPT| deLermInes LIe muxImuI number oI nesLed
procedure cuIIs. Ls deIuuIL vuIue Is 500. WILI LIIs vuIue, LIe ubove IucLorIuI
IuncLIon works onIy Ior n 500. or Iurger vuIues, uILer MAX0EPT| sLeps MuPAD
ussumes LIuL LIere Is un InIInILe recursIon und uborLs wILI un error messuge. L Is
udvIsubIe Lo uvoId deep recursIons, Lo suve on memory, Increuse eIIIcIency und Lo
uvoId LIese probIems.
1,-q
The ke|urn Volue ol o Procedure
he keIura ulue el u Fretedure
WIen you cuII u procedure, LIe sysLem execuLes ILs body, I.e., LIe sequence oI
sLuLemenLs beLween begin und endproc. Every procedure reLurns some vuIue,
eILIer expIIcILIy vIu relurn or oLIerwIse the tclue oj the lcst commcnd executed
uithin the procedure.
z
TIus, you cun ImpIemenL LIe ubove IucLorIuI IuncLIon
wILIouL usIng relurn:
foclorioi .= proc(n} begin
if n = 0 lhen 1 eise n*foclorioi(n - 1} endif
endproc.
TIe if sLuLemenL reLurns eILIer 1 or n(n 1)! . SInce LIe end oI LIe procedure Is
reucIed dIrecLIy uILer LIe if sLuLemenL, LIIs Is LIe reLurn vuIue oI LIe cuII
foclorioi(n}.
As soon us LIe sysLem encounLers u relurn sLuLemenL, IL LermInuLes LIe procedure:
foclorioi .= proc(n} begin
if n = 0 lhen relurn(1} endif
n*foclorioi(n - 1}
endproc.
or n = 0, MuPAD

does noL execuLe LIe IusL sLuLemenL (LIe recursIve cuII oI


n*foclorioi(n-1}) uILer reLurnIng 1. or n = 0, LIe mosL recenLIy compuLed
vuIue Is n*foclorioi(n-1}, wIIcI Is LIen LIe reLurn vuIue oI LIe cuII
foclorioi(n}.
z
I LIere Is no commund Lo execuLe, LIe reLurn vuIue Is WTL.
1,-g
TZ NuPAD

Procedures
A procedure muy reLurn un urbILrury MuPAD objecL, sucI us un expressIon, u
sequence, u seL, u IIsL, or even u procedure. However, II LIe reLurned procedure
uses IocuI vurIubIes oI LIe ouLer procedure, you Iuve Lo decIure LIe IuLLer wILI LIe
opLIon escope. OLIerwIse, LIIs Ieuds Lo u MuPAD wurnIng messuge or Lo
unwunLed eIIecLs. TIe IoIIowIng procedure reLurns u IuncLIon LIuL uses LIe
purumeLer poWer oI LIe ouLer procedure:
generolePoWerFunclion .= proc(poWer}
oplion escope
begin
x -> (x^poWer}
endproc.
f .= generolePoWerFunclion(Z}.
g .= generolePoWerFunclion(5}.
f(o} g(b}
a
2
, b
5
1,-6
ke|urning 5ymbolic Func|ion Colls
keIuraiag $ymbelit luatIiea fulls
Muny sysLem IuncLIons reLurn LIemseIves us symboIIc IuncLIon cuIIs II LIey
cunnoL IInd u sImpIe represenLuLIon oI LIe requesLed resuIL:
sin(x} mox(o b} inl(exp(x^3} x}
sIn(x) , mux(a, b) ,
_
e
x
3
dx
You ucIIeve LIe sume beIuvIor In your own procedures wIen you encupsuIuLe LIe
procedure nume In u hoid upon reLurn. TIe hoid (puge -q) prevenLs LIe IuncLIon
Irom cuIIIng ILseII recursIveIy und endIng up In un InIInILe recursIon. TIe
IoIIowIng IuncLIon compuLes LIe ubsoIuLe vuIue Ior numerIcuI InpuLs (InLegers,
ruLIonuI numbers, reuI IIouLIng-poInL numbers, und compIex numbers). or uII
oLIer kInds oI InpuLs, IL reLurns ILseII symboIIcuIIy:
Abs .= proc(x} begin
if lesllype(x Type..Wumeric} lhen
if domlype(x} = 00MC0MPLEX lhen
relurn(sqrl(Re(x}^Z + Tm(x}^Z}}
eise if x >= 0 lhen
relurn(x}
eise relurn(-x}
endif
endif
endif
hoid(Abs}(x}
endproc.
Abs(-1} Abs(-Z/3} Abs(1.Z34} Abs(Z + T/3}
Abs(x + 1}
1,
2
3
, 1.234,

37
3
, Abs(x + 1)
1,-,
TZ NuPAD

Procedures
A more eIegunL wuy Is Lo use LIe MuPAD

objecL procnome, wIIcI reLurns LIe


nume oI LIe cuIIIng procedure:
Abs .= proc(x} begin
if lesllype(x Type..Wumeric} lhen
if domlype(x} = 00MC0MPLEX lhen
relurn(sqrl(Re(x}^Z + Tm(x}^Z}}
eise if x >= 0 lhen
relurn(x}
eise relurn(-x}
endif
endif
endif
procnome(orgs(}}
endproc.
Abs(-1} Abs(-Z/3} Abs(1.Z34} Abs(Z + T/3}
Abs(x + 1}
1,
2
3
, 1.234,

37
3
, Abs(x + 1)
Here, we use LIe expressIon orgs(}, wIIcI reLurns LIe sequence oI urgumenLs
pussed Lo LIe procedure (cI. puge 1;-z1).
1,-S
Iocol ond Globol Voriobles
letul uad 6lebul uriubles
You cun use urbILrury IdenLIIIers In procedures. TIey ure uIso cuIIed lobcl
tcricbles:
o .= b. f .= proc(} begin o .= o^Z + 1 endproc.
f(} f(} f(}
b
2
+ 1
_
b
2
+ 1
_
2
+ 1
_
_
b
2
+ 1
_
2
+ 1
_
2
+ 1
TIe procedure f modIIIes LIe vuIue oI o, wIIcI Ius been seL ouLsIde LIe
procedure. WIen LIe procedure LermInuLes, o Ius u new vuIue, wIIcI Is uguIn
cIunged by IurLIer cuIIs Lo f.
TIe keyword iocoi decIures IdenLIIIers us loccl tcricbles LIuL ure onIy vuIId
wILIIn LIe procedure:
o .= b. f .= proc(} iocoi o begin o .= Z endproc.
f(}. o
b
DespILe LIe equuI numes, LIe ussIgnmenL o.=Z oI LIe IocuI vurIubIe does noL uIIecL
LIe vuIue oI LIe gIobuI IdenLIIIer o LIuL Ius been deIIned ouLsIde LIe procedure.
You cun decIure un urbILrury number oI IocuI vurIubIes by specIIyIng u sequence oI
IdenLIIIers uILer iocoi:
f .= proc(x y z}
iocoi A B C
begin
A.= 1 B.= Z C.= 3 A*B*C*(x + y + z}
endproc.
f(A B C}
6 A+ 6 B + 6 C
1,-q
TZ NuPAD

Procedures
ocuI vurIubIes oI u procedure Iuve u specIuI domuIn Lype 00MvAR. TIey do noL
geL mIxed up wILI gIobuI vurIubIes wIIcI ure IdenLIIIers oI Lype 00MT0EWT. NoLe
LIuL uIso IocuI vurIubIes decIured by LIe sume nume In LIe source code oI dIIIerenL
IuncLIons Iuve no reIerence Lo one unoLIer. AIso, wIen cuIIIng u IuncLIon severuI
LImes, u IocuI vurIubIe reIers Lo u dIIIerenL vuIue In eucI cuII:
f .= proc(x} iocoi o b
begin
o .= x
if x > 0 lhen b .= f(x - 1}
eise b .= 1
endif
prinl(o x}
b + o
end.
f(Z}
0 0
1 1
Z Z
4
We recommend Lo Luke InLo uccounL LIe IoIIowIng ruIe oI LIumb:
UsIng gIobuI vurIubIes Is generuIIy consIdered bud progrummIng sLyIe.
Use IocuI vurIubIes wIenever possIbIe.
TIe reuson Ior LIIs prIncIpIe Is LIuL procedures ImpIemenL muLIemuLIcuI
IuncLIons, wIIcI sIouId reLurn u unIque ouLpuL vuIue Ior u gIven seL oI InpuL
vuIues. I you use gIobuI vurIubIes LIen, dependIng on LIeIr vuIues, LIe sume
procedure cuII muy Ieud Lo dIIIerenL resuILs:
o .= 1. f .= proc(b} begin o .= o + 1 o + b endproc.
f(1} f(1} f(1}
3, 4, 5
Moreover, u procedure cuII cun cIunge LIe cuIIIng envIronmenL In u subLIe wuy by
redeIInIng gIobuI vurIubIes (sIde eIIecL). n more compIex progrums, LIIs muy
Ieud Lo unwunLed eIIecLs LIuL ure dIIIIcuIL Lo debug.
1,-1o
Iocol ond Globol Voriobles
An ImporLunL dIIIerence beLween gIobuI und IocuI vurIubIes Is LIuL un unInILIuIIzed
gIobuI vurIubIe Is regurded us u smbol, wIose vuIue Is ILs own nume, wIIIe LIe
vuIue oI un unInILIuIIzed IocuI vurIubIe Is WTL. UsIng u IocuI vurIubIe wILIouL
InILIuIIzuLIon Ieuds Lo u wurnIng messuge In MuPAD

und sIouId be uvoIded:


TAmCioboi + 1
AmGIobuI + 1
f .= proc(}
iocoi TAmLocoi
begin
TAmLocoi + 1
endproc.
f(}
norning. uninilioiized voriobie TAmLocoi used
during evoiuolion of f
Error. Tiiegoi operond _pius]
during evoiuolion of f
TIe reuson Ior LIe error Is LIuL MuPAD cunnoL udd LIe vuIue WTL oI LIe IocuI
vurIubIe Lo LIe number 1.
We now presenL u reuIIsLIc exumpIe oI u meunIngIuI procedure. I we use urruys oI
domuIn Lype 00MARRAY Lo represenL muLrIces, we ure Iuced wILI LIe probIem LIuL
LIere Is no dIrecL wuy Lo perIorm muLrIx muILIpIIcuLIon wILI sucI urruys.

TIe
IoIIowIng procedure soIves LIIs probIem: you cun compuLe LIe muLrIx producL
C = A B wILI LIe commund C.=MolrixProducl(AB}. We wunL LIe procedure Lo
work Ior urbILrury dImensIons oI LIe muLrIces A und B, provIded LIe resuIL Is
deIIned muLIemuLIcuIIy. I A Is un mn muLrIx, LIen B muy be un n r muLrIx,
wIere m, n, r ure urbILrury posILIve InLegers. TIe resuIL Is LIe mr muLrIx C wILI
LIe enLrIes
C
ij
=
n

k=1
A
ik
B
kj
, i = 1, . . . , m, j = 1, . . . , r.
TIe muILIpIIcuLIon procedure beIow uuLomuLIcuIIy exLrucLs LIe dImensIon
purumeLers m, n, r Irom LIe urgumenLs, numeIy Irom LIe 0-LI operunds oI LIe
InpuL urruys (puge q-qq). I B Is u q r muLrIx wILI q = n, LIe muILIpIIcuLIon Is noL
deIIned muLIemuLIcuIIy. n LIIs cuse, LIe procedure LermInuLes wILI un error

I you use LIe duLu Lype 0om..Molrix(} InsLeud, you cun dIrecLIy use LIe sLundurd operuLors +, -,
*, ^, / Ior urILImeLIc wILI muLrIces (cI. puge q-;o II.).
1,-11
TZ NuPAD

Procedures
messuge. or LIuL purpose, we empIoy LIe IuncLIon error, wIIcI uborLs LIe
cuIIIng procedure und wrILes LIe sLrIng pussed us urgumenL on LIe screen. We
sLore LIe resuIL componenL by componenL In LIe IocuI vurIubIe C. We InILIuIIze LIIs
vurIubIe us un urruy oI dImensIon mr, so LIuL LIe resuIL oI our procedure Is oI
LIe desIred duLu Lype 00MARRAY. We mIgIL ImpIemenL LIe sum over k In LIe
compuLuLIon oI C
ij
us u Ioop oI LIe Iorm for k from 1 lo n do .. nsLeud, we
use LIe sysLem IuncLIon pius wIIcI reLurns LIe sum oI ILs urgumenLs. We
generuIIy recommend Lo use LIese sysLem IuncLIons, II possIbIe, sInce LIey work
quILe eIIIcIenLIy. TIe reLurn vuIue oI MolrixProducl Is LIe IInuI expressIon C:
MolrixProducl .= /* muilipiicolion C=AB of on m x n */
proc(A B} /* molrix A by on n x r Molrix B */
iocoi m n r i g k C /* Wilh orroys A B of */
begin /* domoin lype 00MARRAY */
m .= op(A _0 Z Z]}
n .= op(A _0 3 Z]}
if n <> op(B _0 Z Z]} lhen
error("incompolibie molrix dimensions"}
endif
r .= op(B _0 3 Z]}
C .= orroy(1..m 1..r} /* inilioiizolion */
for i from 1 lo m do
for g from 1 lo r do
C_i g] .= pius(A_i k]*B_k g] S k = 1..n}
endfor
endfor
C
endproc.
A generuI remurk ubouL MuPAD progrummIng sLyIe: you sIouId uIwuys perIorm
urgumenL cIeckIng In procedures meunL Ior InLerucLIve use. I you ImpIemenL u
procedure, you usuuIIy know wIIcI Lypes oI InpuLs ure vuIId (sucI us 00MARRAY In
LIe ubove exumpIe). I somebody pusses purumeLers oI LIe wrong Lype by mIsLuke,
LIIs usuuIIy Ieuds Lo sysLem IuncLIons cuIIs wILI InvuIId urgumenLs, und your
procedure uborLs wILI un error messuge orIgInuLIng Irom u sysLem IuncLIon. n LIe
ubove exumpIe, LIe IuncLIon op reLurns LIe vuIue FATL wIen uccessIng LIe 0-LI
operund oI A or B und one oI LIem Is noL oI Lype 00MARRAY. TIen LIIs vuIue Is
ussIgned Lo m, n or r, und LIe IoIIowIng for Ioop uborLs wILI un error messuge,
sInce FATL Is noL uIIowed us u vuIue Ior LIe endpoInL oI LIe Ioop.
1,-1
Iocol ond Globol Voriobles
n sucI u sILuuLIon, IL Is oILen dIIIIcuIL Lo IocuLe LIe source oI LIe error. However,
un even worse scenurIo mIgIL Iuppen: II LIe procedure does noL uborL, LIe resuIL
Is IIkeIy Lo be wrong! TIus, Lype cIeckIng IeIps Lo uvoId errors.
n LIe ubove exumpIe, we mIgIL udd u Lype cIeck oI LIe Iorm
if domlype(A} <> 00MARRAY or domlype(B} <> 00MARRAY
lhen error("orgumenls musl be of lype 00MARRAY"}
endif
Lo LIe procedure body. SLurLIng on puge 1;-zo, we dIscuss u sImpIer Lype cIeckIng
concepL.
1,-1
TZ NuPAD

Procedures
$ubpretedures
OILen Lusks occur IrequenLIy wILIIn u procedure und you wunL Lo ImpIemenL LIem
uguIn In LIe Iorm oI u procedure. TIIs sLrucLures und sImpIIIIes LIe progrum code.
n muny cuses, sucI u procedure Is used onIy Irom wILIIn u sIngIe procedure.
TIen IL Is reusonubIe Lo deIIne LIIs procedure IocuIIy us u subprocedure onIy In LIe
scope oI LIe cuIIIng procedure. n MuPAD

you cun use IocuI vurIubIes Lo


ImpIemenL subprocedures. I you wunL Lo muke
g .= proc(} begin ... endproc.
u IocuI procedure oI
f .= proc(} begin ... endproc.
deIIne f us IoIIows:
f .= proc(}
iocoi g
begin
g .= proc(} begin ... endproc /* subprocedure */
/* moin porl of f Which coiis g(..}. */
...
endproc.
Now, g Is u loccl procedure oI f und you cun use IL onIy Irom wILIIn f.
We gIve un exumpIe. You cun ImpIemenL muLrIx muILIpIIcuLIon by meuns oI
suILubIe coIumnrow muILIpIIcuLIons:
_
2 1
5 3
_

_
4 6
2 3
_
=
_
_
_
_
_
(2, 1)
_
4
2
_
(2, 1)
_
6
3
_
(5, 3)
_
4
2
_
(5, 3)
_
6
3
_
_
_
_
_
_
=
_
10 15
26 39
_
.
More generuIIy, II we purLILIon LIe InpuL muLrIces by rows a
i
und coIumns b
j
,
respecLIveIy, LIen
_
_
_
a
1
.
.
.
a
m
_
_
_ (b
1
, . . . , b
n
) =
_
_
_
a
1
b
1
. . . a
1
b
n
.
.
.
.
.
.
.
.
.
a
m
b
1
. . . a
m
b
n
_
_
_,
1,-1q
5ubprocedures
wILI LIe Inner producL
a
i
b
j
=

r
(a
i
)
r
(b
j
)
r
.
We now wrILe u procedure MolrixMuil LIuL expecLs InpuL urruys A und B oI LIe
Iorm orroy(1..m1..k} und orroy(1..k1..n}, und reLurns LIe mn muLrIx
producL A B. A cuII oI LIe subprocedure RoWTimesCoiumn wILI urgumenLs i, j
exLrucLs LIe i-LI row und LIe j-LI coIumn Irom LIe InpuL muLrIces A und B,
respecLIveIy, und compuLes LIe Inner producL oI LIe row und LIe coIumn. TIe
subprocedure uses LIe urruys A, B us weII us LIe IocuIIy decIured dImensIon
purumeLers m, n, und k us gIobuI vurIubIes:
MolrixMuil .= proc(A B}
iocoi m n k K /* iocoi voriobies */
RoWTimesCoiumn /* iocoi subprocedure */
begin
/* subprocedure */
RoWTimesCoiumn .= proc(i g}
iocoi roW coiumn r
begin
/* ilh roW of A. */
roW .= orroy(1..k _A_ir] S r=1..k]}
/* glh coiumn of B. */
coiumn .= orroy(1..k _B_rg] S r=1..k]}
/* roW limes coiumn */
pius(roW_r]*coiumn_r] S r=1..k}
endproc
/* moin porl of lhe procedure MolrixMuil. */
m .= op(A _0 Z Z]} /* number of roWs of A */
k .= op(A _0 3 Z]} /* number of coiumns of A */
K .= op(B _0 Z Z]} /* number of roWs of B */
n .= op(B _0 3 Z]} /* number of coiumns of B */
if k <> K lhen
error("# of coiumns of A <> # of roWs of B"}
endif
/* molrix A*B. */
orroy(1..m 1..n
__RoWTimesCoiumn(i g} S g=1..n] S i=1..m]}
endproc.
1,-1g
TZ NuPAD

Procedures
TIe IoIIowIng exumpIe reLurns LIe desIred resuIL:
A .= orroy(1..Z 1..Z __Z 1] _5 3]]}.
B .= orroy(1..Z 1..Z __4 6] _Z 3]]}.
MolrixMuil(A B}
_
10 15
26 39
_
1,-16
5cope ol Voriobles
$tepe el uriubles
TIe MuPAD

progrummIng Iunguuge ImpIemenLs lexiccl scopin. TIIs


essenLIuIIy meuns LIuL LIe scope oI u procedure`s IocuI vurIubIes und purumeLers
cun uIreudy be deLermIned wIen LIe procedure Is deIIned. We sLurL wILI u sImpIe
exumpIe Lo expIuIn LIIs concepL.
p .= proc(} begin x endproc.
x .= 3. p(} x .= 4. p(}
3
4
q .= proc(} iocoi x begin x .= 5 p(} endproc.
q(}
4
IrsL, u procedure p wILIouL urgumenLs Is deIIned. L uses u vurIubIe x, wIIcI Is
noL decIured us u IocuI vurIubIe oI p. TIus, LIe cuII p(} reLurns LIe vuIue oI LIe
gIobuI vurIubIe x, us sIown In LIe Lwo subsequenL cuIIs. n LIe procedure q,
Iowever, LIe vurIubIe x Is decIured IocuI, und LIe vuIue 5 Is ussIgned Lo IL. TIe
gIobuI vurIubIe x Is noL vIsIbIe Irom wILIIn LIe procedure q, onIy LIe IocuI vurIubIe
x cun be uccessed. NeverLIeIess, LIe cuII q(} reLurns LIe vuIue oI LIe lobcl
vurIubIe x, und not LIe currenL vuIue oI LIe IocuI vurIubIe x wILIIn p. We mIgIL, Ior
exumpIe, deIIne u subprocedure wILIIn q Lo ucIIeve LIe IuLLer beIuvIor:
x .= 4.
q .= proc(}
iocoi x p
begin
x .= 5
p .= proc(} begin x endproc
x .= 6
p(}
endproc.
q(} p(}
6, 4
1,-1,
TZ NuPAD

Procedures
TIe prevIousIy deIIned gIobuI procedure p Is noL uccessed Irom wILIIn q becuuse u
IocuI vurIubIe p Is decIured. TIe cuII oI LIe IocuI procedure p Irom wILIIn q now
Indeed reLurns LIe currenL vuIue oI LIe IocuI vurIubIe x, us sIown by LIe cuII q(}.
TIe IusL commund p(}, Iowever, execuLes LIe gIobuI procedure p deIIned beIore,
wIIcI sLIII reLurns LIe currenL vuIue 4 oI LIe gIobuI vurIubIe x.
Here Is unoLIer exumpIe:
p .= proc(x} begin Z * cos(x} + 1 endproc.
q .= proc(y}
iocoi cos
begin
cos .= proc(z} begin z + 1 endproc
p(y} * cos(y}
endproc.
p(PT} q(PT}
1, 1
TIe procedure p uses MuPAD`s gIobuIIy deIIned cosIne IuncLIon. WILIIn q, we
Iuve deIIned u IocuI subprocedure cos. CuIIIng q, LIe InLernuI cuII cos(y} reIers Lo
LIe IocuI IuncLIon cos. Even wIen cuIIed Irom wILIIn q, LIe procedure p sLIII uses
LIe MuPAD gIobuI cosIne IuncLIon.
WIen usIng LIe opLIon escope, u IocuI vurIubIe cun be uccessed even wIen IL Ius
escuped LIe scope oI LIe procedure LIuL IL wus IocuI Lo. n LIe IoIIowIng exumpIe,
LIe counLer reLurned by f reIers Lo LIe IocuI vurIubIe x oI f. TIe procedures
counler1, counlerZ eLc. ure noL IocuI Lo f unymore buL sLIII use LIe reIerence Lo x
Lo syncIronIze subsequenL cuIIs oI eucI counLer. NoLe LIuL boLI counLers reIer Lo
dijjerent IndependenL InsLunces oI x, so LIuL LIey counL IndependenLIy:
f .= proc(} iocoi x
oplion escope
begin
x .= 1
// The foiioWing procedure
// is lhe relurn voiue of f.
proc(} begin x .= x + 1 end
end.
counler1 .= f(}. counlerZ .= f(}.
1,-1S
5cope ol Voriobles
counler1(} counler1(} counler1(}
counlerZ(} counlerZ(}
counler1(} counlerZ(} counler1(}
2, 3, 4
2, 3
5, 4, 6
1,-1q
TZ NuPAD

Procedures
ype 0etluruIiea
MuPAD

provIdes eusy-Lo-use Lype cIeckIng Ior procedure urgumenLs. or


exumpIe, you cun resLrIcL LIe urgumenLs oI MolrixProducl, u procedure Irom LIe
SecLIon sLurLIng on puge 1;-q, Lo LIe domuIn Lype 00MARRAY us IoIIows:
MolrixProducl .= proc(A. 00MARRAY B. 00MARRAY}
iocoi m n r i g k C
begin ...
I you decIure LIe Lype oI LIe purumeLers oI u procedure In LIe Iorm used ubove,
orgumenl.lypeSpecifier, u cuII oI LIe procedure wILI purumeLers oI un
IncompuLIbIe Lype Ieuds Lo un error messuge. n LIe exumpIe ubove, we used LIe
domuIn Lype 00MARRAY us u Lype specIIIer.
We Iuve dIscussed MuPAD`s Lype concepL In CIupLer 1q. TIe Type IIbrury oIIers
Type..WonWegTnl Lo represenL LIe seL oI nonneguLIve InLegers. I we use IL In LIe
IoIIowIng vurIunL oI LIe IucLorIuI IuncLIon
foclorioi .= proc(n. Type..WonWegTnl} begin
if n = 0 lhen
relurn(1}
eise n*foclorioi(n - 1}
endif
endproc.
LIen onIy nonneguLIve InLegers ure permILLed Ior LIe urgumenL n:
foclorioi(4}
24
foclorioi(4.0}
Error. nrong lype of 1. orgumenl (lype Type..WonWeg`
Tnl expecled
gol orgumenl 4.0}
during evoiuolion of foclorioi
foclorioi(-4}
Error. nrong lype of orgumenl n (lype Type..WonWeg`
Tnl expecled
gol orgumenl -4}
during evoiuolion of foclorioi
1,-o
Procedures wi|h o Vorioble Number ol Argumen|s
Fretedures wiIh u uriuble umber el krgumeaIs
TIe sysLem IuncLIon mox compuLes LIe muxImum oI ILs urgumenLs. You muy cuII IL
wILI urbILrurIIy muny urgumenLs:
mox(1} mox(3/7 9/Z0} mox(-1 3 0 7 3/Z 7.5}
1,
9
20
, 7.5
You cun ImpIemenL LIIs beIuvIor In your own procedures us weII. TIe IuncLIon
orgs reLurns LIe urgumenLs pussed Lo LIe cuIIIng procedure:
orgs(0} : LIe number oI urgumenLs,
orgs(i} : LIe i-LI urgumenL, 1 i orgs(0},
orgs(i..g} : LIe sequence oI urgumenLs Irom i Lo j,
1 i j orgs(0},
orgs(} : LIe sequence orgs(1}orgs(Z}... oI uII
urgumenLs.
TIe IoIIowIng IuncLIon sImuIuLes LIe beIuvIor oI LIe sysLem IuncLIon mox:
moximum .= proc(} iocoi m i begin
m .= orgs(1}
for i from Z lo orgs(0} do
if m < orgs(i} lhen m .= orgs(i} endif
endfor.
m
endproc.
moximum(1} moximum(3/7 9/Z0} moximum(-1 3 0 7 3/Z 7.5}
1,
9
20
, 7.5
Here, we InILIuIIze m wILI LIe IIrsL urgumenL. TIen, we LesL Ior eucI oI LIe
remuInIng urgumenLs wIeLIer IL Is greuLer LIun m, und II so, repIuce m by LIe
correspondIng urgumenL. TIus, m conLuIns LIe muxImum uL LIe end oI LIe Ioop.
NoLe LIuL II you cuII moximum wILI onIy one urgumenL (so LIuL orgs(0}=1), LIen
LIe Ioop for i from Z lo 1 do ... Is noL execuLed uL uII.
1,-1
TZ NuPAD

Procedures
You muy use boLI IormuI purumeLers und uccesses vIu orgs In u procedure:
f .= proc(x y} begin
if orgs(0} = 3 lhen
x^Z + y^3 + orgs(3}^4
eise x^Z + y^3
endif
endproc.
f(o b} f(o b c}
a
2
+b
3
, a
2
+b
3
+c
4
TIe IoIIowIng exumpIe Is u LrIvIuI IuncLIon reLurnIng ILseII symboIIcuIIy Ior uny
number oI urgumenLs LIuL ure ucLuuIIy pussed:
f .= proc(} begin procnome(orgs(}} endproc.
f(1} f(1 Z} f(1 Z 3} f(o1 bZ c3 d4}
f(1) , f(1, 2) , f(1, 2, 3) , f(u1, bz, c, dq)
1,-
Cp|ions: |he kemember Toble
0pIieas: Ihe kemember uble
WIen decIurIng MuPAD

procedures, you cun specIIy options LIuL uIIecL LIe


execuLIon oI u procedure cuII. BesIdes LIe opLIon escope uIreudy menLIoned, LIe
opLIon remember muy be oI InLeresL Lo LIe user. n LIIs secLIon, we Luke u cIoser
Iook uL LIIs opLIon und demonsLruLe ILs eIIecL wILI un exumpIe. TIe sequence oI
IbonuccI numbers Is deIIned by LIe recursIon
F
n
= F
n1
+F
n2
, F
0
= 0, F
1
= 1.
L Is eusy Lo LrunsIuLe LIIs InLo u MuPAD procedure:
F .= proc(n. Type..WonWegTnl}
begin
if n < Z lhen n
eise F(n - 1} + F(n - Z} endif
endproc.
F(i} S i = 0..10
0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55
TIIs wuy oI compuLIng F
n
Is IIgIIy IneIIIcIenL Ior Iurger vuIues oI n. To see wIy,
IeL us Lruce LIe recursIve cuIIs oI F wIen compuLIng F
4
. You muy regurd LIIs us u
Lree sLrucLure: F(4} cuIIs F(3} und F(Z}, F(3} cuIIs F(Z} und F(1} eLc.:
F
4
F
3
F
2
F
2
F
1
F
1
F
0
F
1
F
0
One cun sIow LIuL LIe cuII F(n} Ieuds Lo ubouL 1.45.. (1.618..)
n
cuIIs oI F Ior Iurge
n. TIese cosLs grow drumuLIcuIIy IusL Ior IncreusIng vuIues oI n:
lime(F(10}} lime(F(15}} lime(F(Z0}} lime(F(Z5}}
80, 910, 10290, 113600
1,-
TZ NuPAD

Procedures
We recuII LIuL LIe IuncLIon lime reLurns LIe LIme In mIIIIseconds used Lo evuIuuLe
ILs urgumenL.
We see LIuL muny cuIIs (sucI us, Ior exumpIe, F(1}) ure execuLed severuI LImes.
or evuIuuLIng F(4}, IL Is suIIIcIenL Lo execuLe onIy LIe boxed IuncLIon cuIIs
F(0}...F(4} In LIe ubove IIgure und Lo sLore LIese vuIues. AII oLIer
compuLuLIons oI F(0}F(1}F(Z} ure redundunL sInce LIeIr resuILs ure uIreudy
known. TIIs Is precIseIy wIuL MuPAD does wIen you decIure F wILI LIe oplion
remember:
F .= proc(n. Type..WonWegTnl}
oplion remember
begin
if n < Z lhen n
eise F(n - 1} + F(n - Z} endif
endproc.
TIe sysLem InLernuIIy creuLes u remember LubIe Ior LIe procedure F, wIIcI
InILIuIIy Is empLy. AL eucI cuII Lo F, MuPAD cIecks wIeLIer LIere Is un enLry Ior
LIe currenL urgumenL sequence In LIIs LubIe. I LIIs Is LIe cuse, LIe procedure Is
noL execuLed uL uII, und LIe resuIL Is Luken Irom LIe LubIe. I LIe currenL urgumenLs
do noL uppeur In LIe LubIe, LIe sysLem execuLes LIe procedure body us usuuI und
reLurns ILs resuIL. TIen IL uppends LIe urgumenL sequence und LIe reLurn vuIue Lo
LIe remember LubIe. TIIs ensures LIuL u procedure Is noL unnecessurIIy execuLed
LwIce wILI LIe sume urgumenLs.
n LIe IbonuccI exumpIe, LIe cuII F(n} now Ieuds Lo onIy n + 1 cuIIs Lo compuLe
F(0}...F(n}. n uddILIon, LIe sysLem seurcIes LIe remember LubIe n 2 LImes.
However, LIIs Iuppens very quIckIy. n LIIs exumpIe, LIe beneIIL In speed Irom
usIng oplion remember Is quILe drumuLIc:
lime(F(10}} lime(F(15}} lime(F(Z0}} lime(F(Z5}}
lime(F(500}}
0, 10, 0, 10, 390
TIe reuI runnIng LImes ure so smuII LIuL LIe sysLem cunnoL meusure LIem exucLIy.
TIIs expIuIns LIe (rounded) LImes oI 0 mIIIIseconds Ior F(10} und F(Z0}.
UsIng oplion remember In u procedure Is promIsIng wIenever u
procedure Is cuIIed IrequenLIy wILI LIe sume urgumenLs.
1,-q
Cp|ions: |he kemember Toble
OI course, you cun ImpIemenL LIIs meLIod Ior compuLIng LIe IbonuccI numbers
dIrecLIy by compuLIng F
n
ILeruLIveIy InsLeud oI recursIveIy und sLorIng uIreudy
compuLed vuIues In u LubIe:
q
F .= proc(n. Type..WonWegTnl}
iocoi i F
begin
F_0] .= 0. F_1] .= 1.
for i from Z lo n do
F_i] .= F_i - 1] + F_i - Z]
endfor
endproc.
lime(F(10}} lime(F(15}} lime(F(Z0}} lime(F(Z5}}
lime(F(500}}
10, 0, 10, 0, 400
TIe IuncLIon numiib..fibonocci Irom LIe number LIeory IIbrury Is yeL IusLer Ior
Iurge urgumenLs, sInce IL uses more eIuboruLe uIgorILIms und dIrecL IormuIus.
Wurning: TIe remember mecIunIsm recognIzes onIy prevIousIy processed
InpuLs, buL does noL consIder LIe vuIues oI possIbIy used gIobuI vurIubIes. WIen
LIe vuIues oI LIese gIobuI vurIubIes cIunge, LIen LIe remembered reLurn vuIues
ure usuuIIy wrong. n purLIcuIur, LIIs Is LIe cuse Ior gIobuI envIronmenL vurIubIes
sucI us 0TCTTS:
fioolexp .= proc(x} oplion remember
begin fiool(exp(x}} endproc.
0TCTTS .= Z0. fioolexp(1}
2.7182818284590452354
0TCTTS .= 40. fioolexp(1} fiool(exp(1}}
2.718281828459045235360287471344923927842
2.718281828459045235360287471352662497757
Here, LIe sysLem ouLpuLs LIe remembered vuIue oI fioolexp(1} wILI IIgIer
precIsIon uILer swILcIIng Irom 20 Lo 40 0TCTTS. NeverLIeIess, LIIs Is sLIII LIe vuIue
compuLed wILI 0TCTTS=Z0; LIe ouLpuL onIy sIows uII dIgILs LIuL were used
q
TIIs procedure Is noL properIy ImpIemenLed: wIuL Iuppens wIen you cuII F(0}?
1,-g
TZ NuPAD

Procedures
interncll

In LIIs compuLuLIon. TIe IusL oI LIe LIree numbers Is LIe Lrue vuIue oI
exp(1} compuLed wILI 40 dIgILs. L dIIIers Irom LIe wrongIy remembered vuIue uL
LIe 30-LI decImuI dIgIL.
You cun expIIcILIy udd new enLrIes Lo LIe remember LubIe oI u procedure. n LIe
IoIIowIng exumpIe, f Is LIe IuncLIon x sIn(x)/x, wIIcI Ius u removubIe
sInguIurILy uL x = 0. TIe IImIL Is f(0) := IIm
x0
sIn(x)/x = 1:
f .= proc(x} begin sin(x}/x endproc. f(0}
Error. 0ivision by zero
during evoiuolion of f
You cun eusIIy udd LIe vuIue Ior x = 0:
f(0} .= 1. f(0}
1
TIe ussIgnmenL f(0}.=1 creuLes u remember LubIe Ior f, so LIuL u IuLer cuII oI
f(0} does noL Lry Lo evuIuuLe LIe vuIue oI sIn(x)/x Ior x = 0. Now you cun use f
wILIouL runnIng InLo dunger uL x = 0.
Wurning: TIe cuII:
deiele f. f(x} .= x^Z.
does not generuLe LIe IuncLIon f : x x
2
, buL ruLIer creuLes u remember LubIe Ior
LIe IdenLIIIer f wILI LIe enLry x^Z onl jor the smbolic identijier x. Any oLIer cuII
Lo f reLurns u symboIIc IuncLIon cuII:
f(x} f(y} f(1}
x
2
, f(y) , f(1)

nLernuIIy, MuPAD uses u cerLuIn number oI uddILIonuI guurd dIgILs exceedIng LIe number oI
dIgILs requesLed vIu 0TCTTS. However, Ior LIe ouLpuL, LIe sysLem LruncuLes LIe InLernuIIy compuLed vuIue
Lo LIe requesLed number oI dIgILs.
1,-6
Inpu| Porome|ers
lapuI FurumeIers
TIe decIured IormuI urgumenLs oI u procedure cun be used IIke uddILIonuI IocuI
vurIubIes:
f .= proc(o b} begin o .= 1 o + b endproc.
o .= Z. f(o 1}. o
2
ModIIyIng o wILIIn LIIs procedure does noL uIIecL LIe IdenLIIIer o LIuL Is used
ouLsIde LIe procedure. You sIouId be cuuLIous wIen you uccess LIe cuIIIng
urgumenLs vIu orgs (puge 1;-z1) In u procedure uILer cIungIng some InpuL
purumeLer. AssIgnmenL Lo u IormuI purumeLer cIunges LIe reLurn vuIue oI orgs:
f .= proc(o} begin o .= 1 o orgs(1} endproc. f(Z}
1, 1
n prIncIpIe, urbILrury MuPAD

objecLs muy be InpuL purumeLers oI u procedure.


TIus you cun use seLs, IIsLs, expressIons, or even procedures und IuncLIons:
p .= proc(f} begin
_f(1} f(Z} f(3}]
endproc.
p(g}
[g(1) , g(2) , g(3)]
p(proc(x} begin x^Z endproc}
[1, 4, 9]
p(x -> x^3}
[1, 8, 27]
1,-,
TZ NuPAD

Procedures
n generuI, user-deIIned procedures evuIuuLe LIeIr urgumenLs (cuII by vuIue):
wIen you cuII f(x}, LIe procedure f knows onIy LIe vuIue oI LIe IdenLIIIer x. I you
decIure u procedure wILI LIe oplion hoid, LIen LIe cuII by nume scIeme Is used
InsLeud: LIe expressIon or LIe nume oI LIe IdenLIIIer pussed us LIe ucLuuI
urgumenL Is seen by LIe procedure. n LIIs cuse, you cun use conlexl Lo obLuIn LIe
vuIue oI LIe expressIon:
f .= proc(x} oplion hoid
begin x = conlexl(x} endproc.
x .= Z.
f(x} f(sin(x}} f(sin(PT}}
x = 2, sIn(x) = sIn(2) , sIn() = 0
1,-S
Evoluo|ion Wi|hin Procedures
vuluuIiea NiIhia Fretedures
n CIupLer , we Iuve dIscussed MuPAD

`s evuIuuLIon sLruLegy: compIeLe


evuIuuLIon uL InLerucLIve IeveI. TIus uII IdenLIIIers ure repIuced by LIeIr vuIues
recursitel unLII onIy symboIIc IdenLIIIers wILIouL u vuIue remuIn (or LIe
evuIuuLIon depLI gIven by LIe envIronmenL vurIubIe LEvEL Is reucIed):
deiele o b c. x .= o + b. o .= b + 1. b .= c.
x
2 c + 1
n conLrusL, wILIIn procedures, LIe sysLem perIorms evuIuuLIon noL compIeLeIy buL
onIy wILI evuIuuLIon depLI 1. TIIs Is sImIIur Lo InLernuIIy repIucIng eucI IdenLIIIer
by ievei(idenlifier 1}: every IdenLIIIer Is repIuced by ILs vuIue, buL not
recursitel. We recuII Irom puge -1 LIe dIsLIncLIon beLween LIe tclue oI un
IdenLIIIer (LIe evuIuuLIon uL LIe LIme oI ussIgnmenL) und ILs etcluction (LIe
currenL vuIue, wIere symboIIc IdenLIIIers LIuL Iuve been ussIgned u vuIue In LIe
meunLIme ure repIuced by LIeIr vuIues us weII). n InLerucLIve mode, cuIIIng un
objecL yIeIds ILs compIeLe evuIuuLIon, wIIIe In procedures onIy LIe objecL`s vuIue Is
reLurned. TIIs expIuIns LIe dIIIerence beLween LIe InLerucLIve resuIL ubove und
LIe IoIIowIng resuIL:
f .= proc(} begin
deiele o b c.
x .= o + b. o .= b + 1. b .= c.
x
endproc.
f(}
a +b
TIe reuson wIy Lwo dIIIerenL beIuvIors ure ImpIemenLed Is LIuL LIe sLruLegy oI
IncompIeLe evuIuuLIon mukes LIe evuIuuLIon oI procedures IusLer und Increuses
LIe eIIIcIency oI MuPAD procedures consIderubIy. or u begInner In
progrummIng MuPAD procedures, LIIs evuIuuLIon concepL Ius ILs pILIuIIs.
However, uILer some prucLIce you ucquIre un upproprIuLe progrummIng sLyIe so
LIuL you cun work wILI LIe resLrIcLed evuIuuLIon depLI wILIouL probIems.
1,-q
TZ NuPAD

Procedures
Wurning: I you do noL work InLerucLIveIy wILI MuPAD, buL use un edILor Lo
wrILe your MuPAD communds InLo u LexL IIIe wIIcI Is reud InLo u MuPAD sessIon
vIu reod (puge 1z-), LIese communds ure execuLed wILIIn u procedure (numeIy,
reod). ConsequenLIy, LIe evuIuuLIon depLI Is 1.
You cun use LIe sysLem IuncLIon ievei (puge -q) Lo conLroI LIe evuIuuLIon depLI
und Lo enIorce compIeLe evuIuuLIon II necessury:
f .= proc(} begin
deiele o b c.
x .= o + b. o .= b + 1. b .= c.
ievei(x}
endproc.
f(}
2 c + 1
Wurning: ievei does noL evuIuuLe IocuI vurIubIes.
Moreover, you cunnoL use IocuI vurIubIes us symboIIc IdenLIIIers; you musL
InILIuIIze LIem beIore use. TIe IoIIowIng procedure, In wIIcI u symboIIc IdenLIIIer
x Is pussed Lo LIe InLegruLIon IuncLIon, Is InvuIId:
f .= proc(n} iocoi x begin inl(exp(x^n} x} endproc.
You cun puss LIe nume oI LIe InLegruLIon vurIubIe us uddILIonuI urgumenL Lo LIe
procedure. TIus, LIe IoIIowIng vurIunLs ure vuIId:
f .= proc(n x} begin inl(exp(x^n} x} endproc.
f .= proc(n x} iocoi y begin
y .= x inl(exp(y^n} y} endproc.
I you need symboIIc IdenLIIIers Ior InLermedIuLe resuILs, you cun generuLe un
IdenLIIIer wILIouL u vuIue vIu genidenl(} (puge q-8) und ussIgn IL Lo u IocuI
vurIubIe.
1,-o
Func|ion Environmen|s
luatIiea avireameaIs
MuPAD

provIdes u vurIeLy oI LooIs Ior IundIIng buIIL-In muLIemuLIcuI sLundurd


IuncLIons sucI us sin, cos, exp. TIese LooIs ImpIemenL LIe muLIemuLIcuI
properLIes oI LIese IuncLIons. TypIcuI exumpIes ure LIe fiool conversIon rouLIne,
LIe dIIIerenLIuLIon IuncLIon diff, or LIe IuncLIon expond, wIIcI you use Lo
munIpuIuLe expressIons:
fiool(sin(1}} diff(sin(x} x x x}
expond(sin(x + 1}}
0.8414709848, cos(x) , cos(1) sIn(x) + sIn(1) cos(x)
n LIIs sense, LIe muLIemuLIcuI knowIedge ubouL LIe sLundurd IuncLIons Is
dIsLrIbuLed over severuI sysLem IuncLIons: LIe IuncLIon fiool Ius Lo know Iow Lo
compuLe numerIcuI upproxImuLIons oI LIe sIne IuncLIon, diff musL know ILs
derIvuLIve, und expond Ius Lo know LIe uddILIon LIeorems oI LIe LrIgonomeLrIc
IuncLIons.
You cun InvenL urbILrury new IuncLIons us symboIIc numes or ImpIemenL LIem In
procedures. How cun you puss LIe knowIedge ubouL LIe muLIemuLIcuI meunIng
und LIe ruIes oI munIpuIuLIon Ior LIe new IuncLIons Lo LIe oLIer sysLem IuncLIons?
or exumpIe, Iow cun you LeII LIe dIIIerenLIuLIon rouLIne diff wIuL LIe derIvuLIve
oI your newIy creuLed IuncLIon Is? I LIe IuncLIon Is composed oI sLundurd
IuncLIons known Lo MuPAD, sucI us, Ior exumpIe, f : x x sIn(x), LIen LIIs Is no
probIem. TIe cuII
f .= x -> (x*sin(x}}. diff(f(x} x}
sIn(x) +x cos(x)
ImmedIuLeIy yIeIds LIe desIred unswer. However, oILen LIere ure sILuuLIons wIere
LIe newIy ImpIemenLed IuncLIon cunnoL be composed Irom sLundurd objecLs.
TIus, our gouI Is Lo Iund LIe ruIes oI munIpuIuLIon (IIouLIng-poInL upproxImuLIon,
dIIIerenLIuLIon eLc.) Ior smbolic IuncLIon cuIIs Lo LIe MuPAD IuncLIons fiool,
diff eLc. TIIs Is LIe ucLuuI cIuIIenge wIen you ImpIemenL u new muLIemuLIcuI
IuncLIon In MuPAD: Lo dIsLrIbuLe LIe knowIedge ubouL LIe muLIemuLIcuI
meunIng oI LIe symboI Lo MuPAD`s sLundurd LooIs. ndeed, LIIs Is u necessury
Lusk: Ior exumpIe, II you wunL Lo dIIIerenLIuLe u more compIex expressIon
conLuInIng boLI LIe new IuncLIon und some sLundurd IuncLIons, LIen LIIs Is onIy
1,-1
TZ NuPAD

Procedures
possIbIe vIu LIe sysLem`s dIIIerenLIuLIon rouLIne. TIus, LIe IuLLer Ius Lo Ieurn Iow
Lo IundIe LIe new symboIs.
or LIuL purpose, MuPAD provIdes LIe domuIn Lype 00MFuWCEWv (sIorL Ior:
IuncLIon envIronmenL). ndeed, uII buIIL-In muLIemuLIcuI sLundurd IuncLIons ure
oI LIIs Lype In order Lo enubIe fiool, diff, expond eLc. Lo IundIe LIem:
domlype(sin}
DOM_UNC_ENV
You cun cuII u IuncLIon envIronmenL IIke uny normuI IuncLIon or procedure:
sin(1.7}
0.9916648105
A IuncLIon envIronmenL consIsLs oI LIree operunds. TIe IIrsL operund Is u
procedure LIuL compuLes LIe reLurn vuIue oI u IuncLIon cuII. TIe second operund
Is u procedure Ior prInLIng u symboIIc IuncLIon cuII on LIe screen. TIe LIIrd
operund Is u LubIe conLuInIng InIormuLIon Iow LIe sysLem IuncLIons fiool, diff,
expond, eLc. sIouId IundIe symboIIc IuncLIon cuIIs.
You cun Iook uL LIe procedure Ior evuIuuLIng u IuncLIon cuII wILI LIe IuncLIon
expose, jusL IIke Ior normuI IuncLIons:
expose(sin}
proc(x}
nome sin
iocoi f y
oplion no0ebug
begin
if orgs(0} = 0 lhen
error("no orgumenls given"}
eise
...
endproc
To keep LIe exumpIe munugeubIe, we wIII cIoose Lwo cIoseIy reIuLed IuncLIons und
ucL us II LIey were noL ImpIemenLed In MuPAD yeL. Our exumpIe IuncLIons ure LIe
compIeLe eIIIpLIc InLegruI IuncLIons oI LIe IIrsL und second kInd, K(z) und E(z).
SInce MuPAD uIreudy Ius u predeIIned IdenLIIIer E, we wIII ImpIemenL LIese
IuncLIons us eiiipE und, Ior consIsLency, eiiipK. (TIe more obvIous numes
1,-
Func|ion Environmen|s
eiiiplicE und eiiiplicK ure uIreudy used by LIe MuPAD versIons oI LIe sume
IuncLIons.) TIese IuncLIons uppeur In sucI dIIIerenL conLexLs us cuIcuIuLIng LIe
perImeLer oI un eIIIpsIs, LIe gruvILuLIonuI or eIecLrosLuLIc poLenLIuI oI u unIIorm
rIng or LIe probubIIILy LIuL u rundom wuIk In LIree dImensIons ever goes LIrougI
LIe orIgIn. or LIIs presenLuLIon, IeL us concenLruLe on LIe IoIIowIng properLIes oI
LIe IuncLIons E und K:
E

(z) =
E(z) K(z)
2 z
,
K

(z) =
E(z) (1 z)K(z)
2 (1 z)z
,
E(0) = K(0) =

2
, E(1) = 1,
K
_
1
2
_
=
8
3/2

1
4
_
2
, K(1) =

_
1
4
_
2
4

2
.
TIuL Is, we ure goIng Lo ImpIemenL LIe derIvuLIves oI E und K wILI LIe ubove
reIuLIons und muke LIe IuncLIons evuIuuLe uL specIuI poInLs. AddILIonuIIy, we wIII
ImpIemenL LIe IuncLIons In sucI u wuy LIuL LIey ure wrILLen us E und K In LIe
ouLpuL.
TIe busIc IuncLIons ure eusy Lo wrILe:
eiiipE .=
proc(x} begin
if x = 0 lhen PT/Z
eiif x = 1 lhen 1
eise procnome(x} endif
endproc.
eiiipK .=
proc(x} begin
if x = 0 lhen PT/Z
eiif x = 1/Z lhen *PT^(3/Z}/gommo(-1/4}^Z
eiif x = -1 lhen gommo(1/4}^Z/4/sqrl(Z*PT}
eise procnome(x} endif
endproc.
1,-
TZ NuPAD

Procedures
SInce LIe vuIues oI LIe IuncLIons ure known onIy uL specIIIc pIuces, we use
procnome (puge 1;-;) Lo reLurn LIe symboIIc expressIons eiiipE(x} und
eiiipK(x}, respecLIveIy, Ior uII urgumenLs wIere LIe IuncLIon vuIues ure noL
known. TIIs yIeIds:
eiiipE(0} eiiipE(1/Z}
eiiipK(1Z/17} eiiipK(x^Z+1}

2
, eIIIpE
_
1
2
_
, eIIIpK
_
12
17
_
, eIIIpK
_
x
2
+ 1
_
You generuLe u new IuncLIon envIronmenL by meuns oI funcenv:
oulpulE .= f -> hoid(E}(op(f}}.
eiiipE .= funcenv(eiiipE oulpulE}.
oulpulK .= f -> hoid(K}(op(f}}.
eiiipK .= funcenv(eiiipK oulpulK}.
TIese communds converL LIe procedures eiiipE und eiiipK Lo IuncLIon
envIronmenLs. TIe IIrsL urgumenLs ure LIe procedures Ior evuIuuLIon. TIe
(opLIonuI) second urgumenL oI funcenv Is LIe procedure Ior screen ouLpuL. We
wunL u symboIIc expressIon eiiipE(x} dIspIuyed us E(x} und IIkewIse eiiipK(x}
sIuII be dIspIuyed us K(x}. TIIs Is ucIIeved by LIe second urgumenL oI funcenv,
wIIcI you sIouId InLerpreL us u conversIon rouLIne. On InpuL eiiipE(x}, IL
reLurns LIe MuPAD objecL Lo prInL on LIe screen InsLeud oI eiiipE(x}. TIe
urgumenL f, wIIcI represenLs eiiipE(x}, Is converLed Lo LIe unevuIuuLed
IuncLIon cuII E(x} (noLe LIuL x=op(f} Ior f=eiiipE(x} und LIuL you need
hoid(E} Lo prevenL evuIuuLIon oI LIe IdenLIIIer E). TIe sysLem ouLpuLs LIIs
expressIon InsLeud oI eiiipE(x} on LIe screen:
6
eiiipE(0} eiiipE(1/Z}
eiiipK(1Z/17} eiiipK(x^Z+1}

2
, E
_
1
2
_
, K
_
12
17
_
, K
_
x
2
+ 1
_
TIe (opLIonuI) LIIrd urgumenL Lo funcenv Is u LubIe oI junction cttributes. L LeIIs
LIe sysLem IuncLIons fiool, diff, expond eLc. Iow Lo IundIe symboIIc cuIIs oI LIe
6
NoLe LIuL you sIouId uvoId reLurnIng sLrIngs Irom sucI procedures. UsIng sLrIngs breuks boLI
preLLy-prInLIng und LypeseLLIng oI LIe ouLpuL.
1,-q
Func|ion Environmen|s
Iorm eiiipK(x} und eiiipE(x}. n LIe exumpIe ubove, we dId noL provIde uny
sucI IuncLIon uLLrIbuLes. Hence, LIe sysLem IuncLIons do noL yeL know Iow Lo
proceed und, by deIuuIL, reLurn LIe expressIon or LIemseIves symboIIcuIIy:
fiool(eiiipE(1/3}} expond(eiiipE(x + y}}
diff(eiiipE(x} x} diff(eiiipK(x} x}
E
_
1
3
_
, E(x +y) ,

x
E(x) ,

x
K(x)
By ussIgnIng Lo LIe "diff" sIoL oI our IuncLIon envIronmenLs, we seL LIe uLLrIbuLes
Ior LIe dIIIerenLIuLIon rouLIne diff:
eiiipE..diff .=
proc(fx}
iocoi z
begin
z .= op(f}
(eiiipE(z} - eiiipK(z}}/(Z*z} * diff(z x}
endproc.
eiiipK..diff .=
proc(fx}
iocoi z
begin
z .= op(f}
(eiiipE(z} - (1-z}*eiiipK(z}}/
(Z*(1-z}*z} * diff(z x}
endproc.
TIese communds LeII diff LIuL diff(fx} wILI u symboIIc IuncLIon cuII
f=eiiipE(z}, wIere z depends on x, sIouId uppIy LIe procedure ussIgned Lo
eiiipE..diff. TIe weII-known cIuIn ruIe yIeIds
d
dx
E(z) = E

(z)
dz
dx
.
TIe specIIIed procedure ImpIemenLs LIIs ruIe, wIere LIe Inner IuncLIon In LIe
expressIon f=eiiipE(z} Is gIven by z=op(f}.
1,-g
TZ NuPAD

Procedures
Nou MuPAD lnous the deritctites oj the junctions represented b the
identijiers eiiipE cnd eiiipK. We Iuve uIreudy ImpIemenLed LIe screen ouLpuLs:
diff(eiiipE(z} z} diff(eiiipE(y(x}} x}
diff(eiiipE(x*sin(x}} x}
E(z) K(z)
2 z
,
(E(y(x)) K(y(x)))

x
y(x)
2 y(x)
(E(x sIn(x)) K(x sIn(x))) (sIn(x) +x cos(x))
2 x sIn(x)
As Iur us diff Is concerned, LIe ImpIemenLuLIon oI our Lwo eIIIpLIc InLegruIs Is now
compIeLe:
diff(eiiipE(x} x x}
E(x)K(x)
2 x
+
E(x)+K(x) (x1)
2 x (x1)
2 x

E(x) K(x)
2 x
2
normoi(diff(eiiipK(Z*x + 3} x x x}}
- (73 E(Z x + 3} + 6 K(Z x + 3} + 115 x E(Z x + 3} +
Z
ZZ x K(Z x + 3} + 46 x E(Z x + 3} +
Z 3
Z0Z x K(Z x + 3} + 60 x K(Z x + 3}} /
6 5 4 3 Z
(3Z x + Z40 x + 744 x + 1ZZ0 x + 1116 x +
540 x + 10}
As un uppIIcuLIon, we now wunL MuPAD Lo compuLe LIe IIrsL Lerms oI LIe TuyIor
expunsIon oI LIe compIeLe eIIIpLIc InLegruI oI LIe IIrsL kInd uround x = 0. We cun
use LIe IuncLIon loyior sInce IL cuIIs diff InLernuIIy:
loyior(eiiipK(x} x = 0 6}

2
+
x
8
+
9 x
2
128
+
25 x
3
512
+
1225 x
4
32768
+
3969 x
5
131072
+O
_
x
6
_
1,-6
Func|ion Environmen|s
BuL LIere Is more: WILI IuncLIons sucI us LIe eIIIpLIc InLegruIs, wIIcI uppeur In
LIeIr own derIvuLIves, LIe InLegruLIon rouLIne Ius u good cIunce oI IIndIng
symboIIc InLegruIs once LIe diff uLLrIbuLes Iuve been ImpIemenLed:
inl(eiiipE(x} x}
2 E(x)
3

2 K(x)
3
+x
_
2 E(x)
3
+
2 K(x)
3
_
Ixercise 1,.1: ExLend LIe deIInILIons oI eiiipE und eiiipK by u "fiool" sIoL.
Use hypergeom..fiool und LIe IoIIowIng equIvuIences:
E(z) =

2
hypergeom
__

1
2
,
1
2
_
, [1], z
_
K(z) =

2
hypergeom
__
1
2
,
1
2
_
, [1], z
_
AIso, exLend LIe deIInILIons oI LIe IuncLIons sucI LIuL your new IIouL evuIuuLIon Is
uuLomuLIcuIIy used wIen u IIouLIng poInL vuIue Is gIven us InpuL.
Ixercise 1,.: mpIemenL un ubsoIuLe vuIue IuncLIon Abs us u IuncLIon
envIronmenL. TIe cuII Abs(x} sIouId reLurn LIe ubsoIuLe vuIue Ior reuI numbers x
oI domuIn Lype 00MTWT, 00MRAT, or 00MFL0AT. or uII oLIer urgumenLs, LIe
symboIIc ouLpuL 1x1 sIouId uppeur on LIe screen. TIe ubsoIuLe vuIue Is
dIIIerenLIubIe on R\{0}. Ls derIvuLIve Is
d|y|
dx
=
|y|
y
dy
dx
.
SeL LIe "diff" uLLrIbuLe uccordIngIy und compuLe LIe derIvuLIve oI Abs(x^3}.
Compure your resuIL Lo LIe correspondIng derIvuLIve oI LIe sysLem IuncLIon obs.
1,-,
TZ NuPAD

Procedures
k Fregrummiag xumple: 0illereaIiuIiea
n LIIs secLIon, we dIscuss un exumpIe demonsLruLIng LIe LypIcuI mode oI
operuLIon oI u symboIIc MuPAD

procedure. We ImpIemenL u symboIIc


dIIIerenLIuLIon rouLIne LIuL compuLes LIe derIvuLIves oI uIgebruIc expressIons
composed oI uddILIons, muILIpIIcuLIons, exponenLIuLIons, some muLIemuLIcuI
IuncLIons (exp, In, sIn, cos, .), consLunLs, und symboIIc IdenLIIIers.
TIIs exumpIe Is onIy Ior IIIusLruLIon purposes, sInce MuPAD uIreudy provIdes sucI
u IuncLIon: LIe diff rouLIne. TIIs IuncLIon Is ImpIemenLed In LIe MuPAD kerneI
und LIereIore very IusL. A user-deIIned IuncLIon LIuL Is wrILLen In LIe MuPAD
progrummIng Iunguuge cun IurdIy ucIIeve LIe eIIIcIency oI diff.
TIe IoIIowIng uIgebruIc dIIIerenLIuLIon ruIes ure vuIId Ior LIe cIuss oI expressIons
LIuL we consIder:
(1)
df
dx
= 0, II f does noL depend on x,
(z)
dx
dx
= 1,
()
d(f +g)
dx
=
df
dx
+
dg
dx
(IIneurILy),
(q)
da b
dx
=
da
dx
b +a
db
dx
(producL ruIe),
()
da
b
dx
=
d
dx
e
b In(a)
= e
b In(a)
d
dx
(b In(a))
= a
b
In(a)
db
dx
+a
b1
b
da
dx
,
(6)
d
dx
F(y(x)) = F

(y)
dy
dx
(cIuIn ruIe).
Moreover, Ior some IuncLIons F, LIe derIvuLIve Is known, und we wunL Lo Luke LIIs
InLo uccounL In our ImpIemenLuLIon. or un unknown IuncLIon F, we reLurn LIe
symboIIc IuncLIon cuII oI LIe dIIIerenLIuLIon rouLIne.
1,-S
A Progromming Eomple: Dilleren|io|ion
TIe procedure 0iff In TubIe 1;.1 ImpIemenLs LIe ubove properLIes In LIe sLuLed
order. Ls cuIIIng synLux Is 0iff(expressionidenlifier}.
0iff .= proc(f x . 00MT0EWT} // (0}
iocoi o b F y begin
if nol hos(f x} lhen relurn(0} endif // (1}
if f = x lhen relurn(1} endif // (Z}
if lype(f} = "pius" lhen
relurn(mop(f 0iff x}} endif // (3}
if lype(f} = "muil" lhen
o .= op(f 1} b .= subsop(f 1 = 1}
relurn(0iff(o x}*b + o*0iff(b x}} // (4}
endif
if lype(f} = "poWer" lhen
o .= op(f 1} b .= op(f Z}
relurn(f*in(o}*0iff(b x}
+ o^(b - 1}*b*0iff(o x}} // (5}
endif
if op(f 0} <> FATL lhen
F .= op(f 0} y .= op(f 1} // (6}
if F = hoid(exp} lhen
relurn( exp(y}*0iff(y x}} endif // (6}
if F = hoid(in} lhen
relurn( 1/y *0iff(y x}} endif // (6}
if F = hoid(sin} lhen
relurn( cos(y}*0iff(y x}} endif // (6}
if F = hoid(cos} lhen
relurn(-sin(y}*0iff(y x}} endif // (6}
/* specify furlher knoWn funclions here */
endif
procnome(orgs(}} // (7}
endproc.
TubIe 1;.1: A symboIIc dIIIerenLIuLIon rouLIne
n (o), we ImpIemenLed un uuLomuLIc Lype cIeck oI LIe second urgumenL, wIIcI
musL be u symboIIc IdenLIIIer oI domuIn Lype 00MT0EWT.
n (1), LIe MuPAD IuncLIon hos cIecks wIeLIer LIe expressIon f Lo be
dIIIerenLIuLed depends on x.
IneurILy oI dIIIerenLIuLIon Is ImpIemenLed In () by meuns oI LIe MuPAD
1,-q
TZ NuPAD

Procedures
IuncLIon mop:
mop(f1(x} + fZ(x} + f3(x} 0iff x}
DIII(I1(x) , x) +DIII(Iz(x) , x) +DIII(I(x) , x)
n (q), we IundIe u producL expressIon f = f
1
f
2
. . . : LIe commund o.=op(f1}
deLermInes LIe IIrsL IucLor a = f
1
, LIen subsop(f1=1} repIuces LIIs IucLor by 1,
sucI LIuL b ussumes LIe vuIue f
2
f
3
. . . . TIen, we cuII 0iff(ox} und 0iff(bx}.
I b = f
2
f
3
. . . Is ILseII u producL, LIIs Ieuds Lo unoLIer execuLIon oI sLep (q) uL
LIe nexL recursIon IeveI. n LIIs wuy, (q) IundIes producLs oI urbILrury IengLI.
SLep () dIIIerenLIuLes powers. or f = a
b
, LIe cuII op(f1} reLurns LIe buse a und
op(fZ} LIe exponenL b. n purLIcuIur, LIIs covers uII monomIuI expressIons oI LIe
Iorm f = x
n
Ior consLunL n. TIe recursIve cuIIs Lo 0iff Ior a = x und b = n LIen
yIeId 0iff(ox}=1 und 0iff(bx}=0, respecLIveIy, und LIe expressIon reLurned
In () sImpIIIIes Lo LIe correcL resuIL nx
n1
.
I LIe expressIon f Is u symboIIc IuncLIon cuII oI LIe Iorm f = F(y), we exLrucL LIe
ouLer IuncLIon F In (6) vIu F.=op(f0} (oLIerwIse, F geLs LIe vuIue FATL). NexL,
we IundIe LIe cuse wIere F Is u IuncLIon wILI one urgumenL y und exLrucL LIe
Inner IuncLIon by y.=op(f1}. I F Is LIe nume oI u IuncLIon wILI known
derIvuLIve (sucI us F = exp, In, sIn, cos), LIen we uppIy LIe cIuIn ruIe. L Is eusy Lo
exLend LIIs IIsL oI IuncLIons F wILI known derIvuLIves. n purLIcuIur, you cun udd u
IormuIu Ior dIIIerenLIuLIng symboIIc expressIons oI LIe Iorm inl(}. ExLensIons
Lo IuncLIons F wILI more LIun one urgumenL ure uIso possIbIe.
InuIIy, sLep (;) reLurns 0iff(fx} symboIIcuIIy II no sImpIIIIcuLIons oI LIe
expressIon f Iuppen In sLeps (1) LIrougI (6).
0iff`s mode oI operuLIon Is udopLed Irom LIe sysLem IuncLIon diff. Compure LIe
IoIIowIng resuILs Lo LIose reLurned by diff:
0iff(x*in(x + 1/x} x}
In
_
x +
1
x
_

x
_
1
x
2
1
_
x +
1
x
0iff(f(x}*sin(x^Z} x}
sIn
_
x
2
_
DIII(f(x) , x) + 2 x cos
_
x
2
_
f(x)
1,-qo
Progromming Eercises
Fregrummiag xertises
Ixercise 1,.: WrILe u sIorL procedure dole LIuL Lukes LIree InLegers monlh, doy,
yeor us InpuL und prInLs LIe duLe In LIe usuuI wuy. or exumpIe, LIe cuII
dole(531990} sIouId yIeId LIe screen ouLpuL 5/3/1990.
Ixercise 1,.q: We deIIne LIe IuncLIon f : N N by
f(x) =
_
3 x + 1 Ior odd x,
x/2 Ior even x.
TIe (3 x + 1) probIem usks wIeLIer Ior un urbILrury InILIuI vuIue x
0
N, LIe
sequence recursIveIy deIIned by x
i+1
:= f(x
i
) conLuIns LIe vuIue 1. WrILe u
progrum LIuL on InpuL x
0
reLurns LIe smuIIesL Index i wILI x
i
= 1.
Ixercise 1,.g: mpIemenL u IuncLIon Ccd Lo compuLe LIe greuLesL common
dIvIsor oI Lwo posILIve InLegers. OI course, you sIouId noL use LIe sysLem
IuncLIons gcd und igcd. HInL: LIe EucIIdeun AIgorILIm Ior compuLIng LIe gcd Is
bused on LIe observuLIon
gcd(a, b) = gcd(a mod b, b) = gcd(b, a mod b)
und LIe IucLs gcd(0, b) = gcd(b, 0) = b.
Ixercise 1,.6: mpIemenL u IuncLIon uodrolure. or u IuncLIon f und u
MuPAD

IIsL X oI numerIcuI vuIues


x
0
< x
1
< < x
n
,
LIe cuII uodrolure(fX} sIouId compuLe u numerIcuI upproxImuLIon oI LIe
InLegruI
_
x
n
x
0
f(x) dx
n1

i=0
(x
i+1
x
i
) f(x
i
).
1,-q1
TZ NuPAD

Procedures
Ixercise 1,.,: NewLon`s meLIod Ior IIndIng u numerIcuI rooL oI u IuncLIon
f : R R empIoys LIe ILeruLIon x
i+1
= F(x
i
), wIere F(x) = x f(x)/f

(x).
WrILe u procedure WeWlon. TIe cuII WeWlon(fx0n}, wILI un expressIon f,
sIouId reLurn LIe IIrsL n + 1 eIemenLs x
0
, . . . , x
n
oI LIe NewLon sequence.
or bonus poInLs, exLend LIe exumpIe on puge 11-q Lo dIspIuy LIe sequence jusL
Iound.
Ixercise 1,.S: TIe Sierpinsli tricnle Is u weII-known IrucLuI. We deIIne u
vurIunL oI IL us IoIIows. TIe SIerpInskI LrIungIe Is LIe seL oI uII poInLs (x, y) NN
wILI LIe IoIIowIng properLy: LIere exIsLs uL IeusL one posILIon In LIe bInury
expunsIons oI x und y sucI LIuL boLI Iuve u 1-bIL uL LIIs posILIon. WrILe u progrum
Sierpinski LIuL on InpuL xmoxymox pIoLs LIe seL oI uII sucI poInLs wILI InLeger
coordInuLes In LIe runge 1 x xmox, 1 y ymox. HInL: LIe IuncLIon
numiib..godic compuLes LIe bInury expunsIon oI un InLeger. TIe grupIIcuI
prImILIve piol..PoinlLislZd cun be used Lo creuLe u pIoL oI LIe poInLs.
Ixercise 1,.q: A loiccl jormulc Is composed oI IdenLIIIers und LIe operuLors
ond, or, und nol. or exumpIe:
formuio .= (x ond y} or
((y or z} ond (nol x} ond y ond z}
SucI u IormuIu Is cuIIed sctisjicble II IL Is possIbIe Lo ussIgn LIe vuIues TRuE und
FALSE Lo uII IdenLIIIers In sucI u wuy LIuL LIe IormuIu cun be evuIuuLed Lo TRuE.
WrILe u progrum LIuL cIecks wIeLIer un urbILrury IogIcuI IormuIu Is suLIsIIubIe.
1,-q
k
Solotions to Ixercises
Ixercise .1: TIe IeIp puge ?diff LeIIs you Iow Lo compuLe IIgIer order
derIvuLIves:
diff(sin(x^Z} x x x x x}
32 x
5
cos
_
x
2
_
120 x cos
_
x
2
_
+ 160 x
3
sIn
_
x
2
_
You cun uIso use LIe Ionger commund diff(diff(...x}x}.
Ixercise .: TIe exucL represenLuLIons ure:
sqrl(Z7} - Z*sqrl(3} cos(PT/}

3,
_

2 + 2
2
TIe numerIcuI upproxImuLIons ure:
0TCTTS .= 5.
fiool(sqrl(Z7} - Z*sqrl(3}} fiool(cos(PT/}}
1.7321, 0.92388
TIey ure correcL Lo wILIIn 5 dIgILs.
Ixercise .:
expond((x^Z + y}^5}
x
10
+ 5 x
8
y + 10 x
6
y
2
+ 10 x
4
y
3
+ 5 x
2
y
4
+y
5
A 5olu|ions |o Eercises
Ixercise .q:
normoi((x^Z - 1}/(x + 1}}
x 1
Ixercise .g: You cun pIoL LIe sInguIur IuncLIon f(x) = 1/ sIn(x) on LIe InLervuI
[1, 10] wILIouL uny probIems:
piol(1/sin(x} x = 1..10}
Ixercise .6: MuPAD

ImmedIuLeIy reLurns LIe cIuImed IImILs:


iimil(sin(x}/x x = 0}
iimil((1 - cos(x}}/x x = 0}
iimil(in(x} x = 0 Righl}
1, 0,
iimil(x^sin(x} x = 0}
iimil((1 + 1/x}^x x = infinily}
iimil(in(x}/exp(x} x = infinily}
1, e, 0
A-
5olu|ions |o Eercises
iimil(x^in(x} x = 0 Righl}
iimil((1 + PT/x}^x x = infinily}
iimil(Z/(1 + exp(-1/x}} x = 0 Lefl}
, e

, 0
TIe resuIL undefined denoLes u non-exIsLIng IImIL:
iimil(exp(col(x}} x = 0}
undeIIned
Ixercise .,: You obLuIn LIe IIrsL resuIL In LIe desIred Iorm by IucLorIng:
sum(k^Z + k + 1 k = 1..n}. x = foclor(x}
n
3
3
+n
2
+
5 n
3
=
_
1
3
_
n
_
n
2
+ 3 n + 5
_
sum((Z*k - 3}/((k + 1}*(k + Z}*(k + 3}}
k = 0..infinily}

1
4
sum(k/(k - 1}^Z/(k + 1}^Z k = Z..infinily}
5
16
Ixercise .S:
A .= molrix(__1 Z 3] _4 5 6] _7 0]]}.
B .= molrix(__1 1 0] _0 0 1] _0 1 0]]}.
Z*(A + B} A*B
_
_
_
4 6 6
8 10 14
14 18 0
_
_
_,
_
_
_
1 4 2
4 10 5
7 7 8
_
_
_
A-
A 5olu|ions |o Eercises
(A - B}^(-1}
_
_
_

5
2
3
2

5
7
5
2

3
2
6
7

1
2
1
2

2
7
_
_
_
Ixercise .q: u) TIe IuncLIon numiib..mersenne reLurns u IIsL oI vuIues Ior p
yIeIdIng LIe 44 currenLIy known Mersenne prImes LIuL Iuve been Iound on
supercompuLers. TIe ucLuuI compuLuLIon Ior 1 < p 1000 cun be eusIIy
perIormed In MuPAD:
seiecl(_S 1..1000] isprime}.
seiecl(x p -> (isprime(Z^p - 1}}}
AILer some LIme you obLuIn LIe desIred IIsL oI vuIues oI p:
seiecl(x p -> (isprime(Z^p - 1}}}
[2, 3, 5, 7, 13, 17, 19, 31, 61, 89, 107, 127, 521, 607]
TIe correspondIng Mersenne prImes ure:
mop(x p -> (Z^p-1}}
_3 7 31 1Z7 191 131071 5Z4Z7 Z14743647
Z30543009Z13693951 6197001964Z69013744956Z111
16ZZ59Z76Z9Z1336339157010Z1Z7 ... ]
b) DependIng on your compuLer`s speed, you cun LesL onIy LIe IIrsL 13 or 14 ermuL
numbers In u reusonubIe umounL oI LIme. NoLe LIuL LIe 12-LI ermuL number
uIreudy Ius 1234 decImuI dIgILs.
Fermol .= n -> Z^(Z^n} + 1. isprime(Fermol(10}}
ASE
TIe onIy known ermuL prImes ure LIe IIrsL IIve ermuL numbers (IncIudIng
Fermol(0}). ndeed, II MuPAD LesLs LIe IIrsL 12 ermuL numbers, LIen uILer some
LIme IL reLurns LIe IoIIowIng IIve vuIues:
A-q
5olu|ions |o Eercises
seiecl(_Fermol(i} S i = 0..11] isprime}
[3, 5, 17, 257, 65537]
Ixercise q.1: TIe IIrsL operund oI u power Is LIe buse, LIe second Is LIe
exponenL. TIe IIrsL und second operund oI un equuLIon Is LIe IeIL und LIe
rIgIL-Iund sIde, respecLIveIy. TIe operunds oI u IuncLIon cuII ure ILs urgumenLs:
op(o^b 1} op(o^b Z}
a, b
op(o = b 1} op(o = b Z}
a, b
op(f(o b} 1} op(f(o b} Z}
a, b
Ixercise q.: TIe IIsL wILI LIe Lwo equuLIons Is op(sel1}. Ls second operund
Is LIe equuLIon y=..., wIose second operund Is LIe rIgIL-Iund sIde:
sel .= soive({x+sin(3}*y = exp(o}
y-sin(3}*y = exp(-o}] {xy]}
__
x =
e
a
sIn(3) e
a
+
sIn(3)
e
a
sIn(3) 1
, y =
1
e
a
(sIn(3) 1)
__
y .= op(sel _1 Z Z]}

1
e
a
(sIn(3) 1)
Use ossign(op(sel}} Lo perIorm ussIgnmenLs oI boLI unknowns x und y
sImuILuneousIy.
Ixercise q.: I uL IeusL one number In u numerIcuI expressIon Is u IIouLIng-poInL
number, LIen LIe resuIL Is u IIouLIng-poInL number:
1/3 + 1/3 + 1/3 1.0/3 + 1/3 + 1/3
1, 1.0
A-g
A 5olu|ions |o Eercises
Ixercise q.q: You obLuIn LIe desIred IIouLIng-poInL numbers ImmedIuLeIy by
uppIyIng fiool:
fiool(PT^(PT^PT}} fiool(exp(PT*sqrl(163}/3}}
1.340164183 10
18
, 640320.0
NoLe LIuL onIy LIe IIrsL 10 dIgILs oI LIese vuIues ure reIIubIe sInce LIIs Is LIe deIuuIL
precIsIon. ndeed, Ior Iurger vuIues oI 0TCTTS, you IInd:
0TCTTS .= 100.
fiool(PT^(PT^PT}} fiool(exp(PT*sqrl(163}/3}}
134016413006357435.Z974491Z9640131415099374974573499`
Z37779Z75165603409Z6190940614Z6947Z61130114Z

6403Z0.00000000060463735049016039471741115394757`
714576036659119465ZZ1Z5Z694Z53634015ZZ646
We compuLe 235 decImuI dIgILs oI PT Lo obLuIn LIe correcL 234-LI dIgIL uILer LIe
decImuI poInL. AILer seLLIng 0TCTTS.=Z35, LIe resuIL Is LIe IusL sIown dIgIL oI
fiool(PT}. A more eIegunL wuy Is Lo muILIpIy by 10
234
. TIen LIe desIred dIgIL Is
LIe IIrsL dIgIL beIore LIe decImuI poInL, und we obLuIn IL by LruncuLIng LIe dIgILs
uILer LIe decImuI poInL:
0TCTTS .= Z35. lrunc(10^Z34*PT} - 10*lrunc(10^Z33*PT}
6
Ixercise q.g: u) nLernuIIy, MuPAD compuLes wILI some uddILIonuI dIgILs noL
sIown In LIe ouLpuL.
0TCTTS .= 10. x .= 10^50/3.0 fioor(x}
3.333333333 10
49
33333333333333333307484730568084080731669827420160
A-6
5olu|ions |o Eercises
b) AILer IncreusIng 0TCTTS, MuPAD dIspIuys LIe uddILIonuI dIgILs. However, noL
uII oI LIem ure correcL:
0TCTTS .= 40. x
3.333333333333333330748473056808408073167 10
49
ResLurL LIe compuLuLIon wILI LIe Increused vuIue oI 0TCTTS Lo obLuIn LIe desIred
precIsIon:
0TCTTS .= 40. x .= 10^50/3.0
3.333333333333333333333333333333333333333 10
49
Ixercise q.6: TIe numes coulion!-!, x-y, und Jock&Jiii ure InvuIId sInce LIey
conLuIn LIe specIuI cIurucLers !, -, und &, respecLIveIy. SInce un IdenLIIIer`s nume
musL noL sLurL wILI u number, Zx Is noL vuIId eILIer. TIe numes diff und exp ure
vuIId numes oI IdenLIIIers. However, you cunnoL ussIgn vuIues Lo LIem sInce LIey
ure proLecLed numes oI MuPAD IuncLIons. TIe nume #1 Is u vuIId nume oI
IdenLIIIer. However, you cunnoL ussIgn vuIues Lo IL becuuse, sLurLIng wILI u IusI
murk, IL cunnoL be ussIgned Lo.
Ixercise q.,: We use LIe sequence operuLor S (puge q-zq) Lo generuLe LIe seL oI
equuLIons und LIe seL oI unknowns. TIen u cuII Lo soive reLurns u seL oI sImpIer
equuLIons:
equolions .= {(x.i + x.(i+1} = 1} S i = 1..19
xZ0 = PT].
unknoWns .= {x.i S i = 1..Z0].
soiulions .= soive(equolions unknoWns}
{_x1 = 1 - PT x10 = PT x11 = 1 - PT x1Z = PT
x13 = 1 - PT x14 = PT x15 = 1 - PT x16 = PT
x17 = 1 - PT x1 = PT x19 = 1 - PT xZ = PT
xZ0 = PT x3 = 1 - PT x4 = PT x5 = 1 - PT
x6 = PT x7 = 1 - PT x = PT x9 = 1 - PT]]
A-,
A 5olu|ions |o Eercises
We use LIe IuncLIon ossign Lo ussIgn LIe compuLed vuIues Lo LIe IdenLIIIers:
ossign(op(soiulions 1}}. x1 xZ x3 x4 x5 x6
1 , , 1 , , 1 ,
Ixercise q.S: MuPAD sLores LIe expressIon o^b-sin(o/b} In LIe Iorm
sin(o*b^(-1}}*(-1}+o^b. Ls expressIon Lree Is:
+
*
sin
*
o ^
b -1
-1
^
o b
Ixercise q.q: We observe LIuL:
op(Z/3} op(x/3}
2, 3
x,
1
3
TIe reuson Is LIuL Z/3 Is oI domuIn Lype 00MRAT, wIose operunds ure LIe
numeruLor und LIe denomInuLor. TIe domuIn Lype oI LIe symboIIc expressIon x/3
Is 00MEXPR und ILs InLernuI represenLuLIon Is x*(1/3}. TIe sILuuLIon Is sImIIur Ior
1+Z*T und x+Z*T:
op(1 + Z*T} op(x + Z*T}
1, 2
x, 2 I
A-S
5olu|ions |o Eercises
TIe IIrsL objecL Is oI domuIn Lype 00MC0MPLEX. Ls operunds ure LIe reuI und LIe
ImugInury purL. TIe operunds oI LIe symboIIc expressIon x+Z*T ure LIe IIrsL und
LIe second Lerm oI LIe sum.
Ixercise q.1o: TIe expressIon Lree oI condilion=(nol o} ond (b or c} Is:
ond
nol
o
or
b c
TIus op(condilion1}=nol o und op(condilionZ}=b or c. We obLuIn LIe
uLoms o, b, c us IoIIows:
op(condilion _1 1]} op(condilion _Z 1]}
op(condilion _Z Z]}
a, b, c
Ixercise q.11: You cun use boLI LIe ussIgnmenL IuncLIon ossign presenLed on
puge q-8 und LIe ussIgnmenL operuLor .=.
for i from 1 lo 100 do ossign(x.i i} end.
for i from 1 lo 100 do x.i .= i end.
You cun uIso puss u seL oI ussIgnmenL equuLIons Lo LIe ossign IuncLIon:
ossign({x.i = i S i = 1..100]}.
Ixercise q.1: SInce u sequence Is u vuIId urgumenL oI LIe sequence operuLor,
you muy ucIIeve LIe desIred resuIL us IoIIows:
(x.i S i} S i = 1..10
x1 xZ xZ x3 x3 x3 x4 x4 x4 x4 ...
A-q
A 5olu|ions |o Eercises
Ixercise q.1: We use LIe uddILIon IuncLIon pius und generuLe ILs urgumenL
sequence vIu S:
pius(((i+g}^(-1} S g = 1.. i} S i=1..10}
1464232069
232792560
Ixercise q.1q:
L1 .= _o b c d]. LZ .= _1 Z 3 4].
L1.LZ zip(L1 LZ muil}
[a, b, c, d, 1, 2, 3, 4] , [a, 2 b, 3 c, 4 d]
Ixercise q.1g: TIe IuncLIon muil muILIpIIes ILs urgumenLs:
mop(_1 x Z] muil muilipiier}
[muILIpIIer, muILIpIIer x, 2 muILIpIIer]
We use mop Lo uppIy LIe IuncLIon subiisl ->mop(subiislmuilZ} Lo LIe
subIIsLs In u nesLed IIsL:
L .= __1 x Z] _PT] _Z/3 1]].
mop(L mop muil Z}
_
[2, 2 x, 4] , [2 ] ,
_
4
3
, 2
__
Ixercise q.16: or
X .= _x1 xZ x3]. Y .= _y1 yZ y3].
LIe producLs ure gIven ImmedIuLeIy by
pius(op(zip(X Y muil}}}
x1 y1 +xz yz +x y
A-1o
5olu|ions |o Eercises
TIe IoIIowIng IuncLIon f muILIpIIes eucI eIemenL oI LIe IIsL Y by ILs InpuL
purumeLer x und reLurns LIe resuILIng IIsL:
f .= x -> (mop(Y muil x}}.
TIe nexL commund repIuces eucI eIemenL oI X by LIe IIsL reLurned by f:
mop(X f}
[[x1 y1, x1 yz, x1 y] , [xz y1, xz yz, xz y] , [x y1, x yz, x y]]
Ixercise q.1,: or eucI m, we use LIe sequence generuLor S Lo creuLe u IIsL oI uII
InLegers Lo be cIecked. TIen we exLrucL uII prImes Irom LIe IIsL vIu
seiecl(isprime}. TIe number oI prImes Is jusL nops oI LIe resuILIng IIsL. We
compuLe LIIs vuIue Ior uII m beLween 0 und 41:
nops(seiecl(_(n^Z + n + m} S n = 1..100] isprime}}
S m = 0..41
1 3Z 0 14 0 Z9 0 31 0 13 0 4 0 1 0
11 0 59 0 Z5 0 14 0 Z 0 Z 0 16 0
34 0 35 0 11 0 Z4 0 36 0 17 0 6
TIere Is u sImpIe expIunuLIon Ior LIe zero vuIues Ior even m > 0. SInce
n
2
+n = n(n + 1) Is uIwuys even, n
2
+n +m Is un even InLeger greuLer LIun 2 und
Ience noL u prIme.
Ixercise q.1S: We sLore LIe cIIIdren In u IIsL C und remove LIe one LIuL wus
counLed ouL uL LIe end oI eucI round. We represenL LIe posILIons 1, 2, . . . , n oI n
cIIIdren by u IIsL wILI LIe correspondIng InLegers. eL oul {1, . . . , n} be LIe
posILIon oI LIe IusL cIIId LIuL wus counLed ouL. AILer deIeLIng LIe oul-LI eIemenL,
LIe nexL round begIns uL posILIon oul In LIe sIorLened IIsL. AL LIe end oI LIe
round, uILer m words, LIe cIIId uL posILIon oul+m-1 In LIe currenL IIsL Is counLed
ouL. SInce we ure counLIng cycIIcuIIy, we Luke LIIs vuIue moduIo LIe number oI
remuInIng cIIIdren. NoLe, Iowever, LIuL o mod b produces numbers In LIe runge
0, 1, . . . , b 1 ruLIer LIun 1, . . . , b. TIIs Is overcome by usIng ((o-1} mod b}+1
InsLeud oI o mod b:
m .= . n .= 1Z. C .= _S 1..n]. oul .= 1.
A-11
A 5olu|ions |o Eercises
oul .= ((oul + m - Z} mod nops(C}} + 1.
C_oul]
8
deiele C_oul].
oul .= ((oul + m - Z} mod nops(C}} + 1.
C_oul]
4
eLc. L Is useIuI Lo ImpIemenL LIe compIeLe counLIng by u Ioop (CIupLer 1):
m .= . n .= 1Z. C .= _S 1..n]. oul .= 1.
repeol
oul .= ((oul + m - Z} mod nops(C}} + 1.
prinl(C_oul]}
deiele C_oul]
unlii nops(C} = 0 endrepeol.

4
1
11
...
9
5
Ixercise q.1q:
sel .= {op(iisl}]. iisl .= _op(sel}].
NoLe LIuL LIe Lwo conversIons list set list In generuI cIunge LIe order oI LIe
IIsL eIemenLs.
A-1
5olu|ions |o Eercises
Ixercise q.o:
A .= {o b c]. B .= {b c d]. C .= {b c e].
A union B union C A inlersecl B inlersecl C
A minus (B union C}
{a, b, c, d, e} , {b, c} , {a}
Ixercise q.1: You obLuIn LIe unIon vIu union:
M .= {{Z 3] {3 4] {3 7] {5 3] {1 Z 3 4]].
union(op(M}}
{1, 2, 3, 4, 5, 7}
und LIe InLersecLIon vIu inlersecl:
inlersecl(op(M}}
{3}
Ixercise q.:
leiephone0ireclory .= lobie(Ford = 115
Reogon = 4711 Bush = 1Z34 Ciinlon = 567}.
An Indexed cuII reLurns ord`s number:
leiephone0ireclory_Ford]
1815
You cun use seiecl Lo exLrucL uII LubIe enLrIes conLuInIng LIe number 6;8:
seiecl(leiephone0ireclory hos 567}
CIInLon 5678
Ixercise q.: TIe commund _op(Tobie}] reLurns u IIsL oI uII ussIgnmenL
equuLIons. TIe cuII mop(opi} (i = 1, 2) exLrucLs LIe IeIL und LIe rIgIL-Iund
sIdes, respecLIveIy, oI LIe equuLIons:
T .= lobie(o = 1 b = Z
1 - sin(x} = "derivolive of x + cos(x}" }.
A-1
A 5olu|ions |o Eercises
indices .= mop(_op(T}] op 1}
[a, b, 1 sIn(x)]
voiues .= mop(_op(T}] op Z}
[1, 2, derIvuLIve oI x + cos(x)]
Ixercise q.q: TIe IoIIowIng LImIngs (In mIIIIseconds) sIow LIuL generuLIng u
LubIe Is more LIme consumIng:
n .= 100000.
lime((T .= lobie((i=i} S i=1..n}}}
lime((L .= _i S i=1..n]}}
422, 165
However, workIng wILI LubIes Is noLubIy IusLer. TIe IoIIowIng ussIgnmenLs creuLe
un uddILIonuI LubIe enLry und exLend LIe IIsL by one eIemenL, respecLIveIy:
lime((T_n + 1] .= WeW}} lime((L .= L._WeW]}}
0, 84
Ixercise q.g: We use LIe sequence generuLor S Lo creuLe u nesLed IIsL und puss
IL Lo orroy:
n .= Z0.
orroy(1..n 1..n
__1/(i + g - 1} S g = 1..n] S i = 1..n]}.
Ixercise q.6:
TRuE ond (FALSE or nol (FALSE or nol FALSE}}
ASE
Ixercise q.,: We use LIe IuncLIon zip Lo generuLe u IIsL oI compurIsons. We
puss LIe sysLem IuncLIon iess us LIIrd urgumenL, wIIcI generuLes InequuIILIes oI
LIe Iorm o<b. TIen we exLrucL LIe sequence oI InequuIILIes vIu op und puss IL Lo
ond:
A-1q
5olu|ions |o Eercises
L1 .= _10*i^Z - i^3 S i = 1..10].
LZ .= _i^3 + 13*i S i = 1..10].
ond(op(zip(L1 LZ iess}}}
9 < 14 ond 3Z < 34 ond 63 < 66 ond 96 < 116 ond
1Z5 < 190 ond 144 < Z94 ond 147 < 434 ond
1Z < 616 ond 1 < 46 ond 0 < 1130
InuIIy, evuIuuLIng LIIs expressIon wILI booi unswers LIe quesLIon:
booi(x}
TRUE
Ixercise q.S: TIe IuncLIon sorl does noL sorL LIe IdenLIIIers uIpIubeLIcuIIy by
LIeIr numes buL uccordIng Lo un InLernuI order (puge q-z8). TIus, we converL
LIem Lo sLrIngs vIu exprZlexl beIore sorLIng:
sorl(mop(onomes(Aii} exprZlexl}}
_"Ax" "Axiom" "AxiomConslruclor" "C" "Col"
"Colegory" ... "zelo" "zip"]
Ixercise q.q: We compuLe LIe reIIecLIon oI LIe puIIndrome
lexl .= "Wever odd or even".
by pussIng LIe reIIecLed sequence oI IndIvIduuI cIurucLers Lo LIe IuncLIon concol,
wIIcI converLs IL Lo u sLrIng uguIn:
n .= ienglh(lexl}.
concol(lexl_n - i + 1] S i = 1..n}
neve ro ddo reveN
TIIs cun uIso be ucIIeved wILI LIe cuII reverl(lexl}.
Ixercise q.o:
f .= x -> (x^Z}. g .= x -> (sqrl(x}}.
A-1g
A 5olu|ions |o Eercises
(fefeg}(Z} (fee100}(x}
4, x
1267650600228229401496703205376
Ixercise q.1: TIe IoIIowIng IuncLIon does LIe job:
f .= L -> _L_nops(L} + 1 - i] S i = 1..nops(L}]
L -> _L_(nops(L} + 1} - i] S i = 1..nops(L}]
f(_o b c]}
[c, b, a]
However, LIe sImpIesL soIuLIon Is Lo use f.=reverl.
Ixercise q.: You cun use LIe IuncLIon iosl (CIupLer 1.z) Lo generuLe LIe
CIebysIev poIynomIuIs us expressIons:
T0 .= 1. T1 .= x.
TZ .= Z*x*x - xZ T3.= Z*x*x - xZ T4.= Z*x*x - xZ
2 x
2
1
2 x
_
2 x
2
1
_
x
1 2 x
2
2 x
_
x 2 x
_
2 x
2
1
__
A mucI more eIegunL wuy Is Lo LrunsIuLe LIe recursIve deIInILIon InLo u MuPAD
IuncLIon LIuL works recursIveIy:
T .= (k x} ->
(if k < Z
lhen x^k
eise Z*x*T(k - 1 x} - T(k - Z x}
endif}.
TIen we obLuIn:
T(i 1/3} S i = Z..5

7
9
,
23
27
,
17
81
,
241
243
A-16
5olu|ions |o Eercises
T(i 0.33} S i = Z..5
0.7822, 0.846252, 0.22367368, 0.9938766288
T(i x} S i = Z..5
Z Z
Z x - 1 Z x (Z x - 1} - x
Z Z
1 - Z x - Z x (x - Z x (Z x - 1}} x -
Z Z
Z x (Z x - 1} - Z x (Z x (x - Z x (Z x - 1}} +
Z
Z x - 1}
You cun obLuIn expunded represenLuLIons oI LIe poIynomIuIs by InserLIng u cuII Lo
expond (puge q-) In LIe IuncLIon deIInILIon.
TIe CIebysIev poIynomIuIs ure uIreudy ImpIemenLed In orlhpoiy, LIe IIbrury Ior
orLIogonuI poIynomIuIs. TIe i-LI CIebysIev poIynomIuI Is reLurned by LIe cuII
orlhpoiy..chebyshev1(i x}.
Ixercise q.: n prIncIpIe, you cun compuLe LIe derIvuLIves oI f In MuPAD und
subsLILuLe x = 0. BuL IL Is sImpIer Lo upproxImuLe LIe IuncLIon by u TuyIor serIes
wIose IeudIng Lerms descrIbe LIe beIuvIor In LIe neIgIborIood oI x = 0:
loyior(lon(sin(x}} - sin(lon(x}} x = 0}
x
7
30
+
29 x
9
756
+
1913 x
11
75600
+O
_
x
13
_
TIus, f(x) = x
7
/30 (1 +O(x
2
)), und Ience f Ius u rooL oI order 7 uL x = 0.
A-1,
A 5olu|ions |o Eercises
Ixercise q.q: TIe reuson Ior LIe dIIIerence beLween LIe resuILs
loyior(diff(1/(1 - x} x} x}
diff(loyior(1/(1 - x} x} x}
1 + 2 x + 3 x
2
+ 4 x
3
+ 5 x
4
+ 6 x
5
+O
_
x
6
_
1 + 2 x + 3 x
2
+ 4 x
3
+ 5 x
4
+O
_
x
5
_
Is LIe LruncuLIon deLermIned by LIe envIronmenL vurIubIe 0R0ER wILI LIe deIuuIL
vuIue 6. BoLI loyior cuIIs compuLe LIe correspondIng serIes up Lo O(x
6
):
loyior(1/(1 - x} x}
1 +x +x
2
+x
3
+x
4
+x
5
+O
_
x
6
_
TIe order Lerm 0(x^5} uppeurs wIen LIe Lerm 0(x^6} Is dIIIerenLIuLed:
diff(x x}
1 + 2 x + 3 x
2
+ 4 x
3
+ 5 x
4
+O
_
x
5
_
Ixercise q.g: An usympLoLIc expunsIon yIeIds:
f .= sqrl(x + 1} - sqrl(x - 1}.
g .= series(f x = infinily}
1

x
+
1
8 x
5
2
+
7
128 x
9
2
+O
_
1
x
11
2
_
TIus
f
1

x
_
1 +
1
8 x
2
+
7
128 x
4
+
_
,
und Ience f(x) 1/

x Ior uII reuI x 1. TIe nexL beLLer upproxImuLIon Is


f(x)
1

x
_
1 +
1
8 x
2
_
.
A-1S
5olu|ions |o Eercises
Ixercise q.6: TIe commund ?reverl requesLs LIe correspondIng IeIp puge.
f .= loyior(sin(x + x^3} x} g .= reverl(x}
x +
5 x
3
6

59 x
5
120
+O
_
x
7
_
x
5 x
3
6
+
103 x
5
40
+O
_
x
7
_
To cIeck LIIs resuIL, we consIder LIe composILIon oI f und g, wIose serIes
expunsIon Is LIuL oI LIe IdenLILy IuncLIon x x:
gef
x +O
_
x
7
_
Ixercise q.,: We perIorm LIe compuLuLIon over LIe sLundurd coeIIIcIenL rIng
(puge q-6q), wIIcI comprIses boLI ruLIonuI numbers und IIouLIng-poInL numbers:
n .= 16.
| .= molrix(n n (i g} -> ((i + g -1}^(-1}}}.
e .= molrix(n 1 1}. b .= |*e.
We IIrsL compuLe LIe soIuLIon oI LIe sysLem oI equuLIons H x =

b wILI exucL
urILImeLIc over LIe ruLIonuI numbers. TIen we converL uII enLrIes oI H und

b Lo
IIouLIng-poInL numbers und soIve LIe sysLem numerIcuIIy (und In LIe unsLubIe und
sIow wuy, usIng un expIIcIL Inverse InsLeud oI cuIIIng numeric..moliinsoive):
exocl = |^(-1}*b numericoi = fiool(|}^(-1}*fiool(b}
exucL =
_
_
_
_
_
_
_
_
_
_
_
1
1
. . .
1
1
1
_
_
_
_
_
_
_
_
_
_
_
, numerIcuI =
_
_
_
_
_
_
_
_
_
_
_
0.999999993
1.000000164
. . .
11.875
4.036132812
0.3975830078
_
_
_
_
_
_
_
_
_
_
_
A-1q
A 5olu|ions |o Eercises
TIe errors In LIe numerIcuI soIuLIon orIgInuLe Irom roundIng errors. To
demonsLruLe LIIs, we repeuL LIe numerIcuI compuLuLIon wILI IIgIer precIsIon:
0TCTTS .= Z0.
numericoi = fiool(|}^(-1}*fiool(b}
numerIcuI =
_
_
_
_
_
_
_
_
_
_
_
1.0000000505004147319
0.99999992752642441474
. . .
0.99999889731407165527
1.0000003278255462646
0.9999999580904841423
_
_
_
_
_
_
_
_
_
_
_
Ixercise q.S: We Iook Ior vuIues wIere LIe deLermInunL oI LIe muLrIx vunIsIes:
molrix(__1 o b] _1 1 c] _1 1 1]]}.
foclor(iinoig..del(x}}
(c 1) (a 1)
TIe muLrIx Is InverLIbIe unIess a = 1 or c = 1.
Ixercise q.q: We IIrsL sLore LIe muLrIx duLu In urruys. TIese urruys ure used
IuLer Lo generuLe muLrIces over dIIIerenL coeIIIcIenL rIngs:
o .= orroy(1..3 1..3 __ 1 3 0]
_-1 Z 7]
_ 0 1]]}.
b .= orroy(1..3 1..Z __7 -1] _Z 3] _0 1]]}.
Now we deIIne LIe consLrucLor M Ior muLrIces over LIe ruLIonuI numbers und
converL LIe urruys Lo correspondIng muLrIces:
M .= 0om..Molrix(0om..Rolionoi}. A .= M(o}. B .= M(b}.
A-o
5olu|ions |o Eercises
TIe meLIod "lronspose" oI LIe consLrucLor compuLes LIe Lrunspose oI u muLrIx B
vIu M..lronspose(B}:
(Z*A + B*M..lronspose(B}}^(-1}
_
_
_
34
1885
7
1508

153
7540
11
3770

31
3016
893
15080

47
3770
201
3016

731
15080
_
_
_
CompuLIng over LIe resIdue cIuss rIng moduIo 7 we IInd:
Mmod7 .= 0om..Molrix(0om..TnlegerMod(7}}.
A .= Mmod7(o}. B .= Mmod7(b}.
C .= (Z*A + B*Mmod7..lronspose(B}}. C^(-1}
_
_
_
3 mod7 0 mod7 1 mod7
1 mod7 3 mod7 2 mod7
4 mod7 2 mod7 2 mod7
_
_
_
We cIeck LIIs by muILIpIyIng LIe Inverse by LIe orIgInuI muLrIx, wIIcI yIeIds LIe
IdenLILy muLrIx over LIe coeIIIcIenL rIng:
x*C
_
_
_
1 mod7 0 mod7 0 mod7
0 mod7 1 mod7 0 mod7
0 mod7 0 mod7 1 mod7
_
_
_
Ixercise q.qo: We compuLe over LIe coeIIIcIenL rIng oI ruLIonuI numbers:
M .= 0om..Molrix(0om..Rolionoi}.
We consIder 3 3 muLrIces. To deIIne LIe muLrIx, we puss u IuncLIon Lo LIe
consLrucLor LIuL mups LIe IndIces Lo LIe correspondIng muLrIx enLrIes:
A-1
A 5olu|ions |o Eercises
A .= M(3 3 (i g} -> (if i=g lhen 0 eise 1 endif}}
_
_
_
0 1 1
1 0 1
1 1 0
_
_
_
TIe deLermInunL oI A Is
iinoig..del(A}
2
TIe eIgenvuIues ure LIe rooLs oI LIe cIurucLerIsLIc poIynomIuI:
p .= iinoig..chorpoiy(A x}
x
3
3 x 2
soive(p x}
{1, 2}
AILernuLIveIy, LIe iinoig puckuge provIdes u IuncLIon Ior compuLIng eIgenvuIues:
iinoig..eigenvoiues(A}
{1, 2}
eL Id denoLe LIe 3 3 IdenLILy muLrIx. TIe eIgenspuce Ior LIe eIgenvuIue
{1, 2} Is LIe soIuLIon spuce oI LIe sysLem oI IIneur equuLIons
(A Id) x =

0. TIe soIuLIon vecLors spun LIe nuIIspuce (LIe kerneI) oI LIe


muLrIx A Id. TIe IuncLIon iinoig..nuiispoce compuLes u busIs Ior LIe
kerneI oI u muLrIx:
Td .= M..idenlily(3}.
iombdo .= -1. iinoig..nuiispoce(A - iombdo*Td}
_

_
_
_
_
1
1
0
_
_
_,
_
_
_
1
0
1
_
_
_
_

_
TIere ure Lwo IIneurIy IndependenL busIs vecLors. Hence LIe eIgenspuce Ior LIe
eIgenvuIue = 1 Is Lwo-dImensIonuI. TIe oLIer eIgenvuIue Is sImpIe:
A-
5olu|ions |o Eercises
iombdo .= Z. iinoig..nuiispoce(A - iombdo*Td}
_

_
_
_
_
1
1
1
_
_
_
_

_
AILernuLIveIy, iinoig..eigenveclors compuLes uII eIgenspuces sImuILuneousIy:
iinoig..eigenveclors(A}
_

_
_

_1, 2,
_

_
_
_
_
1
1
0
_
_
_,
_
_
_
1
0
1
_
_
_
_

_
_

_,
_

_2, 1,
_

_
_
_
_
1
1
1
_
_
_
_

_
_

_
_

_
TIe reLurn vuIue Is u nesLed IIsL. or eucI eIgenvuIue , IL conLuIns u IIsL oI LIe Iorm
[ , muILIpIIcILy oI , eIgenspuce busIs ].
Ixercise q.q1:
p .= poiy(x^7 - x^4 + x^3 - 1}. q .= poiy(x^3 - 1}.
p - q^Z
poIy
_
x
7
x
6
x
4
+ 3 x
3
2, [x]
_
TIe poIynomIuI p Is u muILIpIe oI q:
p/q
poIy
_
x
4
+ 1, [x]
_
TIIs Is conIIrmed by u IucLorIzuLIon:
foclor(p}
poIy (x 1, [x]) poIy
_
x
2
+ x + 1, [x]
_
poIy
_
x
4
+ 1, [x]
_
foclor(q}
poIy (x 1, [x]) poIy
_
x
2
+ x + 1, [x]
_
A-
A 5olu|ions |o Eercises
Ixercise q.q: We use LIe IdenLIIIer R Lo ubbrevIuLe LIe IengLIy Lype nume
0om..TnlegerMod(3}. WILI oiios, MuPAD uIso uses R us un uIIus In LIe ouLpuL oI
LIe IoIIowIng poIynomIuIs.
p .= 3. oiios(R = 0om..TnlegerMod(p}}.
We onIy need Lo Lry LIe possIbIe remuInders 0, 1, 2 moduIo 3 Ior LIe coeIIIcIenLs
a, b, c In a x
2
+b x +c. We generuLe u IIsL oI uII 18 quudruLIc poIynomIuIs wILI a = 0
us IoIIows:
_((poiy(o*x^Z + b*x + c _x] R} S o = 1..p-1}
S b = 0..p-1} S c = 0..p-1].
TIe commund seiecl(irreducibie} exLrucLs LIe 6 IrreducIbIe poIynomIuIs:
seiecl(x irreducibie}
Z Z
_poiy(x + 1 _x] R} poiy(Z x + x + 1 _x] R}
Z
poiy(Z x + Z x + 1 _x] R}
Z Z
poiy(Z x + Z _x] R} poiy(x + x + Z _x] R}
Z
poiy(x + Z x + Z _x] R}]
Ixercise g.1: TIe vuIue oI x Is LIe IdenLIIIer o1. TIe evuIuuLIon oI x yIeIds LIe
IdenLIIIer c1. TIe vuIue oI y Is LIe IdenLIIIer bZ. TIe evuIuuLIon oI y yIeIds LIe
IdenLIIIer cZ. TIe vuIue oI z Is LIe IdenLIIIer o3. TIe evuIuuLIon oI z yIeIds 10.
TIe evuIuuLIon oI u1 Ieuds Lo un InIInILe recursIon, wIIcI MuPAD uborLs wILI un
error messuge. TIe evuIuuLIon oI uZ yIeIds LIe expressIon vZ^Z-1.
Ixercise 6.1: TIe resuIL oI subsop(b+o1=c} Is b+c und noL c+o, us you mIgIL
Iuve expecLed. TIe reuson Is LIuL subsop evuIuuLes ILs urgumenLs. TIe sysLem
reorders LIe sum InLernuIIy wIen evuIuuLIng IL, und LIus subsop processes o+b
InsLeud oI b+o. Upon reLurn, LIe resuIL c+b Is reordered uguIn.
A-q
5olu|ions |o Eercises
Ixercise 6.: TIe IIgIesL derIvuLIve occurrIng In g Is LIe 6-LI derIvuLIve
diff(f(x}xS6}. We puss LIe sequence oI repIucemenL equuLIons:
diff(f(x} x S 6} = f6 diff(f(x} x S 5} = f5 ...
diff(f(x} x} = f1 f(x} = f0
Lo MuPAD`s subsLILuLIon IuncLIon. NoLe LIuL, In uccordunce wILI LIe usuuI
muLIemuLIcuI noLuLIon, diff reLurns LIe IuncLIon ILseII us LIe 0-LI derIvuLIve:
diff(f(x}xS0}=diff(f(x}}=f(x}.
deiele f. g .= diff(f(x}/diff(f(x} x} x S 5}.
subs(g (diff(f(x} x S 6 - i} = f.(6-i}} S i = 0..6}
4 Z 5 Z
60 fZ 4 f5 Z0 f3 1Z0 f0 fZ 100 fZ f3
------ - ---- + ------ - ---------- - ---------- -
4 f1 Z 6 3
f1 f1 f1 f1
f0 f6 Z5 fZ f4 10 f0 fZ f5 Z0 f0 f3 f4
----- + -------- + ----------- + ----------- -
Z Z 3 3
f1 f1 f1 f1
Z 3 Z
90 f0 fZ f3 Z40 f0 fZ f3 60 f0 fZ f4
------------ + ------------- - ------------
4 5 4
f1 f1 f1
Ixercise ,.1: TIe IoIIowIng communds yIeId LIe desIred evuIuuLIon oI LIe
IuncLIon:
f .= sin(x}/x. x .= 1.Z3. f
0.7662510585
However, x now Ius u vuIue. TIe IoIIowIng cuII diff(fx} wouId InLernuIIy Ieud
Lo LIe commund diff(0.766Z510541.Z3}, sInce diff evuIuuLes ILs urgumenLs.
A-g
A 5olu|ions |o Eercises
You cun cIrcumvenL LIIs probIem by prevenLIng u compIeLe evuIuuLIon oI LIe
urgumenLs vIu ievei or hoid (puge -q):
g .= diff(ievei(f 1} hoid(x}} g
cos(x)
x

sIn(x)
x
2
0.3512303507
Here LIe evuIuuLIon oI hoid(x} Is LIe IdenLIIIer x und noL ILs vuIue. WrILIng
hoid(f} InsLeud oI ievei(f1} wouId yIeId LIe wrong resuIL
diff(hoid(f}hoid(x}}=0, sInce hoid(f} does noL conLuIn hoid(x}. UsIng
ievei(f1} repIuces f by ILs vuIue sin(x}/x (puge -q). TIe nexL cuII oI g reLurns
LIe evuIuuLIon oI g, numeIy LIe vuIue oI LIe derIvuLIve uL x=1.Z3. AILernuLIveIy
you cun deIeLe LIe vuIue oI x:
deiele x. diff(f x} 1 x = 1.Z3
0.3512303507
Ixercise ,.: TIe IIrsL LIree derIvuLIves oI LIe numeruLor und LIe denomInuLor
vunIsI uL LIe poInL x = 0:
Z .= x -> (x^3*sin(x}}. W .= x -> ((1 - cos(x}}^Z}.
Z(0} W(0} Z(0} W(0} Z(0} W(0}
Z(0} W(0}
0, 0, 0, 0, 0, 0, 0, 0
or LIe IourLI derIvuLIves, we Iuve:
Z(0} W(0}
24, 6
TIus LIe IImIL Is Z

(0)/N

(0) = 4, uccordIng Lo de I`HospILuI`s ruIe. TIe


IuncLIon iimil compuLes LIe sume resuIL:
iimil(Z(x}/W(x} x = 0}
4
A-6
5olu|ions |o Eercises
Ixercise ,.: TIe IIrsL order purLIuI derIvuLIves oI f
1
ure:
f1 .= sin(x1*xZ}. diff(f1 x1} diff(f1 xZ}
xz cos(x1 xz) , x1 cos(x1 xz)
TIe second order derIvuLIves ure:
diff(f1 x1 x1} diff(f1 x1 xZ}
diff(f1 xZ x1} diff(f1 xZ xZ}
Z
- xZ sin(x1 xZ} cos(x1 xZ} - x1 xZ sin(x1 xZ}
Z
cos(x1 xZ} - x1 xZ sin(x1 xZ} - x1 sin(x1 xZ}
TIe LoLuI derIvuLIve oI f
2
wILI respecL Lo t Is:
fZ .= x^Z*y^Z. x .= sin(l}. y .= cos(l}. diff(fZ l}
2 cos(t)
3
sIn(t) 2 cos(t) sIn(t)
3
Ixercise ,.q:
inl(sin(x}*cos(x} x = 0..PT/Z}
inl(1/(sqrl(1 - x^Z}} x = 0..1}
inl(x*orclon(x} x = 0..1}
inl(1/x x = -Z..-1}
1
2
,

2
,

4

1
2
, In(2)
Ixercise ,.g:
inl(x/(Z*o*x - x^Z}^(3/Z} x}
x
a

2 a x x
2
inl(sqrl(x^Z - o^Z} x}
x

x
2
a
2
2

a
2
In
_
x +

x
2
a
2
_
2
A-,
A 5olu|ions |o Eercises
inl(1/(x*sqrl(1 + x^Z}} x}
urcsInI
_
_
1
x
2
_
Ixercise ,.6: TIe IuncLIon inliib..chongevor onIy perIorms u cIunge oI
vurIubIes wILIouL InvokIng LIe InLegruLIon:
inliib..chongevor(hoid(inl}(sin(x}*sqrl(1 + sin(x}}
x = -PT/Z..PT/Z} l = sin(x}}
_
1
1
t

t + 1

1 t
2
dt
A IurLIer evuIuuLIon ucLIvuLes LIe InLegruLIon rouLIne:
evoi(x}. x = fiool(x}
2

2
3
= 0.9428090416
NumerIcuI quudruLure reLurns LIe sume resuIL:
numeric..inl(sin(x}*sqrl(1 + sin(x}}
x = -PT/Z..PT/Z}
0.9428090416
Ixercise S.1: TIe equuLIon soIver reLurns LIe generuI soIuLIon:
equolions .= {o + b + c + d + e = 1
o + Z*b + 3*c + 4*d + 5*e = Z
o - Z*b - 3*c - 4*d - 5*e = Z
o - b - c - d - e = 3].
soive(equolions {o b c d e]}
{[a = 2, b = z + 2 z1 3, c = 2 3 z1 2 z, d = z, e = z1]}
TIe Iree purumeLers ure on LIe rIgIL-Iund sIdes oI LIe soIved equuLIons. You cun
deLermIne LIem In MuPAD by exLrucLIng LIe rIgIL Iund sIdes und usIng indels Lo
IInd LIe IdenLIIIers conLuIned LIereIn:
A-S
5olu|ions |o Eercises
mop(x mop op Z} indels(x}
{[2, z + 2 z1 3, 2 3 z1 2 z, z, z1]}
{z, z1}
Ixercise S.: TIe symboIIc soIuLIon Is:
soiulion .= soive(ode(
{y(x} = y(x} + Z*z(x} z(x} = y(x}] {y(x} z(x}]}}
__
z(x) =
Cz e
2 x
2

C1
e
x
, y(x) =
C1
e
x
+Cz e
2 x
__
wILI Iree consLunLs C1CZ. We remove LIe ouLer curIy bruces vIu op:
soiulion .= op(soiulion}
_
z(x) =
Cz e
2 x
2

C1
e
x
, y(x) =
C1
e
x
+Cz e
2 x
_
Now, we seL x = 0 und subsLILuLe y(0} und z(0}, respecLIveIy, Ior LIe InILIuI
condILIons. TIen, we soIve LIe resuILIng IIneur sysLem oI equuLIons Ior C1 und CZ:
soive((soiulion 1 x = 0} 1 _y(0} = 1 z(0} = 1]
{C1 CZ]}
__
C1 =
1
3
, Cz =
4
3
__
AguIn, we remove LIe ouLer curIy bruces vIu op und ussIgn LIe soIuLIon vuIues Lo C1
und CZ by meuns oI ossign:
ossign(op(x}}.
TIus, LIe vuIue uL x = 1 oI LIe symboIIc soIuLIon Ior LIe ubove InILIuI condILIons Is:
x .= 1. soiulion
_
z(1) =
1
3 e
+
2 e
2
3
, y(1) =
4 e
2
3

1
3 e
_
A-q
A 5olu|ions |o Eercises
InuIIy, we uppIy fiool:
fiool(x}
[z(1) = 5.04866388, y(1) = 9.729448318]
Ixercise S.:
soive(ode(y(x}/y(x}^Z = 1/x y(x}}}
_

1
C +In(x)
_
soive(ode({y(x} - sin(x}*y(x} = 0 y(1}=1] y(x}}}
_
e
cos(1)
e
cos(x)
sIn(1)
_
soive(ode({Z*y(x} + y(x}/x = 0 y(1} = PT] y(x}}}
_

x
_
A-o
5olu|ions |o Eercises
soive(ode({diff(x(l}l} = y(l}*z(l}
diff(y(l}l} = x(l}*z(l}
diff(z(l}l} = l*z(l}]
{x(l}y(l}z(l}]}}
{ --
{ 1
{ 1
{ 1
{ 1 x(l} =
{ --
/ 1/Z 1/Z 1/Z `
1 Z C10 (-PT} erf(Z l 1/Z T} 1
C11 exp1 - ----------------------------------- 1
` Z /
------------------------------------------------ +
Z
/ 1/Z 1/Z 1/Z `
1 Z C10 (-PT} erf(Z l 1/Z T} 1
C1Z exp1 ----------------------------------- 1
` Z /
----------------------------------------------
Z
y(l} =
/ 1/Z 1/Z 1/Z `
1 Z C10 (-PT} erf(Z l 1/Z T} 1
C11 exp1 - ----------------------------------- 1
` Z /
------------------------------------------------ -
Z
/ 1/Z 1/Z 1/Z `
1 Z C10 (-PT} erf(Z l 1/Z T} 1
C1Z exp1 ----------------------------------- 1
` Z /
----------------------------------------------
Z
-- ]
1 ]
/ Z ` 1 ]
1 l 1 1 ]
z(l} = C10 exp1 -- 1 1 ]
` Z / -- ]
A-1
A 5olu|ions |o Eercises
Ixercise S.q: TIe IuncLIon soive dIrecLIy yIeIds LIe soIuLIon oI LIe recurrence:
soive(rec(F(n} = F(n-1} + F(n-Z} F(n}
{F(0} = 0 F(1} = 1]}}
_
_
_

5
_

5
2
+
1
2
_
n
5

5
_
1
2

5
2
_
n
5
_
_
_
Ixercise q.1: You obLuIn LIe unswer ImmedIuLeIy Irom simpiify:
simpiify(cos(x}^Z + sin(x}*cos(x}}
cos(2 x)
2
+
sIn(2 x)
2
+
1
2
You geL LIe sume resuIL by uppIyIng combine Lo rewrILe producLs oI LrIgonomeLrIc
IuncLIons us sums:
combine(cos(x}^Z + sin(x}*cos(x} sincos}
cos(2 x)
2
+
sIn(2 x)
2
+
1
2
Ixercise q.:
expond(cos(5*x}/(sin(Z*x}*cos(x}^Z}}
cos(x)
2
2 sIn(x)
5 sIn(x) +
5 sIn(x)
3
2 cos(x)
2
f .= (sin(x}^Z - exp(Z*x}} /
(sin(x}^Z + Z*sin(x}*exp(x} + exp(Z*x}}.
normoi(expond(f}}

e
x
sIn(x)
e
x
+sIn(x)
f .= (sin(Z*x} - 5*sin(x}*cos(x}} /
(sin(x}*(1 + lon(x}^Z}}.
A-
5olu|ions |o Eercises
combine(normoi(expond(f}} sincos}

3 cos(x)
Lun(x)
2
+ 1
f .= sqrl(14 + 3*sqrl(3 +
Z*sqrl(5 - 1Z*sqrl(3 - Z*sqrl(Z}}}}}.
simpiify(f sqrl}

2 + 3
Ixercise q.: As u IIrsL sLep, we perIorm u normuIIzuLIon:
inl(sqrl(sin(x} + 1} x}. normoi(diff(x x}}
3 cos(x)
2
sIn(x) +cos(x)
2
+ 2 sIn(x)
3
2 sIn(x)
cos(x)
2
_
sIn(x) + 1
TIen we eIImInuLe LIe cosIne Lerms:
reWrile(x sin}
2 sIn(x) + sIn(x)
2
2 sIn(x)
3
+ 3 sIn(x)
_
sIn(x)
2
1
_
1
_
sIn(x) + 1
_
sIn(x)
2
1
_
TIe IInuI normuIIzuLIon sLep ucIIeves LIe desIred sImpIIIIcuLIon:
normoi(x}
_
sIn(x) + 1
On LIe oLIer Iund, cuIIIng Simpiify Is mucI eusIer:
inl(sqrl(sin(x} + 1} x}. Simpiify(diff(x x}}
_
sIn(x) + 1
A-
A 5olu|ions |o Eercises
Ixercise q.q: TIe probIem obvIousIy Is LIuL LIe vuIuuLIon IuncLIon does noL Iook
cureIuIIy enougI uL LIe Lerm Lo unuIyze. To remedy LIIs, we use LIe IuncLIon
ienglh wIIcI reLurns u generuI, quIckIy compuLed compIexILy:
noTongenl .= x -> if hos(x _hoid(lon} hoid(col}]}
lhen 1000000
eise ienglh(x} endif.
Simpiify(lon(x} - col(x} voiuolion = noTongenl}

2 cos(2 x)
sIn(2 x)
Ixercise q.g: TIe operuLor ossuming (puge q-18) ussIgns properLIes Lo
IdenLIIIers. TIese ure Luken InLo uccounL by iimil:
iimil(Ei(o*x} x = infinily}
IIm
x
EI(a x)
iimil(Ei(o*x} x = infinily} ossuming o > 0

iimil(Ei(o*x} x = infinily} ossuming o < 0


0
Ixercise 1o.1: n unuIogy Lo LIe prevIous gcd exumpIe, we obLuIn LIe IoIIowIng
experImenL:
die .= rondom(1..6}.
experimenl .= __die(} die(} die(}] S i = 1..Z16].
diceScores .= mop(experimenl
x -> (x_1] + x_Z] + x_3]}}.
frequencies .= 0om..Muilisel(op(diceScores}}.
sorling0rder .= (x y} -> (x_1] < y_1]}.
A-q
5olu|ions |o Eercises
sorl(_op(frequencies}] sorling0rder}
__4 4] _5 9] _6 ] _7 9] _ 16] _9 Z0]
_10 Z7] _11 31] _1Z 3Z] _13 Z0] _14 13]
_15 1Z] _16 6] _17 7] _1 Z]]
n LIIs experImenL, LIe score 3 dId noL occur.
Ixercise 1o.: u) TIe commund frondom Is u generuLor Ior rundom
IIouLIng-poInL numbers In LIe InLervuI [0, 1]. TIe cuII
n .= 1000.
obsvoiues .= _sqrl(frondom(}^Z+frondom(}^Z} S i = 1..n].
reLurns u IIsL wILI LIe ubsoIuLe vuIues oI n rundom vecLors In LIe recLungIe
Q = [0, 1] [0, 1]. TIe number oI vuIues 1 Is LIe number oI rundom poInLs In LIe
rIgIL upper quudrunL oI LIe unIL cIrcIe:
m .= nops(seiecl(obsvoiues z -> (z <= 1}}}
821
SInce m/n upproxImuLes LIe ureu /4 oI LIe rIgIL upper quudrunL oI LIe unIL cIrcIe,
we obLuIn LIe IoIIowIng upproxImuLIon Lo :
fiool(4*m/n}
3.284
b) IrsL we deLermIne LIe muxImum oI f. TIe IoIIowIng IuncLIon pIoL sIows LIuL f
Is monoLonIcuIIy IncreusIng on LIe InLervuI [0, 1]:
A-g
A 5olu|ions |o Eercises
f .= x -> x*sin(x} + cos(x}*exp(x}.
piolfuncZd(f(x} x = 0..1}.
TIus f(x) ussumes ILs muxImuI vuIue uL LIe rIgIL end oI LIe InLervuI. TIereIore,
M = f(1) Is un upper bound Ior LIe IuncLIon:
M .= f(1.0}
2.310164925
We use LIe rundom number generuLor deIIned ubove Lo generuLe rundom poInLs In
LIe recLungIe [0, 1] [0, M]:
n .= 1000.
poinliisl .= __frondom(} M*frondom(}] S i = 1..n].
We seIecL LIose poInLs p = [x, y] Ior wIIcI 0 y f(x) IoIds:
seiecl(poinliisl p -> (p_Z] <= f(p_1]}}}.
m .= nops(x}
742
TIus LIe IoIIowIng Is un upproxImuLIon oI LIe InLegruI:
m/n*M
1.714142374
A-6
5olu|ions |o Eercises
TIe exucL vuIue Is:
fiool(inl(f(x} x = 0..1}}
1.679193292
Ixercise 1.1: WILI LIe IoIIowIng deIInILIon oI LIe posl0ulpul meLIod oI Pref,
LIe sysLem prInLs un uddILIonuI sLuLus IIne:
Pref..posl0ulpul(
proc(}
begin
"byles. " .
exprZlexl(op(byles(} 1}} . " (iogicoi} / " .
exprZlexl(op(byles(} Z}} . " (physicoi}"
endproc}.
fiool(sum(1/i! i = 0..100}}
2.718281828
byles. 3691 (iogicoi} / 100593 (physicoi}
Ixercise 1q.1: We IIrsL generuLe LIe seL S:
f .= i -> (i^(5/Z}+i^Z-i^(1/Z}-1} /
(i^(5/Z}+i^Z+Z*i^(3/Z}+Z*i+i^(1/Z}+1}.
S .= {f(i} S i=-1000..-Z] union {f(i} S i=0..1000].
TIen we uppIy domlype Lo uII eIemenLs oI LIe seL Lo deLermIne LIeIr domuIn Lypes:
mop(S domlype}
{DOM_RAT, DOM_NT, DOM_EXPR}
You see LIe expIunuLIon Ior LIIs resuIL by IookIng uL some eIemenLs:
f(-Z} f(0} f(1} f(Z} f(3} f(4}
(2)
5
2
+ 3

2 I
2 (2)
3
2
+ (2)
5
2
+ 1 +

2 I
, 1, 0,
3

2 + 3
9

2 + 9
,
8

3 + 8
16

3 + 16
,
3
5
TIe IuncLIon normoi sImpIIIIes LIe expressIons conLuInIng squure rooLs:
A-,
A 5olu|ions |o Eercises
mop(x normoi}
3, 1, 0,
1
3
,
1
2
,
3
5
Now we uppIy normoi Lo uII eIemenLs oI LIe seL beIore queryIng LIeIr duLu Lype:
mop(S domlypeenormoi}
{DOM_RAT, DOM_NT}
TIus, uII numbers In S ure Indeed ruLIonuI (In purLIcuIur LIere ure Lwo InLeger
vuIues f(0}=-1 und f(1}=0). TIe reuson Is LIuL f(i} cun be sImpIIIIed Lo
(i-1}/(i+1}:
normoi(f(i}}
i 1
i + 1
Ixercise 1q.: We uppIy lesllype("sin"} Lo eucI eIemenL oI LIe IIsL:
iisl .= _sin(i*PT/Z00} S i = 0..100].
Lo IInd ouL wIeLIer IL Is reLurned In LIe Iorm sin(}. TIe IoIIowIng spiil
commund (puge q-6) decomposes LIe IIsL uccordIngIy:
decomposilion .= spiil(iisl lesllype "sin"}.
MuPAD sImpIIIIed 9 oI LIe 101 cuIIs:
A-S
5olu|ions |o Eercises
mop(decomposilion nops} decomposilion_Z]
_9Z 9 0]
-- 1/Z 1/Z 1/Z 1/Z 1/Z 1/Z
1 5 (Z - Z } Z (5 - 5 }
1 0 ---- - 1/4 ------------- ------------------
-- 4 Z 4
1/Z 1/Z 1/Z 1/Z
Z 5 (Z + Z}
---- ---- + 1/4 -------------
Z 4 Z
1/Z 1/Z 1/Z --
Z (5 + 5} 1
------------------ 1 1
4 --
Ixercise 1q.: You cun use seiecl (puge q-6) Lo exLrucL LIose eIemenLs LIuL
lesllype IdenLIIIes us posILIve InLegers. or exumpIe:
sel .= {-5 Z.3 Z x 1/3 4].
seiecl(sel lesllype Type..PosTnl}
{2, 4}
NoLe LIuL LIIs seIecLs onIy LIose objecLs LIuL cre posILIve InLegers, buL noL LIose
LIuL mIgIL represent posILIve InLegers, sucI us LIe IdenLIIIer x In LIe ubove
exumpIe. TIIs Is noL possIbIe wILI lesllype. nsLeud, you cun use ossume Lo seL
LIIs properLy und query IL vIu is:
ossume(x Type..PosTnl}.
seiecl(sel is Type..PosTnl}
{2, 4, x}
A-q
A 5olu|ions |o Eercises
Ixercise 1q.q: We consLrucL LIe desIred Lype specIIIer und empIoy IL us IoIIows:
T .= Type..Lisl0f(Type..Lisl0f(
Type..AnyType 3 3} Z Z}
Type::IsLOI(Type::IsLOI(Type::AnyType, 3, 3) , 2, 2)
lesllype(__o b c] _1 Z 3]] T}
lesllype(__o b c] _1 Z]] T}
TRUE, ASE
Ixercise 16.1: ConsIder LIe condILIons x<>1 ond A und x=1 or A, respecLIveIy.
AILer enLerIng:
x .= 1.
IL Is noL possIbIe Lo evuIuuLe LIem due Lo LIe sInguIurILy In x/(x 1):
x <> 1 ond A
Error. 0ivision by zero _poWer]
x = 1 or A
Error. 0ivision by zero _poWer]
However, LIIs Is noL u probIem wILIIn un if sLuLemenL sInce LIe BooIeun
evuIuuLIon oI x<>1 und x=1 uIreudy LeIIs us LIuL x<>1 ond A evuIuuLes Lo FALSE
und x=1 or A Lo TRuE, respecLIveIy:
(if x <> 1 ond A lhen righl eise Wrong endif}
(if x = 1 or A lhen righl eise Wrong endif}
wrong, rIgIL
On LIe oLIer Iund, evuIuuLIon oI LIe IoIIowIng if sLuLemenL sLIII produces un
error, sInce IL Is necessury Lo evuIuuLe A In order Lo deLermIne LIe LruLI vuIue oI
x=1 ond A:
if x = 1 ond A lhen righl eise Wrong endif
Error. 0ivision by zero _poWer]
A-qo
5olu|ions |o Eercises
Ixercise 1,.1: WILI LIe IormuIus gIven, ImpIemenLuLIon oI LIe "fiool" sIoLs Is
sLruIgILIorwurd:
eiiipE..fiool .= z -> fiool(PT/Z} *
hypergeom..fiool(_-1/Z 1/Z] _1] z}.
eiiipK..fiool .= z -> fiool(PT/Z} *
hypergeom..fiool(_1/Z 1/Z] _1] z}.
TIIs Is uImosL suIIIcIenL:
eiiipE(1/3}
E
_
1
3
_
fiool(x}
1.430315257
However, one LIIng Is mIssIng: we wouId IIke Lo Iuve cuIIs wILI IIouLIng poInL
urgumenLs evuIuuLed ImmedIuLeIy:
eiiipE(0.1}
E(0.1)
To LIIs end, we musL exLend LIe deIInILIons oI eiiipE und eiiipK:
eiiipE .=
proc(x} begin
if domlype(x} = 00MFL0AT
or domlype(x} = 00MC0MPLEX
ond (domlype(Re(x}} = 00MFL0AT
or domlype(Tm(x}} = 00MFL0AT}
lhen
relurn(eiiipE..fiool(x}}
endif
if x = 0 lhen PT/Z
eiif x = 1 lhen 1
eise procnome(x} endif
endproc.
ExLend eiiipK unuIogousIy, LIen muke LIese new IuncLIons InLo IuncLIon
envIronmenLs (LIe ubove deIInILIon repIuced LIe oId one compIeLeIy) und udd LIe
IuncLIon sIoLs we used Ior LIe orIgInuI deIInILIons und LIe new IIouL sIoLs, und you
geL:
A-q1
A 5olu|ions |o Eercises
eiiipE(0.1}
1.530757637
Ixercise 1,.: TIe IoIIowIng procedure evuIuuLes LIe Abs IuncLIon:
Abs .= proc(x}
begin
if domlype(x} = 00MTWT or domlype(x} = 00MRAT
or domlype(x} = 00MFL0AT
lhen if x >= 0 lhen x eise -x endif
eise procnome(x}
endif
endproc.
We converL Abs Lo u IuncLIon envIronmenL und suppIy u IuncLIon producIng LIe
desIred screen ouLpuL:
Abs .= funcenv(Abs
proc(f} begin
"1" . exprZlexl(op(f}} . "1"
endproc
WTL}.
TIen we seL LIe IuncLIon uLLrIbuLe Ior dIIIerenLIuLIon:
Abs..diff .= proc(fx} begin
f/op(f}*diff(op(f} x}
endproc.
Now we Iuve LIe IoIIowIng beIuvIor:
Abs(-Z3.4} Abs(x} Abs(x^Z + y - z}
Z3.4 1x1 1x^Z + y - z1
TIe diff uLLrIbuLe oI LIe sysLem IuncLIon obs yIeIds u sIIgILIy dIIIerenL buL
equIvuIenL resuIL:
diff(Abs(x^3} x} diff(obs(x^3} x}
3 1x^31 Z
------- 3 1x1 sign(x}
x
A-q
5olu|ions |o Eercises
Ixercise 1,.: We use exprZlexl (puge q-qq) Lo converL LIe InLegers pussed us
urgumenLs Lo sLrIngs. TIen we combIne LIem, LogeLIer wILI some sIusIes, vIu LIe
concuLenuLIon operuLor .:
dole .= proc(monlh doy yeor} begin
prinl(unquoled exprZlexl(monlh} . "/" .
exprZlexl(doy} . "/" .
exprZlexl(yeor}}
endproc.
Ixercise 1,.q: We presenL u soIuLIon usIng u Whiie Ioop. TIe condILIon x mod
Z=0 cIecks wIeLIer x Is even:
f .= proc(x} iocoi i
begin
i .= 0
userinfo(Z "lerm " . exprZlexl(i} . ". " .
exprZlexl(x}}
Whiie x <> 1 do
if x mod Z = 0 lhen x .= x/Z
eise x .= 3*x+1 endif
i .= i + 1
userinfo(Z "lerm " . exprZlexl(i} . ". " .
exprZlexl(x}}
endWhiie
i
endproc.
f(4} f(1Z34} f(5679} f(1Z345679}
2, 132, 60, 177
I we seL seluserinfo(fZ} (puge 1-q), LIen LIe userinfo commund ouLpuLs uII
Lerms oI LIe sequence unLII LIe procedure LermInuLes:
seluserinfo(f Z}. f(4}
Tnfo. lerm 0. 4
Tnfo. lerm 1. Z
Tnfo. lerm Z. 1
2
A-q
A 5olu|ions |o Eercises
I you do noL beIIeve In LIe 3 x + 1 conjecLure, you sIouId InserL u sLoppIng
condILIon Ior LIe Index i Lo ensure LermInuLIon.
Ixercise 1,.g: A recursIve ImpIemenLuLIon bused on LIe reIuLIon
gcd(a, b) = gcd(a mod b, b) Ieuds Lo un InIInILe recursIon: we Iuve
a mod b {0, 1, . . . , b 1}, und Ience
(a mod b) mod b = a mod b
In LIe nexL sLep. TIus LIe IuncLIon gcd wouId uIwuys cuII ILseII recursIveIy wILI LIe
sume urgumenLs. However, u recursIve cuII oI LIe Iorm gcd(a, b) = gcd(b, a mod b)
muke sense. SInce a mod b < b, LIe IuncLIon cuIIs ILseII recursIveIy Ior decreusIng
vuIues oI LIe second urgumenL, wIIcI IInuIIy becomes zero:
Ccd .= proc(o b} begin /* recursive vorionl */
if b = 0
lhen o
eise Ccd(b o mod b}
endif
endproc.
or Iurge vuIues oI a und b, you muy need Lo Increuse LIe vuIue oI LIe envIronmenL
vurIubIe MAX0EPT| II Ccd exIuusLs LIe vuIId recursIon depLI. TIe IoIIowIng
ILeruLIve vurIunL uvoIds LIIs probIem:
CC0 .= proc(o b}
begin
Whiie b <> 0 do
_o b] .= _b o mod b]
endWhiie
o
endproc.
TIese ImpIemenLuLIons yIeId LIe sume resuILs us LIe IuncLIons igcd und gcd
provIded by LIe sysLem:
o .= 1Z3456. b .= 10Z0.
Ccd(o b} CC0(o b} igcd(o b} gcd(o b}
20576, 20576, 20576, 20576
A-qq
5olu|ions |o Eercises
Ixercise 1,.6: n LIe IoIIowIng ImpIemenLuLIon, we generuLe u sIorLened copy
Y = [x
1
, . . . , x
n
] oI X = [x
0
, . . . , x
n
] und compuLe LIe IIsL oI dIIIerences
[x
1
x
0
, . . . , x
n
x
n1
] vIu zip und sublrocl (sublrocl(yx}=y-x). TIen we
muILIpIy eucI eIemenL oI LIIs IIsL wILI LIe correspondIng numerIcuI vuIue In LIe
IIsL [f(x
0
), f(x
1
), . . . ]. InuIIy, LIe IuncLIon pius udds uII eIemenLs oI LIe
resuILIng IIsL:
[(x
1
x
0
) f(x
0
), . . . , (x
n
x
n1
) f(x
n1
)] :
uodrolure .= proc(f X}
iocoi Y dislonces numericoivoiues producls
begin
Y .= X deiele Y_1]
dislonces .= zip(Y X sublrocl}
numericoivoiues .= mop(X fioolef}
producls .= zip(dislonces numericoivoiues muil}
pius(op(producls}}
endproc.
n LIe IoIIowIng exumpIe, we use n = 1000 equIdIsLunL sumpIe poInLs In LIe
InLervuI [0, 1]:
f .= x -> (x*exp(x}}. n .= 1000.
uodrolure(f _i/n S i = 0..n]}
0.9986412288
TIIs Is u (crude) numerIcuI upproxImuLIon oI
_
1
0
xe
x
dx (= 1).
A-qg
A 5olu|ions |o Eercises
Ixercise 1,.,: TIe specIIIcuLIon oI WeWlon requIres LIuL LIe IIrsL urgumenL f be
un expression und noL u MuPAD IuncLIon. TIus, Lo compuLe LIe derIvuLIve, we
IIrsL use indels Lo deLermIne LIe unknown In f. We subsLILuLe u numerIcuI vuIue
Ior LIe unknown Lo evuIuuLe LIe ILeruLIon IuncLIon F(x) = x f(x)/f

(x) uL u
poInL:
WeWlon .= proc(f x0 n}
iocoi vors x F sequence i
begin
vors .= indels(fiool(f}}.
if nops(vors} <> 1
lhen error(
"lhe funclion musl conloin exocliy one unknoWn"
}
eise x .= op(vors}
endif
F .= x - f/diff(fx} sequence .= x0
for i from 1 lo n do
x0 .= fiool(subs(F x = x0}}
sequence .= sequence x0
endfor
relurn(sequence}
endproc.
n LIe IoIIowIng exumpIe, WeWlon compuLes LIe IIrsL Lerms oI u sequence rupIdIy
convergIng Lo LIe soIuLIon

2:
WeWlon(x^Z - Z 1 6}
1 1.5 1.416666667 1.414Z1566 1.414Z1356Z
1.414Z1356Z 1.414Z1356Z
A-q6
5olu|ions |o Eercises
TIe IoIIowIng procedure uses WeWlon Lo pIoL LIe upproxImuLIon procedure:
piolWeWlon .=
proc(f x0 n}
iocoi x xvois xmin xmox i xi
begin
xvois .= WeWlon(f x0 n}
xmin .= min(xvois}
xmox .= mox(xvois}
_xmin xmox] .=
_xmin - (xmox - xmin}/Z xmox + (xmox - xmin}/Z]
x .= op(indels(f}}
piol(piol..FunclionZd(f x=xmin..xmox}
piol..LineZd(_xvois_i] f 1 x=xvois_i]]
_xvois_i+1] 0]} S i = 1..nops(xvois}-1
piol..LineZd(_xvois_i] 0] _xvois_i] f 1 x=xvois_i]]
LineSlyie = 0oshed} S i = 1..nops(xvois}
piol..LineZd..LineCoior = RCB..Red}
endproc.
piolWeWlon(x^Z - Z 1 3}
A-q,
A 5olu|ions |o Eercises
piolWeWlon(sin(x}+5*sin(x/3} 4 3}
Ixercise 1,.S: TIe cuII numiib..godic(..Z} yIeIds LIe bInury expunsIon oI un
InLeger us u IIsL oI bILs:
numiib..godic(7 Z} numiib..godic(16 Z}
[1, 1, 1] , [0, 0, 0, 0, 1]
nsLeud oI cuIIIng numiib..godic dIrecLIy, our soIuLIon uses u subprocedure
binory IurnIsIed wILI LIe oplion remember. TIIs ucceIeruLes LIe compuLuLIon
noLubIy sInce numiib..godic Is cuIIed IrequenLIy wILI LIe sume urgumenLs. TIe
cuII isSPoinl(_xy]} reLurns TRuE wIen LIe poInL specIIIed by LIe IIsL _xy] Is u
SIerpInskI poInL. To cIeck LIIs, LIe IuncLIon muILIpIIes LIe IIsLs wILI LIe bILs oI LIe
Lwo coordInuLes. AL LIose posILIons wIere boLI x und y Iuve u 1 bIL, muILIpIIcuLIon
yIeIds u 1. n uII oLIer cuses, 0 0, 1 0, 0 1, produce LIe resuIL 0. I LIe IIsL oI
producLs conLuIns uL IeusL one 1, LIe poInL Is u SIerpInskI poInL.
A-qS
5olu|ions |o Eercises
We use seiecl (puge q-z8) Lo exLrucL LIe SIerpInskI poInLs Irom uII poInLs
consIdered. InuIIy, we creuLe u piol..PoinlLislZd wILI LIese poInLs und cuII
piol (puge 11-1):
Sierpinski .= proc(xmox ymox}
iocoi binory isSPoinl oiiPoinls i g SPoinls
begin
binory .= proc(x} oplion remember begin
numiib..godic(x Z}
endproc
isSPoinl .= proc(Poinl} iocoi x y begin
x .= binory(Poinl_1]}
y .= binory(Poinl_Z]}
hos(zip(x y muil} 1}
endproc
oiiPoinls .= _(_i g] S i = 1..xmox} S g = 1..ymox]
SPoinls .= seiecl(oiiPoinls isSPoinl}
piol(piol..PoinlLislZd(SPoinls Coior = RCB..Biock}}
endproc.
or xmox=ymox=100, suy, you obLuIn u quILe uppeuIIng pIcLure:
Sierpinski(100 100}
A-qq
A 5olu|ions |o Eercises
Ixercise 1,.q: We presenL u recursIve soIuLIon. GIven un expressIon
formuio(x1xZ...} wILI LIe IdenLIIIers x1xZ..., we coIIecL LIe IdenLIIIers In
LIe seL x={x1xZ...] by meuns oI indels. TIen we subsLILuLe TRuE und FALSE,
respecLIveIy, Ior x1 (= op(x1}), und cuII LIe procedure recursIveIy wILI LIe
urgumenLs formuio(TRuExZx3...} und formuio(FALSExZx3...},
respecLIveIy. n LIIs wuy, we LesL uII possIbIe combInuLIons oI TRuE und FALSE Ior
LIe IdenLIIIers unLII LIe expressIon cun IInuIIy be sImpIIIIed Lo TRuE or FALSE uL LIe
boLLom oI LIe recursIon. TIIs vuIue Is reLurned Lo LIe cuIIIng procedure. I uL IeusL
one oI LIe TRuEJFALSE combInuLIons yIeIds TRuE, LIen LIe procedure reLurns TRuE,
IndIcuLIng LIuL LIe IormuIu Is suLIsIIubIe, und oLIerwIse IL reLurns FALSE.
solisfiobie .= proc(formuio} iocoi x
begin
x .= indels(formuio}
if x = {] lhen relurn(formuio} endif
relurn(solisfiobie(subs(formuio op(x 1} = TRuE}}
or solisfiobie(subs(formuio op(x 1} = FALSE}}}
endproc.
I LIe number oI IdenLIIIers In LIe InpuL IormuIu Is n, LIen LIe recursIon depLI Is
uL mosL n und LIe LoLuI number oI recursIve cuIIs oI LIe procedure Is uL mosL 2
n
.
We uppIy LIIs procedure In Lwo exumpIes:
F1 .= ((x ond y} or (y or z}} ond (nol x} ond y ond z.
FZ .= ((x ond y} or (y or z}} ond (nol y} ond (nol z}.
solisfiobie(F1} solisfiobie(nol F1}
solisfiobie(FZ} solisfiobie(nol FZ}
TRUE, TRUE, ASE, TRUE
TIe cuII simpiify(iogic} (puge q-1) sImpIIIIes IogIcuI IormuIue. ormuIu FZ
cun be sImpIIIIed Lo IuIse, no muLLer wIuL LIe vuIues oI x, y, und z ure:
simpiify(F1 iogic} simpiify(FZ iogic}
x y z, ASE
A-go
8
ocomentution und ReIerences
You cun IInd u IIsL oI uII documenLs LIuL ure uvuIIubIe In your InsLuIIuLIon by
cIoosIng Browse HeIp Irom LIe HeIp menu oI uny MuPAD

noLebook wIndow
und LIen cIIckIng on ConLenLs.
TIe MuPAD QuIck ReIerence IIsLs uII MuPAD duLu Lypes, IuncLIons, und IIbrurIes,
und provIdes u survey oI ILs IuncLIonuIILy.
You uIso IInd IInks Lo vurIous IIbrurIes sucI us, Ior exumpIe, 0om (LIe IIbrury Ior
pre-InsLuIIed duLu Lypes). TIe correspondIng documenLuLIon conLuIns u concIse
descrIpLIon oI uII domuIns provIded by 0om. n u MuPAD sessIon, LIe commund
?0om dIrecLIy opens LIIs documenL. Moreover, you cun uccess LIe descrIpLIon oI
IndIvIduuI duLu sLrucLures Irom LIIs documenL, sucI us 0om..Molrix, dIrecLIy
LIrougI LIe cuII ?0om..Molrix. AnoLIer exumpIe Is LIe documenLuLIon Ior LIe
iinoig puckuge (IIneur uIgebru). L cun be requesLed dIrecLIy vIu ?iinoig.
As un InLroducLIon Lo MuPAD, LurgeLed especIuIIy uL WIndows

users, we
recommend LIe IoIIowIng books:
|Muj o| M. MujewskI GeLLIng SLurLed wILI MuPAD. SprInger HeIdeIberg, zoo.
SBN -qo-z86-;
|Muj oq| M. MujewskI MuPAD Pro CompuLIng EssenLIuIs, Second EdILIon.
SprInger HeIdeIberg, zooq. SBN -qo-z1qq-q
n uddILIon Lo LIe MuPAD documenLuLIon, we recommend LIe IoIIowIng books
ubouL compuLer uIgebru In generuI und LIe underIyIng uIgorILIms:
|Wes qq| M. WesLer (ed.), CompuLer AIgebru SysLems. A PrucLIcuI GuIde. WIIey,
1qqq.
Documen|o|ion ond kelerences
|GGqq| J. von zur GuLIen und J. GerIurd, Modern CompuLer AIgebru.
CumbrIdge UnIversILy Press, 1qqq.
|Hec q| A. Heck, nLroducLIon Lo MupIe. SprInger, 1qq.
|DTS q| J.H. DuvenporL, E. TournIer und Y. SIreL, CompuLer AIgebru: SysLems
und AIgorILIms Ior AIgebruIc CompuLuLIon. AcudemIc Press, 1qq.
|GCqz| K.O. Geddes, S.R. Czupor und G. ubuIn, AIgorILIms Ior CompuLer
AIgebru. KIuwer, 1qqz.
B-
f
C Grophics Gollery
Gruphics Gullery
C-
Grophics Gollery
C-
C Grophics Gollery
C-q
Grophics Gollery
C-g
C Grophics Gollery
C-6
Grophics Gollery
C-,
C Grophics Gollery
C-S
Grophics Gollery
C-q
C Grophics Gollery
C-1o
Grophics Gollery
C-11
C Grophics Gollery
C-1
Grophics Gollery
C-1
C Grophics Gollery
C-1q
Grophics Gollery
C-1g
C Grophics Gollery
C-16
Grophics Gollery
C-1,
0
Comments on the Gruphics
Gullery
On LIe coIor puges oI LIIs book you IInd u guIIery oI pIcLures demonsLruLIng LIe
power oI LIe MuPAD

grupIIcs. TIese pIcLures ure dIscussed uL vurIous IocuLIons


In LIIs book und LIe onIIne piol documenLuLIon, respecLIveIy. TIere, IurLIer
deLuIIs IncIudIng LIe MuPAD communds Ior reproducIng LIe pIcLures cun be
Iound.
Iigore 1 sIows u pIoL oI severuI IuncLIons. SInguIurILIes ure IIgIIIgILed by
verLIcuI usympLoLes. See puge 11-. Iigore sIows u IuncLIon pIoL LogeLIer
wILI u spIIne InLerpoIuLIon LIrougI u seL oI sumpIe poInLs. See puge 11-q.
Iigore demonsLruLes some IuyouL possIbIIILIes. See LIe exumpIes on LIe IeIp
puge oI LIe grupIIcuI uLLrIbuLe Loyoul In LIe onIIne piol documenLuLIon.
Iigore q demonsLruLes LIe consLrucLIon oI cycIoIds vIu poInLs IIxed Lo u roIIIng
wIeeI. See puge 11-q1.
Iigore g und Iigore 6 demonsLruLe IuLcIed ureus beLween IuncLIons und wILIIn
cIosed curves, respecLIveIy. See LIe exumpIes on LIe IeIp puge oI piol..|olch.
Iigore , sIows vurIous sLuLIsLIcuI dIsLrIbuLIon IuncLIons.
Iigore S sIows un ImporLed bILmup InsIde IuncLIon pIoLs. See puge 11-11o.
Iigore q sIows some Irumes oI un unImuLIon oI LIe perLurbed orbIL oI u smuII
pIuneL kIcked ouL oI u soIur sysLem by u gIunL pIuneL uILer u neur-coIIIsIon. TIe
unImuLIon Is generuLed In SecLIon

AnImuLIonsJ

ExumpIes oI LIe onIIne piol


documenLuLIon.
Iigore 1o vIsuuIIzes LIe vecLor IIeId v(x, y) = (sIn(3 y), sIn(3 x)).
D Commen|s on |he Grophics Gollery
Iigore 11 sIows LIree soIuLIon curves oI un ODE InsIde LIe dIrecLIonuI vecLor
IIeId ussocIuLed wILI LIe ODE. See LIe exumpIes on LIe IeIp puge oI
piol..veclorFieidZd.
Iigore 1 sIows severuI roLuLed copIes oI u IuncLIon grupI. See LIe exumpIes on
LIe IeIp puge oI piol..RololeZd.
Iigore 1 sIows LIe MundeIbroL seL LogeLIer wILI Lwo bIow ups oI regIons oI
specIuI InLeresL. See LIe exumpIes on LIe IeIp puge oI piol..0ensily.
Iigore 1q sIows u bur pIoL oI sLuLIsLIcuI duLu. See LIe exumpIes on LIe IeIp puge
oI piol..BorsZd.
Iigore 1g sIows LIe Imuge oI u recLungIe In LIe compIex pIune under LIe mup
z sIn(z
2
). See LIe exumpIes on LIe IeIp puge oI piol..Conformoi.
Iigore 16 sIows some eIIIpLIc curves generuLed us u conLour pIoL. See LIe
exumpIes on LIe IeIp puge oI piol..TmpiicilZd.
Iigore 1, sIows LIe eIgenbuum dIugrum oI LIe IogIsLIc mup. See LIe exumpIes
on LIe IeIp puge oI piol..PoinlLislZd.
Iigore 1S sIows BesseI IuncLIons J

(
_
x
2
+y
2
) wILI = 0, 4, 8. See LIe
exumpIes on LIe IeIp puge oI piol..Funclion3d.
Iigore 1q sIows D IuncLIon pIoLs wILI coordInuLe grId IInes. See LIe exumpIes
on LIe IeIp puge oI LIe grupIIcuI uLLrIbuLe Cridvisibie.
Iigore o sIows KIeIn`s boLLIe (u Iumous LopoIogIcuI objecL). TIIs surIuce does
noL Iuve un orIenLuLIon; LIere Is no InsIde und no ouLsIde oI LIIs objecL. See
LIe exumpIes on LIe IeIp puge oI piol..Surfoce.
Iigore 1 modeIs vurIous snuIIs usIng piol..Surfoce (by MuIke Krumer-Jku).
Iigore demonsLruLes LIe re-consLrucLIon oI un objecL wILI roLuLIonuI
symmeLry Irom meusuremenLs oI ILs rudIus uL vurIous poInLs. See puge 11-qq.
Iigore sIows LIe soIuLIon seL oI LIe equuLIon z
2
= sIn(z x
2
y
2
) In D. See
LIe exumpIes on LIe IeIp puge oI piol..Tmpiicil3d.
Iigore q sIows LIe orenz uLLrucLor. See puge 11-116.
-
ladex
#
! . . . . . . . . . . . . . . . . . . . . . . . . . see focl
" . . . . . . . . . . . . . . . . . . . . . . . see sLrIngs
S . . . . . . . . . . . . . . . . . . . . . . . q-1, q-18
. . . . . . . . . . . . . . . . . . . z-1z, z-zz, ,-
' . . . . . . . . . . . . . . . . . . . . . . . . . . . . q-8
* . . . . . . . . . . . . . . . . . . . . . . . . see muil
+ . . . . . . . . . . . . . . . . . . . . . . . . see pius
- . . . . . . . . . . see negole und sublrocl
--> . . . . . . . . . . . . . . . . . . . . . q-1q, q-g
-> . . . . z-16, z-zz, z-z, z-z6, z-z8, z-zq,
q-1q, q-g, q-6, -8, 6-, ;-z, 8-1,
1o-q, 16-, 1;-1, 1;-6, 1;-z;, 1;-1,
A-q, A-11, A-16, A-1q, A--A-;,
A-q
. . . . . . . . . see concol und concuLenuLIon
.. . . . . . . . . . . see expressIons, runge (..)
... . . . . . . . . . . . . . . . . . . . . . . . see huii
/ . . . . . . . . . . . . . . . . . . . . . . see divide
/* ... */ . . . . . . . . . . . . . see commenLs
// . . . . . . . . . . . . . . . . . . . see commenLs
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . z-
.= . . . . . . . . . . . . . . . . . . . see ussIgnmenL
. . . . . . . . . . . . . . . . . . . . . . . . . . . . z-
< . . . . . . . . . . . . . . . . . . . . . . . . see iess
<= . . . . . . . . . . . . . . . . . . . . see ieequoi
<> . . . . . . . . . . . . . . . . . . . . see unequoi
= . . . . . . . . . . . . . . . . . . . . . . . see equoi
> . . . . . . . . . . . . . . . . . . . . . . . . see iess
>= . . . . . . . . . . . . . . . . . . . . see ieequoi
? . . . . . . . . . . . . . . . . . . . . . . . . . see heip
e . q-1, q-g, q-8, ;-z, A-1q, A-8, A-q
ee . . . . . . . . . . . . . . . . . q-1, q-g, q-8
S . . . . z-z-z-z;, z-zq, q-1;, q-q, q-z8,
q-q1, 6-;, ;-z, 1o-1-1o-q, 1q-,
1;-z, A-q, A-;, A-q-A-11,
A-1q-A-16, A-zq, A-z, A-q-A-8
x . . . . z-, z-1, z-18, z-zo, q-1;, -;, 8-z,
8-q, q-, q-1z, q-1;, 1-6, A-q, A-1,
A-16, A-1q, A-zq, A-z6, A-z8-A-o,
A-, A-6
^ . . . . . . . . . . . . . . . . . . . . . . . see poWer
ond . . . . . . . . . . . . . . . . . . . . . . see ond
ossign . . . . . . . . . . . . . . . . . . q-q, A-q
concol . . . q-16, q-1;, q-o, q-qq, A-1
concol . . . . . . . . . . . . . . . . . . . . . q-1o
divide . . . . . . . . . . . . . q-1, q-1, q-16
equoi . . . . . . . . . . . . . . q-16, 1q-z, 1q-
exprseq . . . . . . . . . . . . . . . . . q-16, q-1
fconcol . . . . . . . . . . . . . . . . . . . . . see e
fnesl . . . . . . . . . . . . . . . . . . . . . see ee
fnesl . . . . . . . . . . . . . . . . . . . . . . . q-16
for . . . . . . . . . . . . . . . . . . . . . . . . . 1-
if . . . . . . . . . . . . . . . . . . . . . . . . . . 16-
index . . . . . . . . . . . . . . . . . . . . . . q-zq
inlersecl . . . . . . . . . . . . see inlersecl
ieequoi . . . . . . . . . . . . . . . . . . . . . . q-1q
iess . . . . . . . . . . q-1q, q-16, 1q-z, A-1q
muil . . q-1, q-16, q-z1, q-, 6-6, 1q-z,
A-1o
negole . . . . . . . . . . . . . . . . . . . . . q-1
pius . q-1, q-16, q-1;, q-z1, q-zz, q-,
q-q, 6-6, 1q-z, 1;-1z, A-1o
poWer q-1, q-16, q-1;, q-z1, q-, q-1,
1q-z
seqgen . . . . . . . . . . . . q-1, q-16, q-q
sublrocl . . . . . . . . . . . q-1, q-16, A-q
unequoi . . . . . . . . . . . . . . . . . . . . . . q-1
union . . . . . . . . . . . . . . . . . . q-16, q-1;
A
ubbrevIuLIon . . . . . . . . . . . see ussIgnmenL
obs . . . . . . . . . . . . . z-1o, q-,, q-z, A-qz
uddILIon LIeorems . . . . . . . . . . . z-1q, q-
uIgebruIc sLrucLures . . . . . . . . . q-6o-q-6
oiios . . . . . . . . . . . . . . . . . . . . . . . A-zq
onomes . . . . . . . . . . . . . q-1o, q-1, A-1
ond . . . . . . . . . . . . . . . . q-16, q-18, A-1q
ond . . . q-1q, q-z, q-q,, 16-z, 1;-qz, A-q,
A-o
unImuLIons 11-8, 11-zq, 11-6, 11-;1-11-qq
exumpIes . . . . . . . . . . . . 11-qo-11-qq
Irume by Irume . . . . . . 11-8-11-8q
Inde
joIn . . . . . . . . . . . . . . . . . . . 11-q
number oI Irumes . . . . . . 11-;6-11-;8
pIuyIng . . . . . . . . . . . . . . . . . 11-,g
sImpIe . . . . . . . . . . . . 11-;1-11-;
sLurL . . . . . . . . . . . . . . . . . . . . . 11-q
syncIronIzuLIon oI . . . 11-;q-11-8
LIme runge oI . . . . . . . 11-;6-11-;8
unnuIus . . . . . . . . . . . . . . . . . . . . . . 11-q1
upproxImuLe soIuLIon . . . . . . . . . see fiool
orccos . . . . . . . . . . . . . . . . . . . . . . . z-1q
orccosh . . . . . . . . . . . . . . . . . . . . . . z-1q
orcsin . . . . . . . . . . . . . . . . . . . . . . . z-1q
orcsinh . . . . . . . . . . . . . . . . . . . . . . z-1q
orclon . . . . . . . . . . . . . . . . . . . . . . . z-1q
orclonh . . . . . . . . . . . . . . . . . . . . . . z-1q
org . . . . . . . . . . . . . . . . . . . . . . . . . z-1o
orgs . . . . . . . . . . . . . . 1;-8, 1,-1, 1;-zz
orroy . . . . . . . . . q-qq, q-q6, q-66, A-1q
urruys . . . . . . . . . . . . . . . . . . . q-qq-q-q6
0-LI operund . . . . . . . . . . . . . . q-q
deIeLIng eIemenLs . . . . . . . . . . . q-q
dImensIon . . . . . . . . . . . . . . . . q-q
generuLIon oI . . . . . . . . . . . . q-qq
muLrIx muILIpIIcuLIon . . . . . . . . 1;-11
urrow operuLor (->) . . . . . . . . . . . . . q-z
ossign . . . q-1o, 8-, A-, A-8, A-q, A-zq
ussIgnmenL . . . . . . . . . . . . . . . . z-11, q-8
deiele . . . . . . . . . . . . . . . . . . . . q-q
Indexed . . . . . . . . . . . . . . . . . . q-zq
sImuILuneous . . . . . q-q, q-z8, A-
Lo subIIsL . . . . . . . . . . . . . . . . . q-zq
ossume . ;-q, q-18, q-1S, q-1q, q-zz, q-z
ossumeAiso . . . . . . . . . . . . . . . . . . . q-18
ossuming . . . . . . . . . . . . q-18, q-o, A-q
ossumingAiso . . . . . . . . . . . . . . . . . q-18
ussumpLIons ubouL properLIes . . . . . . . .
. . . . . . . . . . . . . see ossume und is
usympLoLIc expunsIon (series) . . . . . q-8
uLoms . . . . . . . . . . . . . . . . . . . . q-, q-zo
uLLrIbuLes . . . . . . . see grupIIcs, uLLrIbuLes
B
buckLIck . . . . . . . . . . . . . . . . . . . . . . q-8
buLcI mode . . . . . . . . . . . . 11-1o8-11-1oq
BILmup . . . . . . . . . . . . . . . . . . . . . 11-1o;
booi . . . . . . . . . . . . . . . . . . . . q-q,, A-1
BooIeun expressIons . . . . . . . . q-q;-q-q8
evuIuuLIon (booi) . . . . . . . . . . . q-q;
bruncIIng (if und cose) . . . . . . 16-1-16-6
reLurn vuIue . . . . . . . . . . . 16-, 16-
C
C . . . . see C und domuIn, 0om..Compiex
CJC++ uddILIons Lo MuPAD . . . . . . . . 1-6
C . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-;
cumerus In D . . . . . . . . . . . 11-11z-11-11q
unImuLed . . . . . . . . . . . . . . . . 11-11;
cunvus . . . . . . . . . . . . . . . . . . . . . . . 11-q6
cose . . . . . . . . . . . . . . . . . . . . . . . . . 16-
cuse dIsLIncLIon . . . . . . . . . see pieceWise
ceii . . . . . . . . . . . . . . . . . . . . . . . . . q-,
cIurucLerIsLIc poIynomIuI
(iinoig..chorpoiy) . . . q-,g, A-zz
CIebysIev poIynomIuIs . . . . . . q-gg, A-16

2
-LesL (slols..csC0FT) . . . . . . . . . . 1o-
coeff . . . . . . . . . . . . . . . . . . . q-;, q-Sg
coIn Losses . . . . . . . . . . . . . . . . . . . . 1o-z
coiiecl . . . . . . . . . . . . . . . . . . . . . . q-
coIon . . . . . . . . . . . . . . . . . . . . . . . . z-
coIors . . . . . . . . . . . . . . . . . . 11-6;-11-;o
IIndIng by nume . . . . . . . . . . 11-6;
HSV . . . . . . . . . . . . . . 11-6q-11-;o
opucILy . . . . . . . . . . . . . . . . . . 11-68
RGB . . . . . . . . . . . . . . 11-6;-11-6q
RGBu . . . . . . . . . . . . . . . . . . 11-68
coIumn vecLors . . . . . . . . . . . . z-1q, q-66
combine . . . . . . . . . . . . . q-, q-1, A-z
commenLs . . . . . . . . . . . . . . . . . . . . . 1;-
compurIsons . . . . . . . . . . . . . . . . . . . q-1q
composILIon operuLor . . . . . . . . . . . . see e
composILIon operuLor (e) . . . . . . . . . q-8
compuLuLIon
exucL . . . . see symboIIc compuLuLIons
IybrId . . . . . . . . . . . . . . . . . . . . 1-q
numerIcuI . . . . . . . . . . . . . . . . . .
. . . . . . see numerIcuI compuLuLIons
Index-
Inde
symboIIc . see symboIIc compuLuLIons
compuLer uIgebru . . . . . . . . . . . . . . . . 1-
concuLenuLIon (. und concol)
oI IIsLs . . . . . . . . . . . . . . . . . . . q-o
oI muLrIces . . . . . . . . . . . . . . . . . q-;1
oI numes . . . . . . . . . . . . . . . . . q-1o
oI sLrIngs . . . . . . . . . . . . . . . . . q-qq
congugole . . . . . . . . . . . . . . . . -1o, q-;1
conloins . . . . . . . . q-o, q-;, q-8, q-qz
conlexl . . . . . . . . . . . . . . . . . . . . . 1;-z8
cycIoId . . . . . . . . . . . . . . . . . . . . . . 11-q1
D
0 . . . . . . . . . . . . . . . . . . . q-16, q-8q, ,-
duLu Lype . . . . . . . . . . . . . . . . . . . . . . 1-6
debugger . . . . . . . . . . . . . . . . . . . . . . 1-6
decompose . . . . . . . . . . . . . see operunds
degree . . . . . . . . . . . . . . . . . . . . . . q-Sg
deIuyed evuIuuLIon (hoid) . . . . . . . . . . -8
deiele . . . z-8, z-q, z-z8, -, q-q, q-1o,
q-1, q-z;, q-o, q-qo, q-q1, q-q,
q-q6, q-q, -1--;, 6-;, q-1q, q-zo,
1z-q, 1-;, 1-, 1;-11, 1;-z6, 1;-zq,
1;-o, A-11, A-z, A-z6, A-q
denom . . . . . . . . . . . . . . . . . . . . . . . . q-6
denomInuLor (denom) . . . . . . . . . . . . . q-6
derIvuLIve . . . . . . . . . . see dIIIerenLIuLIon
deLermInunL (iinoig..del) . . . . . . . . z-1q
dIugonuI muLrIces . . . . . . . . . . . . . . q-6;
dIe . . . . . . . . . . . . . . . . . . . . . . . . . . 1o-1
diff . . . z-, z-11, z-1, q-z, q-6, q-q,
q-;1, q-8o, q-8q, 6-;, ,-, q-8, q-1;,
1z--1z-, 1-, 1-6, 1q-z, 1;-1,
1;-, 1;-6, 1;-8, 1;-qo, A-18,
A-z, A-z6, A-qz
dIIIerenLIuI equuLIons (ode) . . . . . . . . 8-1z
InILIuI und boundury condILIons . . 8-1z
numerIcuI soIuLIons . . . . . . . . . . .
. . . . . . . . . . . . . . 8-1, 11-q, 11-11;
dIIIerenLIuI operuLor ( und 0) . . . . . . . .
. . . . . . . . . . . . . . . . z-1z, q-8q, ,-
dIIIerenLIuLIon (diff) . . . . . . . . . . ;-z-;-
IIgIer derIvuLIves . . . . . . . . . . . . ;-z
purLIuI derIvuLIves . . . . . . . . . . . . ;-z
sumpIe procedure . . . . . 1;-8-1;-qo
0TCTTS . . . 1-, -,, z-q, q-;, q-q;, 1-11,
1;-z, A-6, A-zo
disconl . . . . . . . . . . . . . . . . . . . . . z-zz
dIsconLInuILIes (disconl) . . . . . . . . . z-zz
dIsLrIbuLIon IuncLIon . . . . . . . . . . . . 1o-q
div . . . . . . . . . . . . . . . . . . . . . . q-6, q-1
divide . . . . . . . . . . . . . . . . . . . . . . q-S6
DodecuIedron . . . . . . . . . . . . . . . . . 11-q
domuIn
0om..ExpressionFieid . . . . . . q-6z
0om..Fiool . . . . . . . . . . . . . . . q-6o
0om..FioolTv . . . . . . . . . . . . . q-q6
0om..TmogeSel . . . . . . . . . . . . . 8-q
0om..Tnleger . . . . . . . . . . . . . q-6o
0om..TnlegerMod . . . . . . q-6o, A-zq
0om..Tnlervoi . . . . . . . . . . . . . 8-11
0om..Molrix . . . . . . . . . . . . . . q-6g
0om..Muilisel . . . . . . . 1o-, A-q
0om..Rolionoi . . . . . . . . . . . . q-6o
0om..Reoi . . . . . . . . . . . . . . . . q-6o
0om..SquoreMolrix . . . . q-6, q-6q
00MARRAY . . . . . . . . . . . . . . . . q-qq
00MB00L . . . . . . . . . . . . . . . . . q-q;
00MC0MPLEX . . . . . . . . . . . . . . . q-6
00MEXPR . . . . . . . . . . . . . . . . . . q-1z
00MFL0AT . . . . . . . . . . . . . . . . . q-6
00MFuWCEWv . . . . . . . . . . . . . 1;-z
00MT0EWT . . . . . . . . . . . . . . . . . q-8
00MTWT . . . . . . . . . . . . . . . . . . . q-6
00MTWTERvAL . . . . . . . . . . . . . . q-1
00MWuLL . . . . . . . . . . . . . . . . . q-qq
00MP0LY . . . . . . . . . . . . . . . . . q-81
00MPR0C . . . . . . . . . . . . . . . . . . 1;-
00MRAT . . . . . . . . . . . . . . . . . . . q-6
00MSET . . . . . . . . . . . . . . . . . . q-6
00MSTRTWC . . . . . . . . . . . . . . . q-qq
00MTABLE . . . . . . . . . . . . . . . . q-qo
00MvAR . . . . . . . . . . . . . . . . . . 1;-1o
pieceWise . . . . . . . . . . . . . . . . 8-1o
reclform . . . . . . . . . . . . . . . . . . q-1z
Series..Puiseux . . . . . . . . . . . q-6
Index-
Inde
soiveiib..BosicSel . . . . . . . . . 8-;
Type . . . . . . . . . . . . . . . 1q-g, 1;-zo
domuIn Lype . . . . . . . . . . . . . . . . . . . q-1
deIInIng your own . . . . . . . . . . q-z
deLermInIng LIe . . . . . see domlype
domlype . q-, q-6, q-8, q-q;, q-6, q-61,
q-6, q-qq, -q, 8-;, 8-q-8-11, q-1z,
1-q, 1q-1, 1q-z, 1q-, 16-q, 16-,
1;-, 1;-;, 1;-8, 1;-1, 1;-z, A-;,
A-8, A-qz
E
E . . . . . . . . . . . . . . . . . . . . . . . . . z-;, z-q
e . . . . . . . . . . . . . . . . . . . . . . . . . . . see E
eIgenvuIues
numerIcuI . . . . . . . . . . . . . . . . . .
. . . . . . . see numeric..eigenvoiues
symboIIc . . see iinoig..eigenvoiues
eIgenvecLors
numerIcuI . . . . . . . . . . . . . . . . . .
. . . . . . see numeric..eigenveclors
symboIIc . see iinoig..eigenveclors
eIIIpLIc InLegruIs . . . . . . . . . . . 1;-z-1;-;
envIronmenL vurIubIes . . . . . . . . . . . . z-8
0TCTTS . . . . . . . . . . . . . . . . . . . . z-;
|TST0RY . . . . . . . . . . . . . . . . . . . 1-8
LEvEL . . . . . . . . . . . . . . . . . . . . -6
MAX0EPT| . . . . . . . . . . . . . . . . . . 1;-q
MAXLEvEL . . . . . . . . . . . . . . . . . . -6
0R0ER . . . . . . . . . . . . . . . . . . . q-6
PRETTYPRTWT . . . . . . . . . . . . . . . 1z-
reInILIuIIzuLIon (resel(}) . z-8, 1-11
TEXTnT0T| . . . . . . . . . . . . . . . . . 1z-q
eps . . . . . . . . . . . . . . . . . . . . . . . . 11-1o;
equuLIons . . . . . . . . . . . . . . . . . . . . . q-1
ussIgnIng soIuLIons (ossign) . . . . 8-
dIIIerenLIuI (ode) . . . . . . . . . . . 8-1z
generuI . . . . . . . . . . . . . . . . . . 8-q
InLeger soIuLIons . . . . . . . . . . . . 8-6
IIneur . . . . . . . . . . . . . . . . . . . 8-
numerIcuI soIuLIons . . . . . . . . . . 8-;
numeric..reoirools . . . . . . . 8-;
numeric..fsoive . . . . . . . . . . 8-;
numeric..soive . . . . . . . . . . . 8-;
seurcI runge . . . . . . . . . . . . . 8-1o
purumeLrIc . . . . . . . . . . . . . . 8-1o
poIynomIuI . . . . . . . . . . . . . . . 8-z
ruLIonuI soIuLIons . . . . . . . . . . . . 8-6
reuI soIuLIons . . . . . . . . . . . . . . . 8-6
recurrence (rec) . . . . . . . . . . . 8-1
soIvIng (soive) . . . . . . . . . . 8-1-8-1
survey oI uII soIvers (?soivers) . . .
. . . . . . . . . . . . . . . . . . . . . S-1, 8-;
escope . . . . . . . . . . . . . . . . . 1;-6, 1,-1S
EucIIdeun AIgorILIm . . . . . . . . . . . . 1;-q1
evoi . . . . . . . . . . -;, g-,, 6-, 8-11, 1-;
evoiAl . . . . . . . . . . . . . . z-z, g-1, 6-z
evoip . . . . . . . . . . . . . . . . . . . . . . . q-SS
evuIuuLIon . . . . . . . . . . . . . . . . . . -1--q
compIeLe . . . . . . . . . . . . . -q--q
deIuyed (hoid) . . . . . . . . . . . . -8
enIorcIng (evoi) . . . . . . . . g-,, 6-
Lree . . . . . . . . . . . . . . . . . . . . -q
IncompIeLe . . . . . . . . . . . . . . . . . -;
Invoke . . . . . . . . . . . . . . . . . . . . z-z
IeveI (LEvEL) . . . . . . . . . . . . . . . -6
muxImuI depLI (MAXLEvEL) . . . . . -6
oI urruys . . . . . . . . . . . . . . . . . . -;
oI muLrIces . . . . . . . . . . . . . . . . . -8
oI poIynomIuIs . . . . . . . . . . . . . . -8
oI LubIes . . . . . . . . . . . . . . . . . . . -8
up Lo u purLIcuIur IeveI (ievei) . . -
wILIIn procedures . . . . . . . . . . . -8
evuIuuLor . . . . . . . . . . . . . . . . . . . . . . 1-6
exucL cuIcuIuLIons . . . . . . . . . . . . . . . . z-
exumpIes
LrunsIer Lo noLebook . . . . . . . . z-q
exp . . . . . . . . . . . . . . -,, q-;1, q-;q, 8-q
expond . . z-1q, q-;1, q-8o, -1o, 8-q, q-g,
A-1;
exponenLIuI IuncLIon (exp) . . . . . . . . . z-;
Ior muLrIces . . . . . . . q-,1, q-;6, q-;q
exponenLIuLIon (^) . . . . . . . . . . see poWer
exporLIng grupIIcs . . . . . . . 11-1o;-11-1oq
buLcI mode . . . . . . . . 11-1o8-11-1oq
InLerucLIve . . . . . . . . . . . . . . . 11-1o;
Index-q
Inde
expose . . . . . . . . . . . . . . -, -6, 1,-
Expr . . . . . . . . . . . . . . . . . . . . . . . . q-8q
expr . . . . . . . . . . . q-g,, q-;1, q-8q, q-1z
exprZlexl . . . q-go, 1z-z, 1-q, 1-z, 16-1,
A-1, A-qz
expressIons . . . . . . . . . . . . . . . q-1z-q-z
0-LI operund . . . . . . . . . . . . . . . q-z1
uLoms . . . . . . . . . . . . . . . . . . . q-zo
BooIeun . . . . . . . . . . . . q-q;-q-q8
evuIuuLIon (booi) . . . . . . . . . q-q;
compurIsons . . . . . . . . . . . . . . . q-1q
equuLIons . . . . . . . . . . . . . . . . . . q-1
expressIon Lrees . . . . . . . . q-1q-q-zo
IucLorIuI (focl) . . . . . . . . . . . . . . q-1
generuLIon vIu operuLors . . q-1z-q-1q
IndeLermInuLes (indels) . . . . . . q-8z
InequuIILIes . . . . . . . . . . . . . . . . q-1
munIpuIuLIon . . . . . . . . . . . q-1-q-z
operunds (op) . . . . . . . . . . q-z1-q-z
quoLIenL moduIo (div) . . . . . . . . q-1
runge (..) . . . . . . . . . . . . . . . . . q-1
remuInder moduIo (mod) . . . . . . . q-1
redeIInILIon . . . . . . . . . . . . . . q-1
sequence generuLor (S) . . . . . . . q-zq
sImpIIIIcuLIon . . . . . . . . . . . . . . . .
. see clso combine, normoi, rodsimp,
simpiify, und Simpiify, q-1-q-1;
LrunsIormuLIon . . . . see clso coiiecl,
combine, foclor, normoi, porlfroc,
reclform, reWrile, q--q-1z

focl . . . . . . . . . . . . -1S, q-;, q-1, q-16


foclor . . . z-1, q-;, q-88, -11, q-6, q-6,
A-zo
IucLorIuI . . . . . . . . . . . . . . . . . . . see focl
FATL . . . . . . . . . . . . . . . . q-;1, q-qq, -11
FALSE . . . . . . . . . . . . . . . . . . . . . . . q-q,
ermuL numbers . . . . . . . . . . . -o, A-q
IbonuccI numbers . . . . . . . . . . . . . . .
. . . . . -, S-1g, 1;-z-1;-z, A-z
IIeId exLensIon
(0om..AigebroicExlension) . . q-6z
IIeIds . . . . . . . . . . . . . . . . . . . . q-6o-q-6
IIIes
reudIng (reod) . . . . . . . . . . . . 1z-
reudIng duLu (imporl..reoddolo) .
. . . . . . . . . . . . . . . . . . . . . . . . 1z-6
wrILIng (Wrile) . . . . . . . . . . . . 1z-
fiool 1-z, -,, z-q, z-1, q-;, q-1;, q-qz,
q-q6, q-;1, ;-, 8-z, 8-;, 8-1o, 1o-z,
1-, 1;-z, 1;-1, 1;-, A-6, A-1q,
A-z8, A-o, A--A-;
IIouLIng poInL . see numerIcuI compuLuLIons
IIouLIng-poInL urruys . . . . . . . . q-qz-q-q
IIouLIng-poInL InLervuIs . . . . . . . q-qq-q-q8
fioor . . . . . . . . . . . . . . . . . . . . q-,, A-6
IonLs . . . . . . . . . . . . . . . . . 11-1oq-11-1o6
for . . . . . . . . . . . . . . . . . q-z, 1g-1, A-q
IormuIu munIpuIuLIon . . . . . . . . . . . . . 1-
ourIer expunsIon . . . . . . . . . . . . . . . q-16
froc . . . . . . . . . . . . . . . . . . . . . . . . . q-;
frondom . . . . . . . . . . . . . . . . . . . . . 1o-z
IrequencIes (0om..Muilisel) . 1o-, A-q
funcenv . . . . . . . . . . . . . . . . 1,-q, A-qz
IuncLIon envIronmenLs . . . . . . 1;-1-1;-;
IuncLIon uLLrIbuLes . . . . . . . . . . 1;-
generuLIon . . . . . . . . . . . see funcenv
operunds . . . . . . . . . . . . . . . . . 1;-z
source code (expose) . . . . . . . . . -6
IuncLIons . . . . . . . . . . . . . q-1q, q-z-q-
us procedures . . . . . . . . . . 1;-1-1;-qz
composILIon . . . . . . . . . . . . . . . see e
consLunL . . . . . . . . . . . . . . . . q-q
converLIng expressIons Lo (-->) .
. . . . . . . . . . . . . . . . . . . . . . . . q-
exLremu . . . . . . . . . . . . . . . . . . z-zz
IuncLIonuI expressIons . . . . . . . q-q
generuLIon (-->) . . . . . . . . . . . . q-z
generuLIon (->) . . . . . . . . . . . . q-z
IdenLILy IuncLIon (id) . . . . . . . . q-6z
ILeruLed composILIon . . . . . . . . see ee
ILeruLed composILIon (ee) . . . . . q-g
kerneI . . . . . . . . . . . . . . . . . . 1-6
numbers us . . . . . . . . . . . . . . q-q
rooLs . . . . . . . . . . . . . . . . . . . . z-zz
Index-g
Inde
G
gcd . . . . . . . . . . . . . . . . . . . . q-Sq, A-qq
generuI pIoL prIncIpIes . . . . . . 11--11-8
generole . . . . . . . . . . . . . . . . . . . . . . 1-
genidenl . . . . . . . . . . . . . . . . q-11, 1;-o
geomeLrIc serIes . . . . . . . . . . . . . . . . q-6
gelprop . . . . . . . . . . . . q-o, q-z1, q-z
gIobuI vurIubIes . . . . . . . . . . . . . . . . . 1;-q
GoIdbucI conjecLure . . . . . . . . . . . . z-z6
grupIIcuI Lrees . . . . . . . . . . . . 11-q6-11-qq
grupIIcs . . . . . . . . . . . . . . . . 11-1-11-1zo
unImuLIons . . . . . . . . . see unImuLIons
uLLrIbuLes . . . . . . . . . . . . 11-;-11-66
AdopliveMesh . . . 11-11, 11-1, 11-z6
Axes . . . . . . . . 11-11, 11-z6, 11-6z
AxesTilieFonl . . . . . . . . . . 11-1oq
AxesTilies . . . . . . . . 11-11, 11-z6
Axesvisibie . . . . . . . 11-11, 11-z6
Bordernidlh . . . . . . . . . . . . 11-q6
Comero0ireclion . . . . . . . . 11-11z
cIunge In exIsLIng objecLs . 11-
Coior . . . . . . . . . . . . . 11-, 11-6;
Coiors . . . 11-;, 11-11, 11-z, 11-z6
CoordinoleType . . . . . . . . . . 11-11
deIuuIL vuIues . . . . . . . 11-;-11-8
FiiiCoior . . . . . . . . . . . . . . 11-6;
FiiiCoiorFunclion . . . . . . . 11-;q
FiiiCoiorType . . . . . . . . . . . 11-z6
Fiiied . . . . . . . . . . . . . . . . . 11-61
Fooler . 11-1o, 11-z, 11-;q, 11-1o
FoolerFonl . . . . . . 11-1oq, 11-1o
Fromes . . . . . . . . . . . . . . . . . . .
. . . . 11-1o, 11-11, 11-z, 11-z6, 11-;6
IuIIy quuIIIIed . . . . . . . . . . 11-6o
Cridvisibie . . . . . . . . . . . . . .
. . . . . . . . . 11-11, 11-1q, 11-z, 11-zq
|eoder . . 11-1o, 11-1q, 11-z, 11-zq,
11-;q, 11-1o
|eoderFonl . . . . . . 11-1oq, 11-1o
|eighl . . . . . . . 11-1o, 11-z, 11-q6
IeIp puges Ior . . . . . 11-6-11-66
IInLs . . . . . . . . . . . . . 11-6z-11-6q
InIerILunce oI . . . . . 11-8-11-6z
Loyoul . . . . . . . . . . . . . . . . 11-11o
Legend . . . . . . . . . . 11-1oz, 11-1o
LegendAiignmenl . . . . . . . . 11-1o
LegendEnlry . . . . . 11-1oz, 11-1o
LegendFonl . . . . . . 11-1o, 11-1oq
LegendPiocemenl . . . . . . . . 11-1o
LegendTexl . . . . . . 11-1oz, 11-1o
Legendvisibie . . . . . . . . . . . . .
. . . . . . . 11-11, 11-z6, 11-1oz, 11-1o
LineCoior . . . . . . . . . . . . . . 11-6;
LineCoiorFunclion . . . . . . . 11-;q
LineCoiorType . . . . . . . . . . . 11-11
Linesvisibie . . . . . . . 11-;, 11-61
Mesh . . . . . . . . . 11-11, 11-1, 11-z6
Wome . . . . . . . . . . . . . . . . . 11-1o
PoinlCoior . . . . . . . . . . . . . 11-6;
Scoiing . . . . . . 11-11, 11-z6, 11-11o
speIIIng . . . . . . . . . . . . . . . . 11-;
Subgridvisibie . . . . . . . . . . . .
. . . . . . . . . 11-11, 11-1q, 11-z6, 11-zq
Submesh . . . . . . . . . . . 11-z6, 11-z8
TexlFonl . . . . . . . . . . . . . . 11-1oq
TicksLobeiFonl . . . . . . . . . 11-1oq
TicksWumber . . . . . . . 11-11, 11-z6
TimeBegin . . . . . . . . . 11-;;, 11-;q
TimeEnd . . . . . . . . . . . 11-;;, 11-;q
TimeRonge . . . . . . . . . 11-;;, 11-;q
Tilie . . . . . . . . 11-1o, 11-z, 11-;q
TilieFonl . . . . . . . . . . . . . 11-1oq
TiliePosilion . . . . . . 11-1o, 11-z
Lype specIIIc . . . . . . . . . . . 11-6o
vieWingBoxYRonge . . . . 11-11, 11-16
vieWingBoxZRonge . . . 11-z6, 11-z
visibieAfler . . . . . . . . . . . . 11-8
visibieAflerEnd . . . . . . . . . 11-81
visibieBefore . . . . . . . . . . . 11-8
visibieBeforeBegin . . . . . . 11-81
visibieFromTo . . . . . . . . . . . 11-8
nidlh . . . . . . . . 11-1o, 11-z, 11-q6
XTicksBelWeen . . . . . . . . . . . 11-1q
XTicks0islonce . . . . . . . . . . 11-1q
YTicksBelWeen . . . . . . . . . . . 11-1q
YTicks0islonce . . . . . . . . . . 11-1q
Index-6
Inde
buLcI mode . . . . . . . . 11-1o8-11-1oq
cumerus In D . . . . . . . 11-11z-11-11q
unImuLed . . . . . . . . . . . . . . 11-11;
cunvus . . . . . . . . . . . . . . . . . . . 11-q6
cupLIon . . . . . . . . . . . . . . . . . . . .
. . . . see grupIIcs, uLLrIbuLes, Fooler
coIors . . . . . . . . . . . . . . . . see coIors
evuIuuLIon mesI . . . . . . see grupIIcs,
uLLrIbuLes, Mesh und Submesh
evuIuuLIon mesI, udupLIve . . . . . . .
. . . . . . . . . . see grupIIcs, uLLrIbuLes,
AdopliveMesh
IonLs . . . . . . . . . . . . . 11-1oq-11-1o6
IooLer . . . . . . . . . . . . . . . . . . . . .
. . . . see grupIIcs, uLLrIbuLes, Fooler
generuI pIoL prIncIpIes . . 11--11-8
grupIIcuI Lrees . . . . . . . . 11-q6-11-qq
ImpIIcIL . . . . . . . . . . . . . . . 11-qq
grupIs oI IuncLIons (piol) . z-16, 11-z
gups In deIInILIon . . . . . 11-, 11-z1
pIecewIse deIIned IuncLIons . . . .
. . . . . . . . . . . . . . . . . . . 11-, 11-z1
sInguIurILIes . . . . . . . . 11-1, 11-o
grId IInes . . . see grupIIcs, uLLrIbuLes,
Cridvisibie und Subgridvisibie
groups oI prImILIves . . . . . . . . . . .
. . . . . . . . . . . . . 11-6, 11-q-11-q6
Ieuder . . . . . . . . . . . . . . . . . . . . .
. . . . see grupIIcs, uLLrIbuLes, |eoder
HSV coIors . . . . . . . . . . . 11-6q-11-;o
Imuge sIze . . see grupIIcs, uLLrIbuLes,
|eighl und nidlh
ImporLIng pIcLures . . . . 11-11o-11-111
Iegends . . . . . . . . . . . 11-1oo-11-1o
IIgIL sources . . . . . . . . . . . . . . 11-6
IogurILImIc pIoLs . . . . . . . . . . . 11-11
objecL browser . . . . . . . . 11-o-11-
OpenG
drIvers . . . . . . . . . . . . . . . . 11-1zo
PIuLo`s poIyIedru . . . . . . . . . . . 11-q
pIuyIng unImuLIons . . . . . . . . . . 11-,g
prImILIves 11-q-11-6, see clso piol
(grupIIcs IIbrury)
properLy InspecLor . . . . . 11-o-11-
RGB coIors . . . . . . . . . . 11-6;-11-6q
suvIng und exporLIng . 11-1o;-11-1oq
buLcI mode . . . . . . 11-1o8-11-1oq
InLerucLIve . . . . . . . . . . . . . 11-1o;
SIerpInskI LrIungIe . . . . . 1,-q, A-q8
sIze oI Imuge see grupIIcs, uLLrIbuLes,
|eighl und nidlh
LILIe (per objecL) . . . . . . . . . . . . . .
. . . . . see grupIIcs, uLLrIbuLes, Tilie
LILIe posILIon see grupIIcs, uLLrIbuLes,
TiliePosilion
LrunsIormuLIon . . . . . . . . 11-q;-11-qq
LrunsIormuLIons . . . . . . . . . . . . 11-6
grupIs oI IuncLIons (piol) . . . . . . . . . 11-z
greuLesL common dIvIsor see gcd und igcd
Grbner buses . . . . . . . . . . . . . see IIbrury
groups oI prImILIves . . . . . . . . 11-q-11-q6
H
Iurdwure IIouL urruys . . . . . . . . q-qz-q-q
hos . . . . . . . . . . . q-, q-1;, 1;-q, A-q
IeIp . . . . . . . . . . . . . . . . . . . . . . z-q, B-1
heip . . . . . . . . . . . . . . . . . . . . . -q, -z
HexuIedron . . . . . . . . . . . . . . . . . . 11-q
HIIberL muLrIx (iinoig..hiiberl) . . . .
. . . . . . . . . . q-q6, q-q6, q-;z, q-q;
Inverse (iinoig..invhiiberl) .
. . . . . . . . . . . . . . . . . . . . . . . . q-q8
IInL . . . . . . see grupIIcs, uLLrIbuLes, IInLs
|TST0RY . . . . . . . . . . . . . . . . . . . . . . 1-8
IIsLory (x und iosl) . . . . . . . . . 1-6-1-8
evuIuuLIon oI iosl . . . . . . . . . . . 1-;
hoid . . . -8, g-S, -q, 6-, ;-, 8-;, 8-1o,
q-1;, 1z-6, 1;-;, 1;-z8, 1;-q, A-z6,
A-q
de I`HospILuI . . . . . . . . . . . . . . . . . . . ;-
huii . . . . . . . . . . . . . . . q-1, q-qq, q-q6
IyperLexL . . . . . . . . . . . . . . . . . . . . . z-q
Index-,
Inde

T . . . . . . . . . . . . . . . . . . . . . . . . . . . . z-q
cosuIedron . . . . . . . . . . . . . . . . . . 11-q
id . . . . . . . . . . . . . . . . . . . . . . . . . . q-6z
IdenLIIIers . . . . . . . . . . . . . z-11, q-8-q-11
ussIgnmenL . . . . . . . . . . . . q-8-q-1o
ussumpLIons . . . . see ossume und is
concuLenuLIon . . . . . . . . . . . . . q-1o
deIeLIng LIe vuIue . . . . . . . . . . . . q-q
dynumIcuI generuLIon . . . . . . . . q-1o
evuIuuLIon . . . . . . . . . . . . . . . . . . -1
generuLIon vIu sLrIngs . . . . . . . . . q-11
greek IeLLers . . . . . . . . . . . . . . . . q-8
IIsL (onomes) . . . . . . . . . . . . . . . q-1o
specIuI cIurucLers . . . . . . . . . . . . q-8
sub- und superscrIpLed . . . . . . q-8
vuIues . . . . . . . . . . . . . . . . . . . . . -1
wILI urbILrury cIurucLers . . . . . . . q-8
wrILe proLecLIon
removIng (unprolecl) . . . . q-1o
seLLIng (prolecl) . . . . . . . q-1o
if . q-q8, q-z, -8, 1-q, 16-1, 16-, 16-6,
1;--1;-, 1;-;, 1;-8, 1;-1z,
1;-zo-1;-zq, 1;-z, 1;-, 1;-q,
A-16, A-qo, A-qz, A-qq, A-q6, A-o
ifoclor . . . . . . . . . z-6, z-zq, -S, q-;
igcd . . . . . . . . . . . . . . 1o-q, 1;-q1, A-qq
TgnoreSpecioiCoses . . . . . . . . . . . . . z-1;
Tm . . . . . . . . . . . . . . . . . . . . . . . z-1o, q-6
ImugInury purL . . . . . . . . . . . . . . . . see Tm
ImugInury unIL . . . . . . . . . . . . . . . . . . z-q
imporl..reodbilmop . . . . . . . . . . . 11-11o
imporl..reoddolo . . . . . . . . . 1-,, 1-1z
ImporLIng pIcLures . . . . . . . . 11-11o-11-111
in . . . . . . . . . . . . . . . . . . . . . . . q-q8, 8-q
IndeLermInuLes . . . . . . . . . . see IdenLIIIers
IndeLermInuLes (indels) . . . . . . . . . q-8z
indels . . . . . . . . . q-S, 8-6, A-z8, A-q6
Indexed uccess . . . . . . . . . . . . . . . . . q-zq
InequuIILIes . . . . . . . . . . . . . . . . . . . . q-1
soIvIng . . . . . . . . . . . . . . . . . . 8-11
infinily . . . . -,, z-zz, z-z, q-8, -1o,
-11, A-18
rounded (R0TWF, R0WTWF) . . q-q
info . . . . . . . . . . . . -z, q-;q, 11-6;, 1q-q
InpuL und ouLpuL . . . . . . . . . . . . 1z-1-1z-;
inl z-, z-1z, z-1, q-1, q-z1, q-, q-;1,
q-8q, ,-q, ;-, q-16, 1-z, 1-6, 1-;,
1;-;, 1;-o, 1;-;, A-z8, A-, A-;
InLegruLIon . . . . . . . . . . . . . . . . . see inl
cIunge oI vurIubIe . . . . . . . . . . . .
. . . . . . . . . . see inliib..chongevor
numerIcuI . . . . . . . . . . . . . . . . .
. . . . . . . . see numerIcuI InLegruLIon
InLermedIuLe resuIL . . . . . . . . . . . . . . z-
InLerpoIuLIon . . . . . . . . . . . . . . . . . . 11-q
inlersecl . . . . . . . . . . . . . . . . q-16, A-1
inlersecl . . . . . . . . . . . q-,, q-q, q-q6
InLervuI urILImeLIc . . . . . . . . . . q-qq-q-q8
union, inlersecl . . . . . . . . . . . q-q6
converL Lo InLervuIs (inlervoi) . q-q6
Iuude domuIn (0om..FioolTv) . q-q6
generuLe InLervuIs (..., huii) . . . .
. . . . . . . . . . . . . . . . . . . q-1, q-qq
inliib..chongevor . . . . . . . . . ,-6, A-z8
TnlMod . . . . . . . . . . . . . . . . . . . . . . q-8
irreducibie . . . . . . . . . . . . . q-qo, A-zq
is . . . . . . . . . . . . . . . . . . . . . . . 8-q, q-1q
isprime -6, z-zq, z-z6, z-z;, q-;, q-q8,
16-1, 16-z, A-q, A-11
iszero . . . . q-6z, q-6, q-68, q-6q, q-;1
ILeruLIon operuLor . . . . . . . . . . . . . see ee
ILeruLIon operuLor (ee) . . . . . . . q-g, q-8
ilhprime . . . . . . . . . . . . . -q, 1z-1, 1z-z
J
JuvuVIew . . . . . . . . . . . . . . . . . . . 11-1o;
jpg . . . . . . . . . . . . . . . . . . . . . . . . 11-1o;
K
kerneI . . . . . . . . . . . . . . . . . . . . . . . . 1-6
exLendIng LIe . . . . . . . . . . . . . 1-6
kerneI IuncLIon . . . . . . . . . . . . . . . . . 1-6
Index-S
Inde

unduu symboI (0) . . . . . . . . . q-g6, A-18


iosl . . . . . . . . . . . . . . . . . . . . . . . . see x
iosl
evuIuuLIon oI . . . . . . . . . . . . . . 1-;
iosl . . . . . . . . . . . . . . . . -;, 1-6, A-16
uurenL serIes . . . . . . . . . . . . . . . . . q-8
Iegends . . . . . . . . . . . . . . . 11-1oo-11-1o
ienglh . . . . . . . . . . . . . q-g1, A-1, A-q
LEvEL . . . . . . . . . . . . . . . . . . . . . . . . g-6
ievei . . . . . . . . . . . . . . g-g, 1;-o, A-z6
IIbrury . . . . . . . . . . . . . . . . . . . . . -1--6
exporLIng u (use) . . . . . . . . . . -q
Ior coIor numes (RCB) . . . . . . . . 11-6;
Ior duLu sLrucLures (0om) . . . . . . q-6o
Ior exLernuI IormuLs (generole) . . 1-
Ior Grbner buses (groebner) . . q-qo
Ior InpuL (imporl) . . . . . . . . . . . 1z-6
Ior IIneur uIgebru (iinoig) . . . . q-;q
Ior number LIeory (numiib) . . . . .
. . . . . . . . . . . . . . . . . . . . z-zq, -
Ior numerIcuI uIgorILIms (numeric)
. . . . . . . . . . . . . . . . . . . . -q, q-;q
Ior orLIogonuI poIynomIuIs
(orlhpoiy) . . . . . . . . . . . . . . . A-1;
Ior sLuLIsLIcs (slols) . . . . . . . . . 1o-z
Ior sLrIngs (slringiib) . . . . . . . q-o
Ior Lype specIIIers (Type) . . . . . . . .
. . . . . . . . . . . . . . 1q-q, 1;-zo, A-qo
InIormuLIon on u (? und info) . -z
sLundurd . . . . . . . . . . . . . . . . . -6
iimil . -,, z-16, z-zz, z-z, q-1oo, A-q
one-sIded . . . . . . . . . . . . . . . . . z-zz
IImIL compuLuLIon (iimil) . . . . . . . . -16
iinoig (IIbrury Ior IIneur uIgebru)
..chorpoiy . . . . . . . . . q-,g, A-zz
..del . . . . . . . . . . . . . . z-1q, A-zo
..eigenvoiues . . q-,g, q-;;, A-zz
..eigenveclors . . . . . . . . . . A-z
..invhiiberl . . . . . . . . . . . . q-q8
..isPos0ef . . . . . . . . . . . . . . q-zz
IIneur uIgebru (iinoig) . . . . . . . . . . . q-;q
IIneIeed . . . . . . . . . . . . . . . . . . . . . . . z-z
IIsLs . . . . . . . . . . . . . . . . . . . . . q-z8-q-
uppIyIng u IuncLIon (mop) . . . . . . q-1
combInIng (zip) . . . . . . . . . . q-
empLy IIsL . . . . . . . . . . . . . . . . . q-z8
seIecLIng uccordIng Lo properLIes
(seiecl) . . . . . . . . . . . . . . . . . q-z
spIILLIng uccordIng Lo properLIes
(spiil) . . . . . . . . . . . . . . . . . . q-z
in . . . . . . . . . . . . . . . . . . . . . . . . . . . z-;
iocoi . . . . . . . . . . . . . . . . . . . . . . . . 1;-q
IocuI vurIubIes (iocoi) . . . . . . . 1;-q-1;-1
IormuI purumeLers . . . . . . . . . . 1;-z;
unInILIuIIzed . . . . . . . . . . . . . 1;-11
iog . . . . . . . . . . . . . . . . . . . . . . . . . q-q;
IogurILIm (in, iog) . . . . . . . . . . z-;, q-q;
IogIcuI IormuIu . . . . . . . . . . . . . . . . 1;-qz
Iong urrow operuLor (-->) . . . . . . . . . q-z
Ioops . . . . . . . . . . . . . . . . . . . . . 1-1-1-
uborLIng (breok) . . . . . . . . . . . 1-q
for . . . . . . . . . . . . . . . . . . . . . . 1-1
repeol . . . . . . . . . . . . . . . . . . . . 1-
reLurn vuIue . . . . . . . . . . . . . . . . 1-
skIppIng communds (nexl) . . . . . 1-q
Whiie . . . . . . . . . . . . . . . . . . . . 1-
orenz uLLrucLor . . . . . . . . . . . . . . . 11-116
M
munIpuIuLIng expressIons . . . . . . q-1-q-z
mop . . . z-zo, q-1,, q-1, q-q, q-8, q-qz,
q-q6, q-;1, -;, 8-q, 8-q, 8-11,
1;-qo, A-q, A-1o, A-1, A-1, A-z8,
A-q, A-;, A-8, A-q
mopcoeffs . . . . . . . . . . . . . . . . . . . . q-S,
mups . . . . . . . . . . . . . . . . . . see IuncLIons
muLIemuLIcuI objecLs . . . . . . . . . . . . . . 1-
muLrIces . . . . . . . . . . . . . . . . . q-6q-q-8o
cIurucLerIsLIc poIynomIuI
(iinoig..chorpoiy) . . . q-,g, A-zz
compuLIng wILI . . . . . . q-;o-q-;z
deIuuIL coeIIIcIenL rIng
(0om..ExpressionFieid) . . . . . q-68
deLermInunL (iinoig..del) . . . . z-1q
dIugonuI . . . . . . . . . . . . . . . . q-6;
Index-q
Inde
eIgenvuIues
numerIcuI . . . . . . . . . . . . . . . .
. . . . . . . see numeric..eigenvoiues
symboIIc . . . . . . . . . . . . . . . . .
. . . . . . . . see iinoig..eigenvoiues
eIgenvecLors
numerIcuI . . . . . . . . . . . . . . . .
. . . . . . see numeric..eigenveclors
symboIIc . . . . . . . . . . . . . . . . .
. . . . . . . see iinoig..eigenveclors
exponenLIuI IuncLIon (exp) q-,1, q-;q
exponenLIuI IuncLIon
(numeric..expMolrix) . . . . . . . q-;6
IuncLIonuI cuIcuIus
(numeric..fMolrix) . . . . . . . . q-;6
HIIberL muLrIx (iinoig..hiiberl)
. . . . . . . . . . . . . . . q-q6, q-;z, q-q;
IdenLILy . . . . . . . . . . . . . . . . q-68
Indexed uccess . . . . . . . . . . . . . q-6;
InILIuIIzuLIon . . . . . . . . . . q-6q-q-6q
Inverse . . . . . . . . . . . . . . z-1q, q-,o
Inverse HIIberL muLrIx
(iinoig..invhiiberl) . . . . . . . q-q8
IIbrury Ior IIneur uIgebru (iinoig) .
. . . . . . . . . . . . . . . . . . . . . . . . q-;q
IIbrury Ior numerIcuI uIgorILIms
(numeric) . . . . . . . . . . . . . . . . q-;q
meLIods . . . . . . . . . . . . . q-;z-q-;
rIng oI squure . . . . . . . . . . . . q-6q
spurse . . . . . . . . . . . . . q-;;-q-;8
submuLrIces . . . . . . . . . . . . . . . q-6;
ToepIILz . . . . . . . . . . . . . . . . q-;8
molrix . . . . z-1q, q-6q, q-6q, q-;;, q-;8,
q-zz, A-1q, A-zo
mox . . . . . . . . . . . . . . . . q-,, 1;-;, 1;-z1
Mox0egree . . . . . . . . . . . . . . . . . . . . . 8-
MAX0EPT| . . . . . . . . . . . . . . . . . 1,-q, A-qq
MAXLEvEL . . . . . . . . . . . . . . . . . . . . . . g-6
meun vuIue (slols..meon) . . . . . . . . 1o-z
memory munugemenL . . . . . . . . . . . . 1-6
Mersenne prImes . . . . . . . . . . . -o, A-q
min . . . . . . . . . . . . . . . . . . . . . . . . . q-z;
minus . . . . . . . . . . . . . . . . . . . . . . . q-;
mod . . . . q-6, q-1, q-18, q-6o, q-61, q-8,
1;-q1, A-11, A-qq
redeIIne . . . . . . . . . . . . . . . . . q-1
modp . . . . . . . . . . . . . . . . . . . . . . . . . q-1
mods . . . . . . . . . . . . . . . . . . . . . . . . . q-1
moduIur exponenLIuLIon (poWermod) . . q-61
moduIe . . . . . . . . . . . . . . . . . . . . . . . 1-6
MoebIus sLrIp . . . . . . . . . . . . . . . . . 11-qz
MonLe-CurIo sImuIuLIon . . . . . . . . . . 1o-6
muilcoeffs . . . . . . . . . . . . . . . . . . . q-S,
muILIseL . . . . . . . . . . . . . . . . . . . . . 1o-
N
NewLon ILeruLIon . . . . . . . . . . 1,-q, A-q6
numeric..fsoive . . . . . . . . . . . . -q
nexlprime . . . . . . . . . . . . . . . . z-zq-z-z6
WTL . . . . . . . . q-qq, 1-z, 1-q, 1;-, A-qz
nops . . z-z-z-z;, z-zq, q-, q-z1, q-zz,
q-6, A-11, A-1z, A-, A-6, A-q6
norm . . . . . . . . . . . . . . . . . . . . . . . . q-;z
normoi . z-1q, z-zo, q-6, q-6q, q-,, q-1,
1-, A-, A-;, A-8
normuI dIsLrIbuLIon (slols..normoiC0F)
. . . . . . . . . . . . . . . . . . . . . . . . 1o-
nol . . z-z6, q-1q, q-z, q-q,, 16-z, 1;-qz,
A-q, A-o
noLebook . . . . . . . . . . . . . . . . . . 1-, 1z-
nlerms . . . . . . . . . . . . . . . . . . . . . . q-8q
nlhcoeff . . . . . . . . . . . . . . . . . . . . . q-8q
nlhlerm . . . . . . . . . . . . . . . . . . . . . q-8q
nuii . . . . . . . . . . . . . . . . . . . . . . . . . 16-
nuII objecLs . . . . . . . . . . . . . . q-qq-q-1oo
nuii(} . . . . . . . . . . . . . . . . . q-z6, q-qq
number LIeory (numiib) . . . . . . . z-zq, -
numbers . . . . . . . . . . . . . . . . . . . q-6-q-;
ubsoIuLe vuIue . . . . . . . . . . . see obs
busIc urILImeLIc . . . . . . . . . . . . . q-;
compIex . . . z-q, see clso domuIns,
00MC0MPLEX
compIex conjuguLIon . see congugole
compuLIng wILI . . . . . . . . z--z-6
decImuI expunsIon
(numiib..decimoi) . . . . . . . . . . -z
Index-1o
Inde
denomInuLor . . . . . . . . . . . see denom
domuIn Lypes . . . . . . . . . . . . . . . q-6
even InLegers (Type..Even) . . . . . 1q-
IucLorIuI . . . . . . . . . . . . . . . . see focl
IIouLIng poInL upproxImuLIon . . . . .
. . . . . . . . . . . . . . . . . . . . see fiool
IrucLIonuI purL . . . . . . . . . . . see froc
greuLesL common dIvIsor . . . . see igcd
I-LI prIme (ilhprime) . . . . . . . . z-zq
ImugInury purL . . . . . . . . . . . . see Tm
InLegers . . . . . . see domuIns, 00MTWT
InLegruI purL . . . . . . . . . . . . see lrunc
i-LI prIme . . . . . . . . . . see ilhprime
moduIur exponenLIuLIon (poWermod)
. . . . . . . . . . . . . . . . . . . . . . . . q-61
nexL prIme . . . . . . . . . see nexlprime
numeruLor . . . . . . . . . . . . . see numer
odd InLegers (Type..0dd) . . . . . . 1q-
operunds . . . . . . . . . . . . . . . . . . q-6
ouLpuL IormuL oI IIouLIng-poInL
numbers (Pref..fioolFormol) . 1-
prImuIILy LesL . . . . . . . . . see isprime
prIme IucLorIzuLIon . . . . . see ifoclor
quoLIenL moduIo (div) . . . . . . . . q-6
rundom . . see rondom und frondom
ruLIonuI . . . . see domuIns, 00MRAT
reuI und ImugInury purL see reclform
reuI purL . . . . . . . . . . . . . . . . . see Re
remuInder moduIo . . . . . . . . see mod
roundIng . . . . . . . . . . . . . . . . . . .
. . . . . see ceii, fioor, round, lrunc
sIgn . . . . . . . . . . . . . . . . . . . see sign
sImpIIIIcuLIon oI rudIcuIs (rodsimp)
. . . . . . . . . . . . . . . . . . . z-1, q-1q
squure rooL . . . . . . . . . . . . . see sqrl
Lype specIIIer . . . . . . . . . . . . . . . 1q-
numer . . . . . . . . . . . . . . . . . . . . . . . . q-6
numeruLor (numer) . . . . . . . . . . . . . . . q-6
numeric (numerIcs IIbrury)
..del . . . . . . . . . . . . . . . . . . q-;6
..eigenvoiues . . . . . . . . . . . . .
. . . . . . . . . . . -, q-;6, 11-q, 11-zo
..eigenveclors . . . . . . . . . . q-;6
..expMolrix . . . . . . . . . . . . . q-;6
..fMolrix . . . . . . . . . . . . . . . q-;6
..fsoive . . . . . . . . . . . . . . -q, S-,
..inl . . . . . . . . . . . -8, ;-, A-z8
..inverse . . . . . . . . . . . . . . . q-;6
..odesoive . . . . . . . . . . . . . . . 8-1
..quodrolure . . . . . . . . . . . . . -q
..reoirools . . . . . . -q, S-,, 8-1o
..singuiorvoiues . . . . . . . . . q-;6
..singuiorveclors . . . . . . . . q-;6
..soive . . . . . . . . . . . . . . . . . 8-;
numerIcuI compuLuLIons . . . . . . . . . . . .
. . . . . . . . . 1-z, -,, z-8, -q, q-;q
precIsIon . . . . . . . . . . . . . see 0TCTTS
numerIcuI InLegruLIon . . . . -q, ,-g, A-z8
numerIcuI InLegruLIon (numeric..inl und
numeric..quodrolure) . . . . . 1;-q1
numiib (IIbrury Ior number LIeory)
..decimoi . . . . . . . . . . . . . . . . -z
..fibonocci . . . . . . . . . . . . . 1;-z
..primedivisors . . . . . . . . . z-zq
..proveprime . . . . . . . . . . . . z-zq
O
0 . . . . . . . . . . . . . . . . . . . . . . q-g6, A-18
objecL browser . . . . . . . . . . . . 11-o-11-
objecL-orIenLed . . . . . . . . . . . . . . . . . 1-6
OcLuIedron . . . . . . . . . . . . . . . . . . . 11-q
ode . . . . . . . . . . . . . . . . . . . . S-1, A-zq
op . . q-, q-q-q-6, q-z1-q-z, q-z6, q-zq,
q-6, q-q1, q-q, q-;, q-8q, q-86,
q-8;, q-q8, 6--6-6, 8-, 8-q, 1o-q,
1;-1z, 1;-, 1;-q, A-, A-8-A-1o,
A-1z-A-1, A-zq, A-q, A-qz, A-q,
A-q6, A-o
OpenG . . . . . . . . . . . . . . . . . . . . 11-1zo
drIvers . . . . . . . . . . . . . . . . . . 11-1zo
operunds . . . . . . . . . . . . . . . q--q-, 6-1
0-LI operund . . . . . . . . . . . q-z1, 6-6
uccessIng . . . . . . . . . . . . . . see op
number oI . . . . . . . . . . . . see nops
oI serIes expunsIons . . . . . . . . . q-;
operuLors . . . . . . . . . . . . . . . . q-1z-q-1q
Index-11
Inde
prIorILIes . . . . . . . . . . . . . . . . . q-18
oplion escope . . . . . . . . . . . 1;-6, 1,-1S
oplion remember . . . . . z-8, 1;-z-1;-z6
or . . . . q-1q, q-q,, 16-z, 1;-qz, A-q, A-o
0R0ER . . . . . . . . . . . . . . . . . . . . . . . q-6
orlhpoiy..chebyshev1 . . . . . . . . . . A-1;
OS commund (syslem) . . . . . . . . . . . 1-1z
ouLpuL
munIpuIuLIon (Pref..oulpul) . . . 1-
oI IIouLIng-poInL numbers
(Pref..fioolFormol) . . . . . . . 1-
order oI Lerms . . . . . . . . . . . . . . z-11
suppressIng . . . . . . . . . . . . . . z-
ouLpuL und InpuL . . . . . . . . . . . . 1z-1-1z-;
preLLy prInL . . . . . . . . . . . . . . . . 1z-
overIoud . . . . . . . . . . . . . . . . . . . . . . 1-6
P
purser . . . . . . . . . . . . . . . . . . . . . . . . 1-6
porlfroc . . . . . . . . . . . . . . . . . . z-1, q-,
purLIuI IrucLIon decomposILIon
(porlfroc) . . . . . . . . . . . . . . . . q-;
PuscuI . . . . . . . . . . . . . . . . . . . . . . . . . 1-
PT . . . . . . . . . . . . . . . . . . . . . . . . . . . z-q
. . . . . . . . . . . . . . . . . . . . . . . . . . . z-q
pieceWise . . . . . . . z-1;, S-1o, 11-, 11-z1
PIuLo`s poIyIedru . . . . . . . . . . . . . . . 11-q
piol (grupIIcs IIbrury)
..AmbienlLighl . . . . . . . . . . 11-6
..ArcZd . . . . . . . . . . . . . . . . 11-q
..Arc3d . . . . . . . . . . . . . . . . 11-q
..ArroWZd . . . . . . . . . . . . . . . 11-q
..ArroW3d . . . . . . . . . . . . . . . 11-q
..BorsZd . . . . . . . . . . . . . . . . 11-
..Bors3d . . . . . . . . . . . . . . . . 11-
..Box . . . . . . . . . . . . . . . . . . 11-q
..Boxpiol . . . . . . . . . . . . . . . 11-
..Comero . . . . . . . . . . 11-6, 11-11
..Convos . . . . . . . . . . . 11-q6, 11-6
..CircieZd . . . . . . . . . . . . . . 11-q
..Circie3d . . . . . . . . . . . . . . 11-q
..CiippingBox . . . . . . . . . . . 11-6
..Cone . . . . . . . . . . . . . . . . . 11-q
..Conformoi . . . . . . . . . . . . . 11-
..CoordinoleSyslemZd . . . . . . .
. . . . . . . . . . . . . . . . . . 11-q;, 11-6
..CoordinoleSyslem3d . . . . . . .
. . . . . . . . . . . . . . . . . . 11-q;, 11-6
..CurveZd . . . . . . . . . . . . . . . 11-
..Curve3d . . . . . . . . . . . . . . . 11-
..Cyiinder . . . . . . . . . . . . . . 11-q
..Cyiindricoi . . . . . . . . . . . 11-
..0ensily . . . . . . . . . . . . . . . 11-
..0islonlLighl . . . . . . . . . . 11-6
..0odecohedron . . . . . . . . . . 11-q
..EiiipseZd . . . . . . . . . . . . . 11-q
..Eiiipse3d . . . . . . . . . . . . . 11-q
..Eiiipsoid . . . . . . . . . . . . . 11-q
..FunclionZd . . . . . . . . . . . . 11-
..Funclion3d . . . . . . . . . . . . 11-
..gel0efouil . . . . . . . . . . . . 11-8
..CroupZd . . . . . . . . . . . . . . . 11-6
..Croup3d . . . . . . . . . . . . . . . 11-6
..|olch . . . . . . . . . . . . . . . . 11-
..|exohedron . . . . . . . . . . . . 11-q
..|islogromZd . . . . . . . . . . . 11-
..Tcosohedron . . . . . . . . . . . 11-q
..TmpiicilZd . . . . . . . . . . . . 11-
..Tmpiicil3d . . . . . . . . . . . . 11-
..Tnequoiily . . . . . . . . . . . . 11-
..Tlerolion . . . . . . . . . . . . . 11-
..LineZd . . . . . . . . . . . . . . . . 11-q
..Line3d . . . . . . . . . . . . . . . . 11-q
..Lislpiol . . . . . . . . . . . . . . 11-
..Lsys . . . . . . . . . . . . . . . . . 11-
..Molrixpiol . . . . . . . . . . . . 11-
..0clohedron . . . . . . . . . . . . 11-q
..0deZd . . . . . . . . . . . . . . . . 11-
..0de3d . . . . . . . . . . 11-, 11-116
..PoroiieiogromZd . . . . . . . . 11-q
..Poroiieiogrom3d . . . . . . . . 11-q
..PiechorlZd . . . . . . . . . . . . 11-
..Piechorl3d . . . . . . . 11-, 11-6z
..Pione . . . . . . . . . . . . . . . . 11-q
..PoinlZd . . . . . . . . . . . . . . . 11-q
..Poinl3d . . . . . . . . . . . . . . . 11-q
Index-1
Inde
..PoinlLighl . . . . . . . . . . . . 11-6
..PoinlLislZd . . . . . . . . . . . 11-q
..PoinlLisl3d . . . . . . . . . . . 11-q
..Poior . . . . . . . . . . . . . . . . 11-
..PoiygonZd . . . . . . . . . . . . . 11-q
..Poiygon3d . . . . . . . . . . . . . 11-q
..Prism . . . . . . . . . . . . . . . . 11-
..Pyromid . . . . . . . . . . . . . . . 11-
..Piol . . . . . . . . . . . . . . . . 11-
..Rosler . . . . . . . . . . 11-, 11-11o
..Reclongie . . . . . . . . . . . . . 11-q
..RefieclZd . . . . . . . . . . . . . 11-6
..Refiecl3d . . . . . . . . . . . . . 11-6
..Rooliocus . . . . . . . . . . . . . 11-
..RololeZd . . . . . . . . . 11-6, 11-q;
..Rolole3d . . . . . . . . . 11-6, 11-q;
..ScoieZd . . . . . . . . . . 11-6, 11-q;
..Scoie3d . . . . . . . . . . 11-6, 11-q;
..Scollerpiol . . . . . . . . . . . 11-
..SceneZd . . . . . . . . . . 11-q6, 11-6
..Scene3d . . . . . . . . . . 11-q6, 11-6
..Sequence . . . . . . . . . . . . . . 11-
..sel0efouil . . . . . . . . . . . . 11-8
..SporseMolrixpiol . . . . . . . 11-
..Sphere . . . . . . . . . . . . . . . . 11-q
..Sphericoi . . . . . . . . . . . . . 11-
..SpolLighl . . . . . . . . . . . . . 11-6
..SlreomiinesZd . . . . . . . . . 11-
..Sum . . . . . . . . . . . . . . . . . . 11-
..Surfoce . . . . . . . . . . . . . . . 11-
..SurfoceSel . . . . . . . . . . . . 11-q
..SurfoceSTL . . . . . . 11-q, 11-11o
..SWeep . . . . . . . . . . . . . . . . 11-
..Telrohedron . . . . . . . . . . . 11-q
..TexlZd . . . . . . . . . . . 11-q, 11-;q
..Texl3d . . . . . . . . . . . 11-q, 11-;q
..TronsformZd . . . . . . 11-6, 11-q;
..Tronsform3d . . . . . . 11-6, 11-q;
..TronsioleZd . . . . . . 11-6, 11-q;
..Tronsiole3d . . . . . . 11-6, 11-q;
..Tube . . . . . . . . . . . . . . . . . 11-
..Turlie . . . . . . . . . . . . . . . . 11-
..veclorFieidZd . . . . . . . . . 11-
..veclorFieid3d . . . . . . . . . 11-
..nolermon . . . . . . . . . . . . . . 11-q
..XRolole . . . . . . . . . . . . . . . 11-
..ZRolole . . . . . . . . . . . . . . . 11-
piol . . . . . . . . . . z-16, z-z, 11-, 11-
piolfuncZd . . . . . . . . . z-16, 11-1oo, A-
png . . . . . . . . . . . . . . . . . . . . . . . . 11-1o;
poiy . . . . . . . . . . q-S1, q-8z-q-8q, A-zq
poiyZiisl . . . . . . . . . . . . . . . . . . . . q-8
poIynomIuIs . . . . . . . . . . . . . . q-81-q-qo
uccessIng Lerms (nlhlerm) . . . . q-8q
uppIyIng u IuncLIon Lo coeIIIcIenLs
(mopcoeffs) . . . . . . . . . . . . . . q-8;
urILImeLIc . . . . . . . . . . . . . . . . q-8
CIebysIev . . . . . . . . . . q-gg, A-16
coeIIIcIenLs
coeff . . . . . . . . . . . . . . . . . . q-8
nlhcoeff . . . . . . . . . . . . . . . q-8q
compuLIng wILI . . . . . . q-8-q-qo
conversIon oI u poIynomIuI
Lo u IIsL (poiyZiisl) . . . . . . . q-8
Lo un expressIon (expr) . . . . . q-8q
deIuuIL rIng (Expr) . . . . . . . . . . q-8q
deIInILIon (poiy) . . . . . . . q-81-q-8q
degree (degree) . . . . . . . . . . . . q-8
dIvIsIon wILI remuInder (divide) .
. . . . . . . . . . . . . . . . . . . . . . . . q-86
evuIuuLIon (evoip) . . . . . . . . . . q-88
IucLorIzuLIon (foclor) . . . . . . . . q-SS
Grbner buses (groebner) . . . . . q-qo
greuLesL common dIvIsor (gcd) . q-8q
IrreducIbIIILy LesL (irreducibie) . .
. . . . . . . . . . . . . . . . . . . . . . . . q-qo
IIbrury Ior orLIogonuI (orlhpoiy)
. . . . . . . . . . . . . . . . . . . . . . . . A-1;
muILIpIIcuLIon by u scuIur IucLor
(muilcoeffs) . . . . . . . . . . . . . . q-8;
number oI Lerms (nlerms) . . . . . q-8q
operunds . . . . . . . . . . . . . . . . . q-8q
PosLscrIpL . . . . . . . . . . . . . . . . . . . 11-1o;
poWermod . . . . . . . . . . . . . . . . . . . . . . q-61
Pref (IIbrury Ior user preIerences) . . . .
. . . . . . . . . . . . . . . . . . . . 1-z-1-
Index-1
Inde
..fioolFormol . . . . . . . . . . . . 1-
..oulpul . . . . . . . . . . . . . . . . . 1-
..poslTnpul . . . . . . . . . . . . . . 1-q
..posl0ulpul . . . . . . . . . . . . . 1-q
..reporl . . . . . . . . . . . . . . . . . 1-z
reseLLIng preIerences . . . . . . . . . 1-q
PRETTYPRTWT . . . . . . . . . . . . . . . . . . . 1z-
prImILIves . . . . . . . . . . . . . . . 11-q-11-6
prinl z-z6, z-zq, q-z6, q-q8-q-o, q-qq,
1-1, 1-1-1-q, 16-1, 1;-z;, A-1z
probubIIILy . . . . . . . . . . . . . . . 1o-1-1o-;
probubIIILy densILy IuncLIon . . . . . . . 1o-q
procedures . . . . . . . . . . . . . . . 1;-1-1;-qz
cuII . . . . . . . . . . . . . . . . . . . . . . 1;-
by nume . . . . . . . . . . . . . . . . 1;-z8
by vuIue . . . . . . . . . . . . . . . . 1;-z8
commenLs (/* */) . . . . . . . . . . . 1;-
deIInILIon . . . . . . . . . . . . . 1;--1;-q
evuIuuLIon IeveI . . . . . . . 1;-zq-1;-o
gIobuI vurIubIes . . . . . . . . . . . . . 1;-q
InpuL purumeLers . . . . . . 1;-z;-1;-z8
IocuI vurIubIes (iocoi) . . . 1;-q-1;-1
IormuI purumeLers . . . . . . . . 1;-z;
wILIouL u vuIue . . . . . . . . . . . 1;-o
MolrixProducl . . . . . . . . . . . . 1;-1z
oplion escope . . . . . . . 1;-6, 1,-1S
oplion remember . . z-8, 1;-z-1;-z6
procnome . . . . . . . . . . . . . . . . . . 1;-8
recursIon depLI (MAX0EPT|) . . . . . .
. . . . . . . . . . . . . . . . . . . 1,-q, A-qq
reLurn vuIue (relurn) . . . . . 1;--1;-6
scopIng . . . . . . . . . . . . . 1;-1;-1;-1q
subprocedures . . . . . . . . 1;-1q-1;-16
symboIIc dIIIerenLIuLIon 1;-8-1;-qo
symboIIc reLurn vuIues . . . . 1;-;-1;-8
LrIvIuI IuncLIon . . . . . . . . . . . . . 1;-zz
Lype decIuruLIon . . . . . . . . . . . . 1;-zo
vurIubIe number oI urgumenLs
(orgs) . . . . . . . . . . . . . 1;-z1-1;-zz
procnome . . . . . . 1,-S, 1;-zz, 1;-, A-qz
producl . . . . . . . . . . . . . . . . . . . . . . z-18
prog..exprlree . . . . . . . . . . . . . . . q-zo
properLIes . . . . . . . . . . . . . . . . . . . . q-18
properLy InspecLor . . . . . . . . . 11-o-11-
prolecl . . . . . . . . . . . . . . . . . . . . . q-1o
PuIseux serIes . . . . . . . . . . . . . . . . . q-8
Q
Q . . . see und domuIn, 0om..Rolionoi
. . . . . . . . . . . . . . . . . . . . . . . . . . . 8-;
quudruLure . . . . see numerIcuI InLegruLIon
quunLIIe IuncLIon . . . . . . . . . . . . . . . 1o-q
quoLIenL moduIo (div) . . . . . . . . q-6, q-1
R
R . . . . . . . see R und domuIn, 0om..Reoi
R . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-;
R . . . . . . . . . . . . . . . . . . . . . . q-18, q-1q
rudIcuI sImpIIIIcuLIon (rodsimp) . . . . q-1q
rodsimp . . . . . . . . . . . . . . . . . z-1, q-1q
rondom . . . . . . . . . . . . . 1o-1, 1o-q, A-q
rundom number generuLors (rondom,
frondom, slols..normoiRondom}
. . . . . . . . . . . . . . . . . . . . 1o-1-1o-;
rundom numbers
normuIIy dIsLrIbuLed
(slols..normoiRondom) . . . . . . 1o-q
oLIer dIsLrIbuLIons . . . . . . . . . . 1o-q
unIIormIy dIsLrIbuLed (frondom) 1o-z
unIIormIy dIsLrIbuLed (rondom) . . 1o-1
runge . . . . . . . see expressIons, runge (..)
R0TWF . . . . . . . . . . . . . . . . . . . . . . q-qg
R0WTWF . . . . . . . . . . . . . . . . . . . . . q-qg
Re . . . . . . . . . . . . . . . . . . z-1o, q-6, q-z
reod . . . . . . . . . . . . . . . . . . . 1-g, 1;-o
reudIng duLu (imporl..reoddolo) . . . . 1z-6
Reoi . . . . . . . . . . . . . . . . . . . . . . . . . S-6
reuI purL . . . . . . . . . . . . . . . . . . . . see Re
rec . . . . . . . . . . . . . . . . . . . . . S-1g, A-z
reclform . . . . . . . . . . . . . . . . . z-1o, q-11
recurrence equuLIons (rec) . . . . . . . . . 8-1
remuInder moduIo (mod) . . . . . . q-6, q-1
redeIInILIon . . . . . . . . . . . . . . . . q-1
oplion remember . . . . . . . . . 1;-z-1;-z6
repeol . . . . . . . . . . . . . . . . . . . . . . A-1z
Index-1q
Inde
resel . . . . . . . . . . . . . . . . . . q-qq, 1-11
resIdue cIuss rIng . . . . . . . . . . . . . . . . .
. . . . . see domuIn, 0om..TnlegerMod
resLurLIng u sessIon (resel(}) . . z-8, 1-11
<ReLurn> . . . . . . . . . . . . . . . . . . . . . . z-z
relurn . . 1,-g, 1;-8, 1;-1o, 1;-zo, 1;-q,
A-o
reverl . . . . . . . . . q-gq, A-1, A-16, A-1q
reWrile
LurgeLs . . . . . . . . . . . . . . . . . . . q-1o
reWrile . . . . . . . . . . . . . . . . . . . . . . q-S
RCB..CoiorWomes . . . . . . . . . . . . . . 11-68
RCB..piolCoiorPoielle . . . . . . . . . 11-68
rIngs . . . . . . . . . . . . . . . . . . . . q-6o-q-6
Rool0f . . . . . . . . . . . . . . . . . . . . . . . 8-z
rooLs . . . . . . . . . . . . . . . . . . . . . . . . z-zz
round . . . . . . . . . . . . . . . . . . . . . . . . q-;
roundIng errors . . . . . . . . . . . . . . . . . 1-z
row vecLors . . . . . . . . . . . . . . . . . . . q-66
runLIme InIormuLIon ubouL uIgorILIms
(userinfo und seluserinfo) . . 1-q
S
suvIng grupIIcs . . . . . . . . . 11-1o;-11-1oq
buLcI mode . . . . . . . . 11-1o8-11-1oq
InLerucLIve . . . . . . . . . . . . . . . 11-1o;
scopIng . . . . . . . . . . . . . . . . . 1;-1;-1;-1q
screen ouLpuL (prinl) . . . . . . . . . . . . 1z-1
munIpuIuLIon (Pref..oulpul) . . . 1-
seiecl . . . . z-z-z-z;, z-zq, q-, q-8,
q-qz, 1q-, A-q, A-11, A-zq, A-,
A-6
semIcoIon . . . . . . . . . . . . . . . . . . . . . z-
sequence . . . . . . . . . . . . . . . . . . . . . . q-1
sequence generuLor (S) . . . . . . . z-z, q-q
in . . . . . . . . . . . . . . . . . . . . . . q-z
sequence generuLor (S) . . . . . . . . . . . . q-1
sequences . . . . . . . . . . . . . . . . q-zq-q-z;
deIeLIng eIemenLs (deiele) . . . . q-z;
Indexed uccess . . . . . . . . . . . . . q-z6
oI InLegers . . . . . . . . . . . . . . . . q-zq
series . . . . . . . . . . . . . z-z, q-gS, A-18
serIes expunsIons . . . . . . . . . . . . . . . . .
. . . . . . . q-6-q-q, see clso series
usympLoLIc expunsIon (series) . . .
. . . . . . . . . . . . . . . . . . . z-z, q-gS
conversIon Lo u sum (expr) . . . . q-;
uurenL serIes (series) . . . . . . q-8
oI Inverse IuncLIons (reverl) . . q-q
operunds . . . . . . . . . . . . . . . . . q-;
poInL oI expunsIon . . . . . . . . . . q-;
PuIseux serIes (series) . . . . . . . q-8
TuyIor serIes (loyior) . . . . . . . . q-6
LruncuLIon (0) . . . . . . . . . . . . . . q-6
order (0R0ER) . . . . . . . . . . . . q-6
sessIon
resLurL (resel(}) . . . . . . . z-8, 1-11
suvIng u (Wrile) . . . . . . . . . . . 1z-6
seLs . . . . . . . . . . . . . . . . . . . . . q-6-q-q
uppIyIng u IuncLIon (mop) . . . . . q-8
busIc seLs (soiveiib..BosicSel) . 8-;
dIIIerence (minus) . . . . . . . . . . q-;
eIemenLs (op) . . . . . . . . . . . . . . q-6
empLy seL ({], ) . . . . . . . . . . . . q-6
excIungIng eIemenLs . . . . . . . . q-;
Imuge seL (0om..TmogeSel) . . . . . 8-q
InLersecLIon (inlersecl) . . . . . . q-;
InLervuIs (0om..Tnlervoi) . . . . . 8-11
number oI eIemenLs (nops) . . . . q-6
order oI LIe eIemenLs . . . . . . . . q-6
removIng eIemenLs . . . . . . . . . . q-;
seIecLIng uccordIng Lo properLIes
(seiecl) . . . . . . . . . . . . . . . . . q-8
seL-vuIued IuncLIons . . . . . . . . . q-;
spIILLIng uccordIng Lo properLIes
(spiil) . . . . . . . . . . . . . . . . . . q-8
unIon (union) . . . . . . . . . . . . . q-;
seluserinfo . . . . . . . . . . . . . . . . . . . 1-q
SIerpInskI LrIungIe . . . . . . . . . 1,-q, A-q8
sign . . . . . . . . . . . . . . . . . . . . . q-;, q-z
sImpIIIIcuLIon . . . . . . . . . . . . . . . . . . 6-z
uuLomuLIc . . . . . . . . . . . -1o--1z
oI expressIons (simpiify) . q-1-q-1;
oI rudIcuIs (rodsimp) . . . . z-1, q-1q
Index-1g
Inde
Simpiify . . . z-1, q-;q, q-1, q-1g, q-1;,
A-, A-q
simpiify . . . z-1, q-1, q-zz, A-z, A-o
sIne InLegruI (Si) . . . . . . . . . . . . . . . . ;-q
soIuLIon
upproxImuLe . . . . . . . . . . . see fiool
soive . . . z-, z-1;, z-18, z-zz, q-, q-11,
-11, 6-, S-1, 8-q-8-;, 8-q, 8-1o,
8-1z, 8-1, 8-1, A-;, A-z8, A-zq,
A-z
soIvIng equuLIons . . . . . . . . . see equuLIons
sorl . . . . . . . . . . . q-1, 1o-q, A-1, A-q
user-deIIned order . . . . . . . . . . 1o-q
source code (expose) . . . . . . . . . . -, -6
source code debugger . . . . . . . . . . . . . 1-6
spurse muLrIces . . . . . . . . . . . . q-;;-q-;8
spiil . . . . . . . . . q-, q-8, q-qz, A-8
sqrl . . . . . . . . . . . . . . . . . . . . . . z-6, q-,
squure rooL (sqrl) . . . . . . . . . . . . z-6, q-,
sLundurd devIuLIon (slols..sldev) . . 1o-
sLuLIsLIcs . . . . . . . . . . . . . . . . . 1o-1-1o-;

2
-LesL (slols..csC0FT) . . . . . . . 1o-
equIprobubIe ceIIs
(slols..equiprobobieCeiis) . 1o-
IrequencIes (0om..Muilisel) . . . .
. . . . . . . . . . . . . . . . . . . 1o-, A-q
IIbrury Ior (slols) . . . . . . . . . 1o-z
meun vuIue (slols..meon) . . . . 1o-z
normuI dIsLrIbuLIon
(slols..normoiC0F) . . . . . . . . 1o-
quunLIIe (slols..normoiuonliie)
. . . . . . . . . . . . . . . . . . . . . . . . 1o-
rundom numbers (frondom, rondom,
slols..normoiRondom) . . . . . . .
. . . . . . . . . . . . . . . 1o-1, 1o-z, 1o-q
sLundurd devIuLIon (slols..sldev)
. . . . . . . . . . . . . . . . . . . . . . . . 1o-
vurIunce (slols..vorionce) . . . 1o-z
slols (IIbrury Ior sLuLIsLIcs)
..csC0FT . . . . . . . . . . . . . . . . . 1o-
..equiprobobieCeiis . . . . . . . 1o-
..meon . . . . . . . . . . . . . . . . . 1o-z
..normoiC0F . . . . . . . . . . . . . . 1o-
..normoiuonliie . . . . . . . . . . 1o-
..normoiRondom . . . . . . . . . . 1o-q
..sldev . . . . . . . . . . . . . . . . 1o-
..vorionce . . . . . . . . . . . . . . 1o-z
sLrIngs . . . . . . . . . . . . . . . . . . q-qq-q-1
converLIng expressIons Lo
(exprZlexl) . . . . . . . . . q-go, 1-q
exLrucLIng symboIs . . . . . . . . . . q-qq
IengLI (ienglh) . . . . . . . . . . . . . q-1
IIbrury (slringiib) . . . . . . . . . q-o
screen ouLpuL (prinl) . . . . . . . . q-qq
subsLrIngs . . . . . . . . . . . . . . . . q-qq
subprocedures . . . . . . . . . . . . 1;-1q-1;-16
subs . q-;z, q-qq, 6-1, 6--6-6, 8-, 8-11,
1o-z, A-z, A-z6, A-zq, A-
subsex . . . . . . . . . . . . . . . . . . . . . . . 6-q
subsop . . . . . q-zq, 6-g, 6-;, 1;-q, A-zq
subsLILuLIon . . . . . . . . . . . . . . . . . 6-1-6-;
enIorced evuIuuLIon (evoi) . . . . . 6-
In sums und producLs (subsex) . . 6-q
muILIpIe s . . . . . . . . . . . . . . . . 6-q
oI operunds (subsop) . . . . . . . . . 6-
oI subexpressIons (subs) . . . . . . . 6-1
oI sysLem IuncLIons . . . . . . . . . . . 6-
sImuILuneous . . . . . . . . . . . . . 6-
sum . . . . . . . . . . . . . . . . . . . . . . . . . . z-18
Symboi . . . . . . . . . . . . . . . . . . . . . . . q-8
symboIIc compuLuLIons . . . . . . . 1-, z-11
symboIIc munIpuIuLIon . . . . . . . . . . . . . 1-
syslem . . . . . . . . . . . . . . . . . . . . . . 1-1z
T
lobie q-o, q-qo, q-q1, q-qz, q-q6, A-1,
A-1q
LubIes . . . . . . . . . . . . . . . . . . . q-qo-q-q
uccessIng eIemenLs . . . . . . . . . . . q-q1
uppIyIng u IuncLIon (mop) . . . . . q-qz
deIeLIng enLrIes (deiele) . . . . . . . q-q1
expIIcIL generuLIon . . . . . . . see lobie
ImpIIcIL generuLIon . . . . . . . . . . q-qo
operunds . . . . . . . . . . . . . . . . . . q-q1
queryIng IndIces (conloins) . . . q-qz
Index-16
Inde
seIecLIng uccordIng Lo properLIes
(seiecl) . . . . . . . . . . . . . . . . . q-qz
spIILLIng uccordIng Lo properLIes
(spiil) . . . . . . . . . . . . . . . . . . q-qz
lon . . . . . . . . . . . . . . . . . . . . . q-1;, A-q
LungenL . . . . . . . . . . . . . . . . . . . . . . 11-q
loyior . . . q-g6, q-;, q-8, 1z-q, 1;-6,
A-1;-A-1q
lesllype . . . . q-zo, 1q-, 1q-, 16-z, 1;-;,
1;-8, A-8, A-qo
TeLruIedron . . . . . . . . . . . . . . . . . . 11-q
TEXTnT0T| . . . . . . . . . . . . . . . . . . . . . 1z-q
lime . q-q, 1-q, 1-6, 1;-z-1;-z, A-1q
LrunsIormuLIons . . . . . . . . . . . 11-q;-11-qq
LrunsIormIng expressIons . . . . . . q--q-1z
TRuE . . . . . . . . . . . . . . . . . . . . . . . . q-q,
lrunc . . . . . . . . . . . . . . . . . . . . q-,, A-6
Type (IIbrury Ior Lype cIeckIng)
..AnyType . . . . . . . . . . . . . . . A-qo
..Even . . . . . . . . . . . . . . . . . 1q-g
..Tnlervoi . . . . . . . . . . . . . . q-zz
..Lisl0f . . . . . . . . . . . . . . . . A-qo
..WegTnl . . . . . . . . . . . . . . . . . 1q-
..WonWegTnl . . . . . . . . . . . . . 1;-zo
..Wumeric . . . . . . . 1q-, 1;-;, 1;-8
..0dd . . . . . . . . . . . . . . . . . . . 1q-
..PosTnl . . . . . . . . . . . . . . . . . 1q-
..Posilive . . . . . . . . . . . . . . q-18
..Reoi . . . . . . . . . . . . . . . . . q-z
..Residue . . . . . . . . . . . . . . . q-zz
lype . . . . . . . . . . . . . . . . . . . . . . . . . 1q-z
Lypes oI MuPAD objecLs . . . . . . 1q-1-1q-6
domuIn Lype (domlype) . . . . . . . . q-z
IIbrury (Type) . . . . 1q-q, 1;-zo, A-qo
Lype cIeckIng (lesllype) . . . . . . 1q-z
Lype query (lype) . . . . . . . . . . . . 1q-z
LypeseL expressIons . . . . . . . . . . . . . . 1z-
U
unossume . . . . . . . . . . . . . . . . . . . . . q-zo
undefined . . . . . . . . . . . . . . . q-1oo, -11
union . . . . . q-,, q-q, q-q6, A-1, A-;
uWKW0nW . . . . . . . . . . . . q-z, q-8, q-q,
unknowns . . . . . . . . . . . . . . see IdenLIIIers
unprolecl . . . . . . . . . . . . . . . . . . . . q-1o
use . . . . . . . . . . . . . . . . . . . . . -q, 11-68
V
vurIunce (slols..vorionce) . . . . . . . 1o-z
veclorFormol . . . . . . . . . . . . . . . . . . 8-
vecLors . . . . . . . . . . . . . . . . . . q-6q-q-8o
coIumn . . . . . . . . . . . . . z-1q, q-66
Indexed uccess . . . . . . . . . . . . . q-6;
InILIuIIzuLIon . . . . . . . . . . . . . . q-66
row . . . . . . . . . . . . . . . . . . . q-66
W
WuLermun poIyIedru . . . . . . . . . . . . 11-q
worksIeeL . . . . . . . . . . . . . . . . . . . . . . 1-
Wrile . . . . . . . . . . . . . . . . . . . 1-g, 1z-6
wrILe proLecLIon
removIng (unprolecl) . . . . . . q-1o
seLLIng (prolecl) . . . . . . . . . q-1o
Z
Z . . . . see Z und domuIn, 0om..Tnleger
Z . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-;
Z . . . . . . . . . . . . . . . . . . q-18, q-1q, q-zz
zip . . z-z8, q-, q-q, q-;z, q-q8, 1o-q,
A-1o, A-1q, A-q
Z
n
. . . . . . see domuIn, 0om..TnlegerMod
Index-1,

You might also like