Introductory Programming Guide.pdf

(9121 KB) Pobierz
Maple
Introductory
ProgrammingGuide
M.B.MonaganK.O.GeddesK.M.Heal
G.LabahnS.M.VorkoetterJ.McCarron
P.DeMarco
c ­Maplesoft,adivisionofWaterlooMapleInc.2005.
ii ¯
Maplesoft,Maple,andMapletarealltrademarksofWaterlooMaple
Inc.
c ­Maplesoft,adivisionofWaterlooMapleInc.2005.Allrightsre-
served.
Theelectronicversion(PDF)ofthisbookmaybedownloadedand
printedforpersonaluseorstoredasacopyonapersonalmachine.The
electronicversion(PDF)ofthisbookmaynotbedistributed.Information
inthisdocumentissubjecttochangewithoutnoticeanddoesnotrep-
resentacommitmentonthepartofthevendor.Thesoftwaredescribed
inthisdocumentisfurnishedunderalicenseagreementandmaybeused
orcopiedonlyinaccordancewiththeagreement.Itisagainstthelaw
tocopythesoftwareonanymediumexceptasspecißcallyallowedinthe
agreement.
WindowsisaregisteredtrademarkofMicrosoftCorporation.
JavaandallJavabasedmarksaretrademarksorregisteredtrade-
marksofSunMicrosystems,Inc.intheUnitedStatesandothercountries.
MaplesoftisindependentofSunMicrosystems,Inc.
Allothertrademarksarethepropertyoftheirrespectiveowners.
ThisdocumentwasproducedusingaspecialversionofMaplethat
readsandupdatesL A T E Xßles.
PrintedinCanada
ISBN1-894511-76-X
Contents
Preface 1
Audience.............................. 1
WorksheetGraphicalInterface.................. 1
ManualSet............................. 2
Conventions............................. 2
TheMapleProgrammingLanguage............. 3
UsingThisBook....................... 3
CustomerFeedback......................... 4
1IntroductiontoProgramminginMaple 5
InThisChapter ....................... 5
1.1TheMapleSoftware..................... 5
1.2MapleStatements ...................... 6
GettingStarted........................ 6
MapleStatements ...................... 7
GettingHelp......................... 7
DisplayingaTextString................... 7
PerforminganArithmeticOperation............ 8
AssigningtoaName..................... 8
UsingMapleLibraryRoutines................ 9
1.3Procedures.......................... 9
DeßningaSimpleProcedure................ 9
MapleLibraryRoutines,Built-InRoutines,andUser-
DeßnedProcedures.................. 13
1.4InterruptingComputationsandClearingtheInternalMem-
ory............................... 16
InterruptingaMapleComputation............. 16
ClearingtheMapleInternalMemory............ 17
1.5Troubleshooting........................ 17
UnexpectedEndofStatement................ 17
iii
iv¯Contents
MissingOperator....................... 18
Invalid,WrongNumberorTypeofArguments...... 19
UnbalancedParentheses................... 19
AssignmentVersusEquality................. 20
1.6Exercises ........................... 21
1.7Conclusion.......................... 21
2MapleLanguageElements 23
InThisChapter ....................... 23
2.1CharacterSet......................... 23
2.2Tokens............................. 24
ReservedWords........................ 24
Programming-LanguageOperators............. 25
Names............................. 26
Strings............................. 38
NaturalIntegers....................... 46
2.3UsingSpecialCharacters................... 46
TokenSeparators....................... 46
BlankSpaces,NewLines,Comments,andContinuation. 46
PunctuationMarks...................... 48
EscapeCharacters...................... 51
2.4TypesandOperands..................... 51
Integers............................ 52
Strings............................. 53
Names............................. 53
Concatenations........................ 55
2.5Troubleshooting........................ 55
AttemptingtoAssigntoaProtectedName........ 55
InvalidLeft-HandAssignment................ 56
IncorrectSyntaxinParse.................. 56
WhiteSpaceCharacterswithinaToken.......... 56
IncorrectUseofDoubleandSingleQuotes......... 57
2.6Exercises ........................... 58
2.7Conclusion.......................... 58
3MapleExpressionsandStatements 59
InThisChapter ....................... 59
3.1SyntaxandSemantics.................... 59
Syntax............................. 59
Semantics........................... 60
3.2Expressions.......................... 61
Contents¯v
Constants........................... 61
Operators........................... 70
DataStructures........................ 89
Functions........................... 92
3.3UsingExpressions...................... 96
InvestigatingthePartsofanExpression.......... 96
EvaluatingandSimplifyingExpressions..........100
UnevaluatedExpressions...................100
SubstitutingSubexpressions.................103
DisplayingLargeExpressions:Labels............105
StructuredTypes.......................106
3.4Statements..........................110
TheAssignmentStatement.................111
SelectionStatements.....................114
RepetitionStatements....................115
ThereadandsaveStatements...............117
ThebreakandnextStatements..............118
TheerrorandreturnStatements.............118
TheuseStatement......................119
ThequitStatement.....................119
3.5Troubleshooting........................119
SyntaxErrors.........................120
ReservedWordUnexpected.................120
BreakorNextNotinLoop.................121
3.6Exercises ...........................121
3.7Conclusion..........................122
4BasicDataStructures 123
InThisChapter .......................123
4.1Sets..............................123
ManipulatingaSet......................124
4.2Lists..............................126
ManipulatingaList.....................128
4.3Tables.............................133
AnAlternateMethodforGeneratingaTable.......135
TableEvaluationRules ...................135
ManipulatingaTable....................136
4.4arraysandArrays ......................141
EvaluationRulesforarrays.................144
ManipulatingarraysandArrays...............145
4.5SelectingElementsfromaDataStructure.........152
Zgłoś jeśli naruszono regulamin