maple basics
TRANSCRIPT
-
7/25/2019 Maple Basics
1/15
2014, Version 02
Basic Elements of the Maple Symbolic Algebra Program Language
Read this whole handout through once without trying any of its suggestions. Then go back and follow its suggestions
about learning to use Maple. Its a good idea to have a sample problem ready for which you know the mathematical
procedure to solve it. You are then in a position to try out what you read on a real problem.
You should keep track of what you dont understand on the second reading. (n the first reading! concepts presented
earlier may become clearer later in the reading." You should then ask about these matters by email or at the very ne#t
class session. In addition to answering your $uestions! I will use your input here to (hopefully" improve the document.%ven if you understand some aspect of the document! if you have a suggestion for improving the e#planation! please letme know.
In particular! if something seems incorrect or doesnt match up with what you observe in Maple! please let me know as
soon as possible by email. This help document is meant to be for Maple &'! but I may not have managed to change allaspects of the document from previous Maple versions that are no longer valid as is.
I. Overview
Maple is an interactive symbolic algebra program.Interactivemeans (1) that you get immediate, step by step results, (2)
that no compiling (first riting the hole program, then having a !compiler" program produce a !machine language"
version, and finally run the !machine language" version, a long indirect process) is necessary, and (#) that you can editand re$use any statement on a or%sheet. <hough algebrais the customary ord to use in the definition, the program
actually does calculus and many other forms of advanced mathematics, not 'ust algebra. inally,symbolicmeans that the
program understands symbolic mathematical symbols and structures it understands, for e*ample, the derivative of a
function hen the function is given only as, say, f(*). +he program can save and symbolically manipulate mathematical
structures defined in symbolic terms. &t the same time, Maple also does numerical calculations. &s a comparison,
languages li%e ortran and need to be compiled and only understand instructions to do numerical calculations.
-ecause it is symbolic, Maple is much more heavily based on the concept of structuresthan other programming languages
and has many more of these structures. +his is particularly true of data structures Maple has to save symbolic entities and
%no hich is hich and hat the parts mean. +hese data structures do not have to, indeed often do not, contain numeric
data they can even contain symbols that stand for other data structures. +hese data structures can even be e*amined and
manipulated directly by the use of the functions nops( ) and op( ) listed in the basic commands section belo. +o useMaple successfully, one has to understand these data structures and distinguish correctly beteen them.
-ecause it is interactive, Maple also has a ell$developed / (raphical /ser nterface) and enhanced system features,
here system refers to ays of interacting ith the Maple program in terms of e*ecution and memory. -ecause it is a
programming language, Maple has the standard programming structures storage of data structures under names, loops
(the repetition of instructions), if$bloc%s (the ability to decide hich instructions to e*ecute), and procedures or
subroutines (saved instructions that can be used elsehere in the program). t also has many functions to create and
manipulate data structures. inally, because it is algebraic, Maple has many built$in procedures that do mathematical
manipulations.
ince there are many, many more aspects to Maple than any one person could possibly %no or use, you have to stay calm
and not be frightened by information in the help material that goes beyond hat you need to do. n other ords, you haveto practice intelligent filteringhen reading the help material. 3ou ant to be aare of possibilities, hich are notimmediately relevant, for hich you can ignore the details hen you first meet them. oever, later, hen doing a
problem, you might then remember that there is something that might help. +hen you can loo% at the details. 5ne attitude
to ta%e hen starting to accomplish a tas% ith Maple is to alays be thin%ing the folloing thought f could do a
certain mathematical operation, doing that operation ould be a useful step in accomplishing the tas%, and so Maple
probably has the ability to do such an operation. +hen see% such an operation in the help system.
II. he Built!in "elp System an# other "elp Material an# Manuals
Maple has a ell$developed built$in help system. +his section describes that Maple help system so that you ill be have
an idea of ho to access and use the help system hen you open a Maple or%sheet even for the first time. oever,
before you can reach the help system you have to read the information on the user interface in section belo. 6hen
-
7/25/2019 Maple Basics
2/15
you do open a or%sheet, you ill them be able to try out the help system.
rom the drop$don elp menu at the top of the Maple or%sheet page, you can reach a large number of help items.
oever, the first thing to loo% at is the Maple elp item. +his is the or%horse that you ill probably be using as
regularly as do. (Maple elp can also be brought up by clic%ing the !7" tool icon at the top of the or%sheet.) 5nce you
bring it up, it e*ists as a separate indo that can be minimi8ed and restored and so can be constantly at hand during your
or% ith Maple ithout losing your place in the help pages. 3ou can even create multiple independent Maple elp
indos so you can %eep several different help pages immediately at hand simultaneously. call this the Maple elp
ystem.
The Table of ontents (T"
9otice also that at the left of each help indo there is a frame in hich you can either loo% at a +able of ontents (+5)
or the earch :esults. 6hen you first bring up the help system, the +5 tab ill be activated. 3ou should become familiar
ith the +5. t is a very important ay to see the possibilities of Maple. &s opposed to searching, it can actually suggest
structural, mathematical, and manipulative tools hich perhaps ould never have occurred to you. /nfortunately, the
local hierarchical structure hich ill describe belo for searches of help pages is 95+ the same hierarchical structure
used in the +5. :emember also that the +5 is not an inde*, so it is not alphabetical.
3ou should first e*amine the +5. +his means get a feeling for hat;s there and ho it;s organi8ed. +his does $Omean
read all the help pages to hich the +5 items refer. /nfortunately again, the many of the items referring to the general
idea of !getting started" are really unintelligible until you %no more about Maple and, even then, only a fe are reallyrelevant or useful. oever, the +utorial items 1,#,..< are somehat useful. /nfortunately, they sho e*amples in
=ocument Mode (see / section), hich e ill 9>V>: be using. +hey also suggest using the so$called !conte*t"
menus for doing mathematical operations, hich e ill almost 9>V>: be doing. /sing these conte*t menus for
mathematical operations seems ?uic% and easy hoever, it obscures hat is be done both from you and any reader of the
or%sheet (such as me), hereas our goal is to alays be as clear as possible about hat e are doing.
&fter e*amining the +5, you should read my etting tarted section belo. +hen you should go to the +5 itemManuals@/ser Manual@ontents. (+he vertical lines tell you succeeding loer level choices in the hierarchy of +5
items.) 3ou should read and try to get a basic understanding of all the chapters e*cept chapters 2 and 10. (n addition,
ignore all information about actions in =ocument Mode or about =ocument -loc%s. 3ou should (must) not ever use these
aspects in any or% you hand in.) >*pect to get only an overall vie of Maple from this /ser Manual. +hen loo% at
Manuals@Arogramming uide@ontents. &gain you only e*pect to get an overall vie of Maple from this reading. mustemphasi8e again that Maple has many more capabilities than even an e*pert fre?uent user ould ever use, so at this point
you are only interested in hat is generally available and here it is described.
)earches
9o, e ill discuss ho the search part of the Maple help system or%s.
earch tends is based on both !topic" names and the occurrence of your search ord on a help page. f you use a !topic"
name, or at least the beginning of one, the search results ill sho the page(s) you are interested in right at the beginning
of the search results. &fter that there ill be a list of other (possibly not relevant) pages, -/+ you need to %no at least
the beginning part of the topic name. or any help page, a topic name is given in the earch :esult list. +opic names also
have a local hierarchical structure hich can be very useful. 3ou %no that a topic name is in such a local hierarchicalstructure hen its name is a se?uence of ords separated by commas. (9ote that the name in parentheses after a topicname in the earch :esults list is notpart of the topic nameB t is actually either a synonym for the topic name that can
also be used to identify the same help page or at least a topic name that ill bring up the indicated page amongst the
search results. -e aare that help pages do not have uni?ue topic names, but often a number of synonyms.) f you enter
the first name in such a se?uence, you ill get a nice hierarchical list of related help pages in the search result pane
ordered alphabetically. or e*ample, you can get the list of all the !plots" pac%age;s functions; help pages by 'ust putting
in the topic !plots", of course ithout the ?uotes. Cee the list of basic commands in ection V, belo.D
+here is no (in Maple 1E) a shortcut to searching the Maple help system. +here is no a search bo* on the far right of
the toolbar. +his only shos some of the search results, but gives more information on many of the results shon. 3ou can
Page 2 of 15
-
7/25/2019 Maple Basics
3/15
select the ee &ll ... at the bottom of the result list to go to the regular help indo ith all the search results.
-e aare that some help pages are real or%sheets and not strictly spea%ing !help pages". +hus, after chec%ing that item
in either the +5 or search results, you have to go to your or%sheet to see the !help page" shon in a ne tab.
f the first fe results do not give hat you are loo%ing for, you ill have to loo% further in the list of results, ma%e some
educated guesses, and try some possibilities. 3ou can also try various synonyms for the term you are loo%ing for. &fter a
hile you ill tend to learn fre?uently used topic names. +he search results are, unfortunately, not completely
alphabetically ordered, although subsets of them are the search results are ordered according to somebody;s idea of
!relevance" but this order does not, in fact, seem to be very useful.
)trategy for *sing the +elp )ystem
+he ay one uses the help system is often to first thin% of hat actions one ants to carry out mathematically and then to
search for ords that describe that action, using the +5 directly or the search facility. &lso instead of thin%ing that one
has to memori8e the e*act synta* for many commands (and e*act synta* is essential for computer code), one remembers
the general ords describing the action of the command and one uses the help system. &fter a hile, you ill remember
the synta* for those commands that you use most often, or at least the beginning part of their topic name andFor position in
the +5.
n ection V belo, have listed many of the basic !topics" that you ill need to %no about. 3ou should loo% at each of
the help pages listed, since put them there because you ill need to use all of them routinely. +heir complete descriptionscan be found on the help system. f the ord itself is not the topic name, have indicated the relevant topic name(s) (in
s?uare brac%ets C...D) under hich you can find it in the help system using search. f the !topic" is folloed immediately
by an empty pair of parentheses, that indicates the !topic" is a Maple function that must be folloed by these parentheses
hen it is used and can ta%e arguments ithin the parentheses. oever, you should not include the parentheses hen
using the function name as a topic name. ome !topics" are folloed by material in curly brac%ets G ...H. +he material in
these brac%ets, ith names separated by vertical lines @, refers to locations in the +able of ontents. inally, some !topics"
are folloed by a brief e*planatory note in parentheses (...).
,dditional +elp )ources
+hrough the elp menu one can also reach some other useful help pages. +a%e a loo% at Manuals, :esources, and more@
/sing the elp ystem. +o other elements on the drop$don elp menu you might find useful once you %no basicallyho Maple operates are Iuic% :eference and Iuic% elp. +hey are indos that pop$up ith various pieces of summary
information on them.
/nfortunately many of the other help items, such as +a%e a +our of Maple and Manuals, :esources, and more@Manuals@
etting tarted... do not seem to me to be really helpful. +hey often do not give you basic information before they give
you more advanced information, and they are often more li%e publicity rather than really telling you ho to do things.
n addition to the built$in help system, there is a Maple eb site, httpFF.maplesoft.com ith a lot of additional help
materials. +he most useful at the beginning are probably the ones am about to describe, although if you loo% around the
site over time and especially on the pages to hich you ill be directed belo, you ill no doubt find much other
interesting and useful material. -efore you go to the help material you should register as a member. +his is totally free.
&long the top of the page is a strip of names bringing up drop$don menus. +he :esources one ill be most useful toyou. irst, go to :esources@ommunity@Maplesoft Membership. +hat ill bring you to the registration page. &fterregistering, you are ready to go to another sort of help material.
o to :esources@ommunity@MapleArimes. 3ou can as% ?uestions of the Maple users; community there, and search
ansers already there.
III. he %&I '%raphical &ser Interface( an# %etting Starte# Information
Page 3 of 15
http://www.maplesoft.com/http://www.maplesoft.com/ -
7/25/2019 Maple Basics
4/15
*sing the -orksheet Mode is %ssential
3ou must be sure to use the 6or%sheet Mode of the / ith standard 2$= Math input, not 6or%sheet Mode ith
!Maple nput" and not =ocument Mode. (2$=, of course, means 2$=imensional.) !Maple nput" does not sho the
mathematical e*pressions you input in the usual 2$= (te*tboo%) format and is thus more difficult to proofread. =ocument
mode is not useful for calculating and programming it is meant to be used to rite documents to be passively read.
f the almost blan% page that opens hen you start Maple has a s?uare brac%et at the left ith a red !J", the prompt, you
are in 6or%sheet Mode. f this is not the case, go to the file menu and choose 9e@6or%sheet Mode. f the page also has a
blin%ing (italici8ed) forard slash as a cursor, you are using standard 2$= Math input. f the cursor is a (non$italici8ed)vertical line, you are set to do Maple nput and you should go to the +ools@5ptions menu item, choose the =isplay tab, andthen choose 2$= Math 9otation on the nput =isplay line. 9o you are ready to program. -ear in mind that much of hat
follos is only directly applicable to 6or%sheet Mode and sometimes only to 2$= Math input. 3ou should also 9>V>:
create a =ocument -loc%.
)tatements and %#ecution roups
Maple programming is bro%en into !statements" hich, in turn are grouped into !e*ecution groups". &n e*ecution group
is indicated on the left hand side of the or%sheet by a large s?uare brac%et encompassing the group and all its output. &
statement is a group of ords and mathematical e*pressions hich ends in a !separator" hich is either a semi$colon or a
colon. & statement can be spread over any number of lines, and all or parts of any number of statements can be on one
line. 5f course, a statement must be in a synta* that Maple can ma%e sense of, that is, hich it can !parse". Maple doesthe parsing internally, you on;t see it. Aarsing is li%e ta%ing a sentence apart into its grammatical components. f the
separator is a semi$colon and if the statement has output, Maple ill print the output of the statement at the bottom of the
e*ecution group hen the e*ecution group is !e*ecuted". f the separator is a colon, Maple ill not print the output of the
statement even if the statement produces output. t is often useful to prevent Maple from printing unnecessary or
voluminous intermediate output by using the colon. !>*ecution" of a statement means that Maple does the calculations
and tas%s indicated.
& statement must be entirely !nested" ithin one e*ecution group. oever, there can be many statements in any
e*ecution group. +his is the ay to tell Maple to !e*ecute" all the statements in an e*ecution group ithout aiting for
any additional input from you. 3ou may ish to have fe or even one statement per e*ecution group hen you start to
program the solution of a particular problem in order to see if each statement is doing hat you e*pect. +hen, hen you
are confident the individual statements are behaving as you e*pect, you might combine statements into many feere*ecution groups (by cut and paste) so you have to spend less time !e*ecuting" individual statements.
f you simply %eep typing on a line, Maple ill automatically rap hat you are typing to the ne*t line in the same
e*ecution group. oever, this ay of entering statements ma%es the logical structure of the input very hard to discern.
3ou ant to put long statements and multiple statements on the page in such a ay that their logical connection is easiest
to discern. +his means that you ant to indent various lines more or less. t also means that you ant to end a line
manually at a logical place and continue on the ne*t line in the same e*ecution group at an indented position before Maple
automatically raps the line at a less logical place. 3ou do this by entering a hift$>nter here you ant to end the line.
3ou e*ecute the statements in an e*ecution group by one of to methods. n all methods the cursor must be inside the
e*ecution group. 3ou can either simply press >nter, or you can clic% the B$icon in the toolbar. 3ou can e*ecute all the
e*ecution groups in the or%sheet by clic%ing the BBB$icon.
3ou can start a ne e*ecution group in essentially three ays. +he first is to e*ecute on e*isting e*ecution group. f there
is already an e*ecution group after it, the cursor moves to the ne*t e*ecution group. f there is no e*isting e*ecution group
after the e*ecuted group, a ne e*ecution group is created. &lso, a ne e*ecution group can be created 'ust before or 'ust
after the current e*ecution group here the cursor resides by going to the nsert menu tab and choosing !>*ecution
roup", hereupon you ill be presented ith a !-efore ursor" or !&fter ursor" choice. inally, at ne e*ecution
group can be created 'ust after the current e*ecution group by clic%ing the !prompt" tool icon !CJ".
3ou can get rid of an entire e*ecution group (and its output) or a te*t regions (see belo) by highlighting it (and its
accompanying output) and choosing =elete >lement in the >dit menu.
Page 4 of 15
-
7/25/2019 Maple Basics
5/15
/ata )tructures and the ,ssignment )tatement
+he first important thing that a computer language does is store information under understandable names. +his ay, once
the information is stored, it can be reused any number of time by simply referring to the name rather than re$entering the
data. Maple is particularly poerful in this respect because it can %eep related data in many %inds of data structuresso
that it is clear ho the different elements of the data are related to each other, and the !data" do not have to be numbers
but may be entirely composed of symbols. +a%e for instance an algebraic e*pression li%e aK*rL bK*. +his e*pression could
be stored under the name !?", and Maple ould store the role each symbol plays. +hen if numerical values are assigned to
the symbols and Maple is as%ed for the value of ?, Maple ill %no e*actly ho to compute it.
+he %ind of statement hich carries out this storing operation is an assignment statement. t is a basicprogramming
structuret is indicated by the presence of the !colonFe?ual" symbol or !". t has the form
Nsome nameJ Nsome mathematical e*pression involving other named structures and Maple functionsJ
C9ote that here and in many other programming instructions, the angle brac%ets, !N...J", contain e*planations of hat
should replace the angle brac%ets in the actual Maple code, although the angle brac%ets themselves are not included in the
code. +he e*planation itself is not hat replaces the angle brac%ets.
6hen e*ecuting this statement, Maple first evaluatesthe right hand side (rhs) and then stores the result under the name
indicated on the left. +his order of first evaluation and then storing is very important. t is not an e?uation. +hus & &L1is a perfectly logical statement. 9ote that named structures might be called variables, but are often ay beyond hat is
usually called a variable in mathematics since they often represent a much more complicated entity than an un%non
number or even vector. +o evaluatesan e*pression means to replace all symbols ith any values that have been assigned
to them in previously e*ecuted statements and then to do as much calculation as possible. or e*ample, if !a" had been
assigned the value # but !b" had not been assigned a value, then 8 2Oa L b ould cause Maple to store the e*pression
PLb under the name 8.
0iewing and 1aming /ata )tructures
+o see the contents of a named structure, e*cept for procedures (see belo), 'ust type the name of the structure folloed
by a semi$colon. +he nops( ) and op( ) functions provide more information about the structure. (ee ection V belo.) or
procedures, one enters eval(Nprocedure nameJ). or vieing large matrices or vectors, i.e., larger that 10*10, see VieingMatrices in ection V.
9ames of data structures can have letters and digits and the underscore character, Q, but they must start ith a letter. +hey
can be much longer than anyone ould find useful. 9ames are case sensitive, that is, names ith the same se?uence of
letters and digits but ith different combinations of loer case and upper case are considered to different names. 9ames
should be mnemonic (hich comes from a ree% ord for !remember"), that is, they may be abbreviations, but they
should immediately remind one of the mathematical or economic concept to hich they refer. +o ma%e names mnemonic,
it often helps to build them from more than one ord, such as 9AQannual. 9otice that the underscore has been used to
ma%e the individual ords more obvious and thus the name more immediately readable. 3ou should also name related
data structures ith clearly systematically related names.
The worksheet versus the omputing %ngine versus %#ecution
-efore e can tal% about actually programming, e need to describe the split in the Maple system beteen the or%sheet
(/) and the computing engine (called the %ernel). omputing is done by the %ernel and data structures are stored or
changed or printed by the %ernel only hen an e*ecution group is !e*ecuted". >*ecution groups can be e*ecuted
anyhere on the or%sheet, at any time, and in any order. tatements can be edited, deleted, or added to the or%sheet in
any e*ecution group, at any time, and in any order. hanging, deleting, or adding statements or e*ecution groups does not
by itself cause e*ecution of anything or change the output printed on the or%sheet in an e*ecution group. +hus the
or%sheet and the %ernel are really very independent. f you loo% at a or%sheet after it has been or%ed ith for a hile,
then, if the user has not been orderly about hat has been done and %ept trac% of it in some ay, it ould be impossible to
tell hat input produced hat output and by hat path.
Page 5 of 15
-
7/25/2019 Maple Basics
6/15
+his independence of the or%sheet and the computing engine is useful in many ays because it ma%es it very easy to
!play ith a problem". +o try a slightly different approach, you do not have to retype a lot of statements, you 'ust need to
edit the e*isting statements and !re$e*ecute". +he ne output ill replace the old output. oever, hen you finally
believe you have a good ay of accomplishing a tas%, it means that you have to !clean up the or%sheet", that is, ma%e it
more orderly and !documented" so that it can serve as a !report" of the solution. Aarticular attention has to be paid to
situations here one needs to report on a comparison of various methods or beteen various sets of data. +hus producing
a finished product is really divided into to stages =evelopment and =ocumenting. +he cleaning up or documenting
operation is covered in ection V, tructuring and =ocumenting your 6or%, belo. irst, more of the development part
of programming is discussed.
2asic 3rogramming )tructures
n addition to the assignment statement, there are three fundamentalprogramming structures. & program=ming structure
is a routine set of phrases hich encapsules a se?uence or se?uences of statements and hich tells Maple ho to treat
these se?uences of statements. +he three fundamental programming structures are the if4block, the loop, and the
procedure. <hough the synta* of these structures differs among different programming languages, these three structures
plus the assignment structure are the four fundamental programming structures of all programming languages.
&n if4blockis a decision structure. t allos the program to ma%e a test or se?uence of tests to determine hich set of
statements should be e*ecuted. t is indicated by the phrases !if Ncondition1J then ... elif Ncondition2J ... else ... end if"
here ... indicates any number of statements (and the ?uotes are not part of the code).
& loop(or repetition) structure directs the program to e*ecute a se?uence of statements repeatedly, each time ith a
different value for one or more variables or named structures. t is indicated by the phrases !for Nloop variableJ from
Nbeginning valueJ to Nending valueJ do ... end do"
&procedureessentially defines a function, that is, it tells the program to store a set of statements under a name hich can
then be e*ecuted together at other desired points in the program in the manner of a mathematical function hen theprocedure is called, that is used, by entering its name and then values for its arguments in parentheses directly after its
name as part of a statement. & procedure definition is indicated by the phrases !NnameJ proc( Nsymbolic arguments for
the procedure 'ust li%e for a functionJ) ... end proc".
+he details of these structures are referenced in ection V belo under Arogramming tructures and ommands.
Arocedures are not only programming structures that the user can create, but many procedures have been created and
supplied by Maple itself. Most of Maple;s procedures are, in fact, procedures ritten in Maple code hich you can vie
ith the command eval(Nfunction nameJ). ince Maple has such a vast array of procedures available, it does not load the
code for all these procedures into memory hen a Maple session first starts. 5nly a basic set of procedures is initially
loaded. +he remaining large group of procedures is organi8ed intopackages. n order to access a procedure in one of these
pac%ages, the user has to either use the long formof a procedure;s name hich is prefi*ed by the pac%age name or load
the hole pac%age (or a subset of its procedures) into memory using the withcommand. 6hen a procedure is in a
pac%age, the pac%age name and the long form of the procedure;s name is given on its help page.
&ll of these four programming structures can be nestedinside themselves and each other. +he term nested means that the
nested structure must be totally contained in a part of the other structure here se?uences of statements can be put. 6henstructures are nested in other structures, it is said that the nested structures are at a deeper levelin the program. +his notionof level is used in numerous help pages.
t is also very important that indention be properly used ith these structures so that the logic of the program is easily
identified visually. +he se?uence(s) of statements in each structure should be indented. &lso, hen one programming
structure is nested in another, the nested structure should be indented along ith the statements ith hich it is included,
and then the statements in the nested structure should be indented still more. +he system of indention should, then, clearly
indicate the logical level of various parts of the program.
)pecial Methods for %ntering some Mathematics
Page 6 of 15
-
7/25/2019 Maple Basics
7/15
-
7/25/2019 Maple Basics
8/15
)ome 2asic 3rogramming 3rinciples
inally, e come to some principles ofprogrammingin general.
+heprimary principle of programmingis
*nderstand how to solve a problem conceptually! logically! and mathematically beforeyou start programming.9>V>: start solving a problem by starting to program. Snoing ho to solve a problem conceptually, logically, and
mathematically is 95+ a programming problem. 59> you understand the mathematical solution to the problem,+>9 you can start to translate the mathematics into computer codeO. You solvethe problem,Maple implementsthe
solution. :eversing this order leads to frustration and chaos. &s they say !=on;t put the cart before the horse".
(Oomputer code is the ord for all or any part of hat you rite on a or%sheet.)
5f course, you may ant to try various potential methods of solution. 3ou may not even be sure that hat you thin% is
a solution is really a solution. +hat is 5S, you are alloed, even encouraged, to e*periment. 5ne of the strong points
of Maple is that it allos you to easily try numerous possibilities. 9onetheless, you should %no, at each point of the
development of your solution, hat you ant to try mathematically before you start programming. 9o amount of
programming or programming s%ill or e*perience can ma%e the mathematics sensible if it is not sensible !arbage in
garbage out".
5ther principles for programming are *se symbolic names liberally.
n most of your Maple code, you ant to use a symbolic name for most entities (that is, data structures). +here are to
reasons for this (1) +his ma%es it more apparent hat the components going into e*pressions mean. (2) 6hen youma%e a change in the value of a variable or parameter in the code, you only have to ma%e the change once.
9o, to types of circumstances arrive in carrying out this principle.
+he first circumstance is here a set of symbolic names on the right hand side of an assignment are used to define
another symbolic entity, but essentially no calculations are being done. or instance, defining the functional form of
the utility function. n this case, one ants to give numerical values to parameters and variables only after such
definitions so that the defined entity is stored as its symbolic definition. n order to ma%e sure this is hat happens, it
is necessary to put a special Maple statement before entering the symbolic definition. +he command to enter isunassign(Na se?uence of the parameters to unassign, separated by commas, ith each parameter surrounded by
apostrophesJ). +hen henever it is evaluated after giving the parameters and variables values, it is evaluated using
the latest values assigned to the parameters and variables. f the parameters and variables are given values first, then
the definition is hardcoded (i.e., stored) ith those values, and changing the values of the parameters and variables
later ill not change the evaluated value of the defined entity.
+he second circumstance arrives in doing computations or plots here the parameters and variables must have
numerical values. n that case, one needs to assign values to parameters and variables before the computation is done.
+he to circumstances both come into play hen one needs to assign values after some definitions but before othercalculations. (9ote +he eval() and subs() functions are useful for assigning numerical values to variables temporarily
during a calculation. &lso values can be unassigned from variables using the unassign() function.)
6eep the names of variables9 (as opposed to parameters9" clean! that is! unassigned. *se subs! eval! and evalfliberally! instead.
(O+here is no rigorous distinction beteen !variables" and !parameters", but, roughly, parameters are variables that
change much less fre?uently hile analy8ing a situation.) &lso, you can use related names for various numerical
values of a variable, hen you ant to %eep the name of the variable itself symbolic, hich you often do. or
e*ample, the symbolic name folloed by an underscore and a suffi*, such as *Q0 or *QsolQ1.
8or all linear algebra work use the :inear,lgebra (:," package along with the 0ectoralculus (0" package. The:inear,lgebra package has the ability to understand the usual matri# algebra e#pressions directly.
Page 8 of 15
-
7/25/2019 Maple Basics
9/15
or information on ho to state matri* algebra e*pressions, see the help page on algebra in ection V. n addition to
its ease in using matri* algebra e*pressions, the Tinear&lgebra pac%age also uses superior numerical calculation
routines. (+he other linear algebra pac%age is the linalg pac%age. t does have some usefulness in con'unction ith the
T& pac%age, but combining the to usefully is rather subtle and re?uires much e*perience. +he functions used by the
to pac%ages are often distinguished by the presence of an initial capital letter in the T& pac%age function names,
such as, Matri*( ) for T& and matri*( ) for linalg.)
*se procedures for blocks of code that get repeated with different values for parameters and variables.
-y using procedures, you ill only have to proofread and debugO that section of code once. (O=ebugging is the
process of finding and correcting errors, traditionally called !bugs", in computer code. -e sure to loo% at the
debugging information in ection V.)
/ont be afraid to e#periment.
=on;t be afraid to e*periment ith code, even if you are not completely sure hat it ill do. ometimes help pages
are not completely clear. (Maybe they are alays not completelyclearB) 6ell, use imagination and try the possibilities
that occur to you. -ut you do ant to be systematic. 3ou ant to try things in some order. 3ou ant to try things that,
under some interpretation, might be logical. 3ou do notant to 'ust randomly try things.
)ave! )ave! )ave.
3ou ant to fre?uently save your or%, so that if something happens and the computer andFor or%sheet !free8es",
you only have to redo a relatively small amount of or%.
I). Structuring an# *ocumenting your +or,
The /evelopment stage versus the /ocumenting )tage
&s indicated above (in ection ), there are to ma'or stages in accomplishing a tas% ith Maple +he development
stage and the documenting stage.
+he first stage is the development stage. ere you e*periment to find a or%able solution or ma%e useful comparisons.+his is the !playing around, messing around" stage. >ven here, though, you ill ant to do some documenting so that you
don;t forget hat your various pieces of code are attempting to do and hat is stored in your data structures.
+he second stage, the documenting stage, starts hen your final solution starts to become clear and is %non to or%.
ere you ant to ma%e sure that your or%sheet can serve as a clear, professional report or presentation. or this to be
true, another person has to be able to understand hat you are doing and hy and be able to duplicate it if desired. list
belo a number of techni?ues for doing this and a number of items to hich you should pay particular attention.
omments and Te#t Regions
5ne important documenting techni?ue is to place items of te#tof various levels around your or%sheet hich tell the
reader hat is going on. -y te#t, mean ords and symbols hich ill not be e*ecuted by Maple. +hese are solely for thereader, Maple ignores them and has no understanding of hat is in them. +he different levels of +e*t items have differentpositions around e*ecutable Maple code.
+he smaller and most ubi?uitous te*t item is the comment. +his starts ith the number sign (U) and can go on any line,
even after code. +his is meant to give a short local piece of information, pertaining perhaps to no more than a single
statement. +he comment is entered in the same fashion as code, that is, as Maple input, so that it could loo% li%e code, but
the number sign and everything after it on the same line is ignored and not e*ecuted by Maple hen the e*ecution group
is e*ecuted.
+he higher level of te*t item is the te#t region. +his ta%es up a hole group by itself indicated by a brac%et on its left (li%e
Page 9 of 15
-
7/25/2019 Maple Basics
10/15
an e*ecution group) but ithout a prompt. t is meant to give information pertaining to the hole or%sheet, a ma'or part
of it, or maybe simply one e*ecution group. uch a region can be inserted 'ust after any e*ecution group by clic%ing the
!+e*t" tool icon !+". &lso an empty e*ecution group can be turned into a te*t region by choosing the te*t item in the
nsert many. & te*t region is ritten mostly as Maple +e*t. +his is more li%e hat you ould get from a ord processor,
so that, for e*ample, fonts and font si8es and attributes can be changed. oever, you can sitch bac% and forth from
Math to +e*t using the menu buttons at the top of the or%sheet. +hus you can rite good loo%ing and easily
understandable math in a te*t region. 9onetheless, Math entered in this ay in a te*t region is never e*ecuted it is simply
for the human reader.
=o not attempt to insert a !paragraph" from the nsert menu. +hat ill only lead to confusion and difficulties.
Information that 1eeds to be /ocumented by Te#t
ome of the important pieces of information that the te*t items should convey are the title of the or%sheet, the authors
name, the date of the or%sheet, headings that divide the or%sheet into logical parts (using perhaps different font si8es),
the purposes of the or%sheet as a hole and of its various parts, e*planations of ho the or% is being done,
'ustifications for various steps and methods, and the meaning of variables and descriptions of hat is contained in the data
structures that are used. +hus the te*t items are the road signs leading the reader (and actually you, too) through the
or%sheet.
Indention
6ithin the e*ecutable code part of the or%sheet, indention is very important for ma%ing the logic of the code readily
apparent hen reading it. ndent continuation lines so that their subordinate nature is clear. (6hen lines need to be
continued, brea% them at a logical point ith shift$enter and do not 'ust let them rap at some random point.) ndent the
statement se?uence parts of do$loops, if$bloc%s, and procedures so that their logical subordination to the structural parts
(for ... do, end do, if ... then, elif ... then, else, end if, proc, end proc) is visually evident. 6hen these programming
structures are nested ithin each other, their indented parts are indented still more relative to the level of indention of their
structural parts.
*sing %$uations and 1on4%valuation Indicators to Identify uput
>ach item of output needs to be easily identified ithout having to constantly loo% bac% in the code to see hat the nth
output item represents. f the statement producing the output is an assignment statement, Maple usually outputs the lefthand name as ell as the right hand values to be assigned to the name. oever, there are circumstances here you ill
ant to output the value of an already calculated value for comparison or here you have no need to save the output. n
these cases, to identify the output you need to put a name ith unevaluation ?uotes (that is, apostrophes) around it or a
name as an argument to evaln( ) to the left of an e?ual sign (that is, 'ust !" not the !" used for assignments) ith the
original right hand side e*pression to the right of the e?ual sign. +his forms a Maple e?uation (one of Maple;s data
structures), hich you aren;t going to store. +hen hen Maple prints the e?uation you get your identification. +he left
hand side of the e?ual sign could also be any te*t enclosed in single bac%?uotes () Csee help page for !name"D.
Including ,ll the Input and utput oncisely
6hen the problem involves comparing results ith various methods andFor values, it is important that the final
documented or%sheet actually shos all the inputs and their corresponding outputs so that it is clear e*actly ho each ofthe results ere produced. n this conte*t, it is often important to remember to use procedures hen the same process isbeing done but ith different values. &s stated before, this means that only one sample of the repeated code needs to be
proofread. -ut in the conte*t of documenting a or%sheet, using procedures also means that, in the places in the
or%sheet here comparisons are being made, the code is often much shorter and more meaningful, alloing us to see (as
the saying goes) the forest instead of the confusion of a lot of trees. +he code in the procedure has been reduced to one
logical step. +his using of procedures also means that the different results are closer together and not hidden in a large
amount of code. +he results are thus easier to visually identify and compare.
Page 10 of 15
-
7/25/2019 Maple Basics
11/15
). Important Basic -omman#s an# Other Elements to Loo, up in the "elp System
9otation C...D give a topic name. G...H gives a toc location.
() indicates a Maple function. =o not include the parentheses hen using as a topic name.
(...) gives an e*planatory note.
%&I '%raphical &ser Interface( Structures
restart
menus
Cor%%sheet,reference,standardDor%sheet modeC/serManual,hapter0#D
Cor%sheetD
Cor%sheet,e*pressionsD
Cor%sheet,documentingD
toolbar (point to a tool ith cursor to see its
function)
conte*t menus
Cor%sheet,e*pressions,manipulatecsmD
statement
CseparatorD
Cor%sheet,e*pressions,enteringDCor%sheet,documenting,2=MathhortcutSeysD
Cor%sheet,documenting,2=Math=etailsD
continue a statement or start a ne statement on the ne*t
line in the same e*ecution group
( shiftLenter)
Cor%sheet,reference,hotinD
e*ecution group
Cor%sheet,documenting,e*ecutiongroupsD
Cor%sheet,e*pressions,e*ecuteselectionDCor%sheet,e*pressions,e*ecuteor%sheetDcomment (on same line as statement)
+e*t :egion (in separate non$e*ecutable
group set off by brac%et on left)
GManuals@/ser Manual@6or%sheet ModeH
2$= math input
Cor%sheet,documenting,2=mathD
Cor%sheet,documenting,2=Math=etailsD
Cor%sheet,documenting,2=MathhortcutSeysD
drag W drop
Cor%sheet,e*pressions,movee*pressionD
palettes Cor%sheet,e*pressions,palettesD
entering fractions and the underscore
C+utorial,Mathpitfall
Page 11 of 15
-
7/25/2019 Maple Basics
12/15
*ata Structures
name
string
integer
decimal number floating point number CfloatD
boolean
e?uation,ine?uality Ce?uationD
range
set, list CsetD
table
nde*ed 9ame
polynomial CpolynomD
&rray( )
Vector( ),Matri*( )
Vector W Matri* input shortcuts
CTinear&lgebra,eneral,MVshortcutD
rtableQinde*ingvieing &rrays, Vectors, and MatricesCor%sheet,e*pressions,structuredvieD
Programming Structures an# -omman#s
programming
GArogrammingH,GArogramming@lo ontrolH
Gprogramming@@9ames and trings@statementH
assignment
unassign( )
if$bloc% (decision) CifDloop CdoD
procedure CprocedureD,Coperators,functionalD
function
pac%ages CithD
print( )
plot( ) CplotD,Cplot#dD,Cplot,parametricD
plots pac%age CplotsD
plottools pac%age CplottoolsD
eval( ), evalb( )
evalf( ), evalc( )
evaln( )uneval( ), single ?uotes X CunevalD, evaln( )
ditto
bac%slash
lhs( ), rhs( )
cat( )
@@ (concatenation operator)
se?( )subs( )
op( ),nops( ) CopD
select, remove, selectremove CselectD
Page 12 of 15
-
7/25/2019 Maple Basics
13/15
map( )
Map() CTinear&lgebra,MapD
convert( )
debug( ) CtraceD, CdebuggerD
try
Mathematics
arithmetic operators (L, $, O, F, R) CarithopD
composition of functions CYD
abs( )
e*p( )ln( )sin( ) (trig functions) CtrigD
diff( ), =( )
nt( )
sum( )
product( )
add( ),mul( ) CaddD
numer( ), denom( ) CnumerD
solve( ) (symbolic)
fsolve( ) (numerical)
dsolve( ) (solve differential e?ns)
=>tools pac%age (=>=ifferential >?ns) C=>toolsD
normal( )
simplify( )
e*pand( )
combine( )
factor( )
polynomial, collect( ), sort( ), coeff( )pac%ages GMathematics@Aac%agesH
Tinear &lgebra pac%age
CTinear&lgebraD
GMathematics@Tinear &lgebra@Tinear
&lgebra Aac%ageH GMathematics@Tinear &lgebra@Tinear&lgebra Aac%age@&lgebra or onstructors
or =ata tructures or >ntry 5perations
or Iueries or olvers or tandard
or ub5perations or unctional alculus
or >igenvalues
or Arogramming@>fficient omputationH
tatistics pac%age
CtatisticsD, GMathematics@tatisticsH
Vectoralculus
CVectoralculusD,
GMathematics@Vector alculusH:andom+ools pac%age
C:andom+oolsD,
GArogramming@:andom 5b'ects@:andom +ools
pac%ageH
rand()
randomi8e()
Page 13 of 15
-
7/25/2019 Maple Basics
14/15
-
7/25/2019 Maple Basics
15/15
)I. Play Aroun# +ith ... Mess Aroun# +ith ... Maple
&t this point you are ready to start using Maple to solve problems. +hat is really the only ay to learn. 5nly hands on
or% ith Maple ill improve your ability ith it. &nd hands$on or% means playing around ith, messing around ith,
Maple. =o not ta%e the position that if you do not %no e*actly hat to do, you shouldn;t do anything. 3ou need to try
and e*periment.
&lso remember, you are not 'ust learning to use one programming language, Maple. 3ou are learning ho to do
programming, and learning ho to use programming to solve problems. & great part of hat you learn can be applied to
every other programming language.