Professional Documents
Culture Documents
Mupad Tutorial
Mupad Tutorial
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
.
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
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
$elIwure
n compurIson Lo oLIer compuLer uIgebru sysLems, MuPAD
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
eIebeek iaIerlute
AILer you cuII LIe MuPAD
14
TIe resuIL oI LIe sImpIIIIcuLIon oI
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
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
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
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
)
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
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
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
piol(F C | x = -1..4}
Ilementury Nomber Theory
MuPAD
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
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
Libruries
MosL oI MuPAD
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
Objects
n CIupLer z, we InLroduced MuPAD
Cb[ec|s
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:
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
)
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
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
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:
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
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:
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
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
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
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
Cb[ec|s
ubles
A LubIe Is u MuPAD
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
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
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
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
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 ( =
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
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
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
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
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
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
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
_
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.
(x), eLc.
6-,
7
iIIerentiution und Integrution
We Iuve uIreudy used LIe 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
(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)
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
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
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) = 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
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
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
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
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
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
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
(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:
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
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:
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.
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
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:
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) 1/f
b wILI u vecLor
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 = (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 = (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
und MucInLosI
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
librury?
TIe renderIng engIne Ior D pIoLs uses LIe OpenG
under WIndows
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
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
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
Algori|hms
lalermuIiea ea MuFk0
klgeriIhms
Some MuPAD
5ession
kesIurIiag u MuFk0
$essiea
TIe commund resel(} reseLs u 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
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,
Procedores
MuPAD
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
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
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
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
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
_
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
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
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
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
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
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
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
(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
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
, 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
_
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 =
_
_
_
_
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
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
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
(
_
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
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
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,