Download ebooks file Maple 9 advanced programming guide 1st Edition Monagan all chapters
Download ebooks file Maple 9 advanced programming guide 1st Edition Monagan all chapters
https://ebookfinal.com/download/sas-certification-prep-guide-advanced-
programming-for-sas-9-fourth-edition-sas-institute/
https://ebookfinal.com/download/sas-certification-prep-guide-base-
programming-for-sas-9-third-edition-sas/
https://ebookfinal.com/download/advanced-3d-game-programming-with-
directx-9-wordware-game-developer-s-library-600th-edition-peter-walsh/
https://ebookfinal.com/download/programming-ruby-1-9-2-0-the-
pragmatic-programmers-guide-fourth-edition-dave-thomas/
Advanced Graphics Programming Using OpenGL 1st Edition Tom
Mcreynolds
https://ebookfinal.com/download/advanced-graphics-programming-using-
opengl-1st-edition-tom-mcreynolds/
https://ebookfinal.com/download/advanced-programming-using-visual-
basic-2008-4th-edition-julia-case-bradley/
https://ebookfinal.com/download/base-sas-9-2-procedures-guide-1st-
edition-sas-publishing/
https://ebookfinal.com/download/getting-started-with-advanced-c-
upgrade-your-programming-skills-1st-edition-vaskaran-sarcar/
Maple 9 advanced programming guide 1st Edition
Monagan Digital Instant Download
Author(s): Monagan, Geddes, Heal, Labahn, et al.
ISBN(s): 9781894511445, 1894511441
Edition: 1
File Details: PDF, 2.25 MB
Year: 2003
Language: english
Maple 9
Advanced Programming
Guide
M. B. Monagan K. O. Geddes K. M. Heal
G. Labahn S. M. Vorkoetter J. McCarron
P. DeMarco
c Maplesoft, a division of Waterloo Maple Inc. 2003.
ii •
c Maplesoft, a division of Waterloo Maple Inc. 2003. All rights re-
served.
Printed in Canada
ISBN 1-894511-44-1
Contents
Preface 1
Audience . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
Worksheet Graphical Interface . . . . . . . . . . . . . . . . . . 2
Manual Set . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
Conventions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
Customer Feedback . . . . . . . . . . . . . . . . . . . . . . . . . 3
iii
iv • Contents
Power . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 414
Procedure Definition . . . . . . . . . . . . . . . . . . . . . 414
Product, Quotient, Power . . . . . . . . . . . . . . . . . . 416
Range . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 416
Rational . . . . . . . . . . . . . . . . . . . . . . . . . . . . 416
Read Statement . . . . . . . . . . . . . . . . . . . . . . . . 417
Return Statement . . . . . . . . . . . . . . . . . . . . . . 417
Rectangular Table . . . . . . . . . . . . . . . . . . . . . . 417
Save Statement . . . . . . . . . . . . . . . . . . . . . . . . 419
Series . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 419
Set . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 419
Statement Sequence . . . . . . . . . . . . . . . . . . . . . 420
Stop Maple . . . . . . . . . . . . . . . . . . . . . . . . . . 420
String . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 420
Sum, Difference . . . . . . . . . . . . . . . . . . . . . . . . 421
Table . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 421
Table Reference . . . . . . . . . . . . . . . . . . . . . . . . 421
Try Statement . . . . . . . . . . . . . . . . . . . . . . . . 422
Unevaluated Expression . . . . . . . . . . . . . . . . . . . 422
Use Statement . . . . . . . . . . . . . . . . . . . . . . . . 422
Logical XOR . . . . . . . . . . . . . . . . . . . . . . . . . 423
Polynomials with Integer Coefficients modulo n . . . . . . 423
A.3 The Use of Hashing in Maple . . . . . . . . . . . . . . . . 424
Basic Hash Tables . . . . . . . . . . . . . . . . . . . . . . 424
Dynamic Hash Tables . . . . . . . . . . . . . . . . . . . . 425
The Simplification Table . . . . . . . . . . . . . . . . . . . 426
The Name Table . . . . . . . . . . . . . . . . . . . . . . . 427
Remember Tables . . . . . . . . . . . . . . . . . . . . . . . 427
Maple Language Arrays and Tables . . . . . . . . . . . . . 428
Maple Language Rectangular Tables . . . . . . . . . . . . 429
A.4 Portability . . . . . . . . . . . . . . . . . . . . . . . . . . . 429
Index 431
Preface
• Numerical programming
Audience
This manual provides information for experienced Maple programmers.
You should be familiar with the following.
• Example worksheets
1
2 • Preface
Manual Set
There are three other manuals available for Maple users, the Maple Get-
ting Started Guide, the Maple Learning Guide, and the Maple Intro-
ductory Programming Guide.2
• The Maple Learning Guide explains how Maple and the Maple lan-
guage work. It describes the most important commands and uses them
to solve technical problems. User hints for Maplet applications are also
described in this guide.
The Maple software also has an online help system. The Maple help sys-
tem allows you to search in many ways and is always available. There are
also examples that you can copy, paste, and execute immediately.
1
The command-line version provides optimum performance. However, the worksheet
interface is easier to use and renders typeset, editable math output and higher quality
plots.
2
The Student Edition does not include the Maple Introductory Programming Guide
and the Maple Advanced Programming Guide. These programming guides can be pur-
chased from school and specialty bookstores or directly from Maplesoft.
Conventions • 3
Conventions
This manual uses the following typographical conventions.
Customer Feedback
Maplesoft welcomes your feedback. For suggestions and comments related
to this and other manuals, email [email protected].
4 • Preface
1 Procedures, Variables,
and Extending Maple
Prerequisite Knowledge
Before reading this chapter, you must have an understanding of Maple
evaluation rules for variables and parameters as described in chapter 6 of
the Introductory Programming Guide.
In This Chapter
Nested Procedures You can define a Maple procedure within another
Maple procedure.
Local Variables Local variables can exist after the procedure which cre-
ated them has exited. This feature allows a procedure to return a proce-
dure. The new procedure requires a unique place to store information.
5
6 • Chapter 1: Procedures, Variables, and Extending Maple
1 1
[1, , , 2]
2 4
Example This new procedure divides each element of a list by the first
element of that list.
> nest := proc(x::list)
> local v;
> v := x[1];
> map( y -> y/v, x );
> end proc:
> nest(lst);
1 1
[1, , , 2]
2 4
Scoping Rules
This section explains Maple scoping rules. You will learn how Maple de-
termines which variables are local to a procedure and which are global.
You must have a basic understanding of Maple evaluation rules for pa-
rameters, and for local and global variables. For more information, refer
to chapter 6 of the Introductory Programming Guide.
8 4 2 16
[ , , , ]
v v v v
If, using the above rule, Maple cannot determine whether a variable
is global or local, the following default decisions are made.
Example
The partition procedure uses an array to store the list because you can
change the elements of an array directly. Thus, you can sort the array in
place and not waste any space generating extra copies.
The quicksort procedure is easier to understand if you look at the
procedure partition in isolation first. This procedure accepts an array
of numbers and two integers. The two integers are element numbers of the
array, indicating the portion of the array to partition. While you could
possibly choose any of the numbers in the array to partition around, this
procedure chooses the last element of the section of the array for that
purpose, namely A[n]. The intentional omission of global and local
statements shows which variables Maple recognizes as local and which
are global by default. It is recommended, however, that you not make
this omission in your procedures.
> partition := proc(A::array(1, numeric),
> m::posint, n::posint)
> i := m;
> j := n;
> x := A[j];
> while i<j do
> if A[i]>x then
1.1 Nested Procedures • 9
a := [2, 4, 1, 5, 3]
[2, 1, 3, 5, 4]
[2, 1, 3, 5, 4]
a := [2, 4, 1, 5, 3]
1.1 Nested Procedures • 11
[1, 2, 3, 4, 5]
> eval(a);
[1, 2, 3, 4, 5]
5, 6, 5, 7, 4, 6, 5, 4, 5, 5, 7, 7, 5, 4, 6, 5, 4, 5, 7, 5
6.648630719
0.828316845400000, −0.328875163100000,
0.790988967100000, 0.624953401700000,
0.362773633800000, 0.679519822000000,
−0.0465278542000000, −0.291055180800000
The proper design choice here is that U should depend only on the
value of Digits when you invoke U. The following version of uniform
accomplishes this by placing the entire computation inside the procedure
that uniform returns.
> uniform := proc( r::constant..constant )
>
> proc()
> local intrange, f;
> intrange := map( x -> round(x*10^Digits),
> evalf(r) );
> f := rand( intrange );
> evalf( f()/10^Digits );
> end proc;
> end proc:
0.476383408581006, 0.554836962987261,
0.147655743361511, 0.273247304736175,
0.148172828708797, −0.258115633420094,
0.558246581434993, 0.518084711267009
Note: The interface variable displayprecision controls the number of
decimal places to be displayed. The default value is −1, representing full
precision as determined by the Digits environment variable. This sim-
plifies display without introducing round-off error. For more information,
refer to ?interface.
14 • Chapter 1: Procedures, Variables, and Extending Maple
Conveying Values
The following example demonstrates how locating the roots of a function
by using Newton’s method can be implemented in a procedure.
1. Choose a point on the x-axis that you think might be close to a root.
3. Draw the tangent to the curve at that point and observe where the
tangent intersects the x-axis. For most functions, this second point is
closer to the real root than your initial guess. To find the root, use
the new point as a new guess and keep drawing tangents and finding
new points.
1.2 Procedures That Return Procedures • 15
2
1.5
1
0.5
x0 x1
0 1 2 3 4 5 6 7 8
–0.5 x
–1
1. Newton’s method
f (xk )
xk+1 = xk −
f 0 (xk )
Example 1
The following procedure takes a function and creates a new procedure,
which takes an initial guess and, for that particular function, generates
the next guess. The new procedure does not work for other functions. To
find the roots of a new function, use MakeIteration to generate a new
guess-generating procedure. The unapply command turns an expression
into a procedure.
> MakeIteration := proc( expr::algebraic, x::name )
> local iteration;
> iteration := x - expr/diff(expr, x);
> unapply(iteration, x);
> end proc:
x0 := 2.0
x0 := 4.828427124
x0 := 4.032533198
x0 := 4.000065353
x0 := 4.000000000
Example 2
The MakeIteration procedure requires its first argument to be an al-
gebraic expression. You can also write a version of MakeIteration that
works on functions. Since the following MakeIteration procedure recog-
nizes the parameter f as a procedure, you must use the eval command
to evaluate it fully.
> MakeIteration := proc( f::procedure )
> (x->x) - eval(f) / D(eval(f));
> end proc:
> g := x -> x - cos(x);
g := x → x − cos(x)
x → x − cos(x)
SirIsaac := (x → x) −
x → 1 + sin(x)
1.2 Procedures That Return Procedures • 17
x0 := 1.0
x0 := 0.7503638679
x0 := 0.7391128909
x0 := 0.7390851334
x0 := 0.7390851332
A Shift Operator
Consider the problem of writing a procedure that takes a function, f , as
input and returns a function, g, such that g(x) = f (x + 1). You can write
such a procedure in the following manner.
> shift := (f::procedure) -> ( x->f(x+1) ):
x → sin(x + 1)
Maple lexical scoping rules declare the f within the inner procedure
to be the same f as the parameter within the outer procedure. Therefore,
the shift command works as written.
The previous example of shift works with univariate functions but
it does not work with functions of two or more variables.
> h := (x,y) -> x*y;
h := (x, y) → x y
> hh := shift(h);
18 • Chapter 1: Procedures, Variables, and Extending Maple
hh := x → h(x + 1)
> hh(x,y);
> hh := shift(h);
hh := x → h(x + 1, args2..−1 )
> hh(x,y);
(x + 1) y
y z2
h := (x, y, z) →
x
> hh(x,y,z);
y z2
x+1
1.3 Local Variables and Invoking Procedures • 19
Example 1
The following procedure creates a new local variable, a, and then returns
this new variable.
> make_a := proc()
> local a;
> a;
> end proc;
By using local variables, you can produce displays that Maple would
otherwise simplify. For example, in Maple, a set contains unique elements.
The following demonstrates that each variable a that make_a returns is
unique.
> test := { a, a, a };
test := {a}
test := {a, a}
test := {a, a, a, a, a, a, a}
20 • Chapter 1: Procedures, Variables, and Extending Maple
Example 2
You can display expressions that Maple would ordinarily simplify au-
tomatically. For example, Maple automatically simplifies the expression
a + a to 2a. It is difficult to display the equation a + a = 2a. To display
such an equation, use the procedure make_a from Example 1.
> a + make_a() = 2*a;
a + a = 2a
eqn := a + a = 2 a
another _a := a
You can then assign the global name a to this extracted variable and
verify the equation.
1.3 Local Variables and Invoking Procedures • 21
2a = 2a
> evalb(%);
true
Assume Facility For complicated expressions, you must use the assume
command to extract the desired variable. You may have encountered this
situation before without realizing it, when you were using the assume
facility to remove an assumption. The assume facility attaches various
definitions to the variable you specify, with one result being that the
name subsequently appears as a local name with an appended tilde. No
relationship exists between the local variable b with an assumption, which
is displayed as b~, and the global variable name containing a tilde b~.
> assume(b>0);
> x := b + 1;
x := b~ + 1
b~ + 1
When you clear the definition of the named variable, the association
between the name and the local name with the tilde is lost, but expressions
created with the local name still contain it.
> b := evaln(b);
b := b
> x;
b~ + 1
Example 3
Creating the Cartesian Product of a Sequence of Sets When you pass
a sequence of sets to the procedure, it constructs a new procedure. The
new procedure returns the next term in the Cartesian product each time
you invoke it. Local variables from the outer procedure are used to keep
track of which term to return next.
The Cartesian product of a sequence of sets is the set of all lists
in which the ith entry is an element of the ith set. Thus, the Cartesian
product of {α, β, γ} and {x, y} is
{α, β, γ} × {x, y} = {[α, x], [β, x], [γ, x], [α, y], [β, y], [γ, y]}.
The number of elements in the Cartesian product of a sequence of sets
grows very rapidly as the number of sets or size of the sets increases. It
therefore requires a large amount of memory to store all the elements of
the Cartesian product.
Solution You must write a procedure that returns a new element of the
Cartesian product each time you call it. By calling such a procedure re-
peatedly, you can process every element in the Cartesian product without
storing all its elements at once.
The following procedure returns the next element of the Cartesian
product of the list of sets s. It uses an array, c, of counters to determine
the next element. For example, c[1]=3 and c[2]=1 correspond to the
third element of the first set and the first element of the second set.
> s := [ {alpha, beta, gamma}, {x, y} ];
c := [3, 1]
1.3 Local Variables and Invoking Procedures • 23
[β, x]
Before you call the element procedure you must initialize all the coun-
ters to 1, except the first one, which must be 0.
> c := array( [0, 1] );
c := [0, 1]
[γ, x]
[α, x]
[β, x]
[γ, y]
[α, y]
[β, y]
24 • Chapter 1: Procedures, Variables, and Extending Maple
FAIL
[γ, x]
Example 4
Instead of writing a new procedure for each Cartesian product you study,
you can write a procedure, CartesianProduct, that returns such a pro-
cedure. CartesianProduct creates a list, s, of its arguments, which must
be sets, and then initializes the array, c, of counters and defines the sub-
procedure element. Finally, the element subprocedure is invoked inside
a proc structure.
> CartesianProduct := proc()
> local s, c, element;
> s := [args];
> if not type(s, list(set)) then
> error "expected a sequence of sets, but received",
> args ;
> end if;
> c := array( [0, 1$(nops(s)-1)] );
>
> element := proc(s::list(set), c::array(1, nonnegint))
> local i, j;
> for i to nops(s) do
> c[i] := c[i] + 1;
> if c[i] <= nops( s[i] ) then
> return [ seq(s[j][c[j]], j=1..nops(s)) ] ;
> end if;
> c[i] := 1;
> end do;
> c[1] := 0;
> FAIL;
> end proc;
>
> proc()
> element(s, c);
> end proc;
> end proc:
Again, you can find all six elements of {α, β, γ} × {x, y}.
> f := CartesianProduct( {alpha, beta, gamma}, {x,y} );
1.3 Local Variables and Invoking Procedures • 25
[γ, x]
[α, x]
[β, x]
[γ, y]
[α, y]
[β, y]
FAIL
[x, N, 23]
[y, N, 23]
[x, Z, 23]
[y, Z, 23]
[x, R, 23]
element := 45
> g();
[x, R, 56]
Exercises
1. The procedure that CartesianProduct generates does not work if one
of the sets is empty.
> f := CartesianProduct( {}, {x,y} );
> f();
[1, 1, 1, 1, 1], [1, 1, 1, 2], [1, 1, 3], [1, 2, 2], [1, 4], [2, 3], [5].
readline( filename )
Maplesoft
s := “Maplesoft”
28 • Chapter 1: Procedures, Variables, and Extending Maple
Example 1
The following application prompts the user for an answer to a question.
> DetermineSign := proc(a::algebraic) local s;
> printf("Is the sign of %a positive? Answer yes or no: ",a);
> s := readline(terminal);
> evalb( s="yes" or s = "y" );
> end proc:
> DetermineSign(u-1);
true
readstat( prompt )
n−1
The user input for a readstat command must have a terminating semi-
colon or colon, or an error is raised.
Advantages Unlike the readline command, which only reads one line,
the readstat allows you to break a large expression across multiple lines.
Another advantage of using the readstat command is that if there is
an error in the input, the readstat command automatically repeats the
prompt for user input.
1.4 Interactive Input • 29
390625
Example 2
The following is an application of the readstat command that imple-
ments an interface to the limit command. The procedure, given the
function f (x), assumes x is the variable if only one variable is present.
Otherwise, the user is asked for the variable and the limit point.
> GetLimitInput := proc(f::algebraic)
> local x, a, K;
> # choose all variables in f
> K := select(type, indets(f), name);
>
> if nops(K) = 1 then
> x := K[1];
> else
> x := readstat("Input limit variable: ");
> while not type(x, name) do
> printf("A variable is required: received %a\n", x);
> x := readstat("Please re-input limit variable: ");
> end do;
> end if;
> a := readstat("Input limit point: ");
> x = a;
> end proc:
x=0
30 • Chapter 1: Procedures, Variables, and Extending Maple
In the following output, the user first tries to use the number 1 as the
limit variable. Because 1 is not a name, GetLimitInput requests another
limit variable.
> GetLimitInput( exp(u*x) );
x=∞
s := “a*x^2 + 1”
> y := parse( s );
y := a x2 + 1
When you parse the string s you get an expression. In this case, you
get a sum.
> type(s, string), type(y, ‘+‘);
true, true
Exploring the Variety of Random
Documents with Different Content
“Go. Washington.
“Mr. Jefferson.”
Dr. Rittenhouse executed this high trust with great ability and
unimpeachable integrity, during three years; at the expiration of
which he resigned it, on the 30th of June, 1795. He had, long before,
expressed his anxious wish to retire from this station; but continued
in office until that time, on the solicitation of the President and at the
earnest desire of Mr. Jefferson.
“To those who know the President of the United States well,—who
know the caution with which he is accustomed to speak, and that he
possesses the talent of correctly estimating, as well as vigorously
overcoming, the difficulties which present themselves in every
circumstance of business,—this would rescue any character from the
unqualified censure of the members of the house of representatives.
But I will go further, and will shew the grounds on which the
President formed his judgment, so that every man may form his own
opinion.”
The Jacobin Club of Paris was one of these political engines of the
French revolution, for some time after its commencement; and,
perhaps, that assembly contained many worthy members, originally,
although it afterwards became notoriously infamous, by the
monstrous enormity of the crimes it countenanced and produced.
Whatever, therefore, may have been the real views and intentions
of some of the members of the Democratic Society which was
formed in Philadelphia, in 1793,—even if those of a majority of their
number were highly unjustifiable,—no imputation, unfavourable to
Dr. Rittenhouse’s character, either as a good citizen or an upright
man, could in the smallest degree be attached to him, by reason of
his having been chosen a President of that body, at the time of its
organization.[279]
On the 7th of August 1783, and after peace had been proclaimed,
congress unanimously passed a resolution in the following words
——“Resolved, That an equestrian statue of General Washington be
erected at the place where the residence of Congress shall be
established;—that the statue be of bronze: the General to be
represented in a Roman dress, holding a truncheon in his right hand,
and his head, encircled with a laurel wreath. The Statue to be
supported by a marble pedestal, on which are to be represented, in
basso relievo, the following principal events of the war, in which
General Washington commanded in person: the evacuation of
Boston;—the capture of the Hessions, at Trenton;—the battle of
Princeton;—the action of Monmouth;—and the surrender of York.—
On the upper part of the front of the pedestal, to be engraved as
follows: “The United States in Congress assembled ordered this
Statue to be erected, in the year of our Lord 1783, in honour of
George Washington, the illustrious Commander in Chief of the
Armies of the United States of America, during the war which
vindicated and secured their Liberty, Sovereignty and
Independence.”[281]
Some time in the summer of the year 1794 (if the Writer’s
recollection be correct,) our benevolent philosopher having occasion
to view the canal, intended to form a communication between the
waters of the Delaware and the Schuylkill, invited Mr. Ceracchi to
accompany him, for the purpose of examining the quality of the
marble in the great quarries of that material, situated near the margin
of the latter river, in the vicinity of the western end of the canal. The
Memorialist joined in this little excursion, during which, Dr.
Rittenhouse was, as usual, communicative, cheerful and instructive.
“Sir,
“My worthy friend, Mr. John Miller, son of the eminent professor,
John Miller, of Glasgow, whom I recommend to your attention, has
charged himself with this letter, and will deliver to you a Writing-Box,
which I dedicate to your use, as President of the Philosophical
Society at Philadelphia, and to your successors in office, as a
testimony of my high esteem for your literary character and for that
of the Society over which you preside.
“This Box is made of Yew, of Black Cherry tree, and Acacia and
Barberry, and veneered with Holly; all the growth of my garden at
this place, and joined, fitted and finished, by my own joiner, in this
house.
Our website is not just a platform for buying books, but a bridge
connecting readers to the timeless values of culture and wisdom. With
an elegant, user-friendly interface and an intelligent search system,
we are committed to providing a quick and convenient shopping
experience. Additionally, our special promotions and home delivery
services ensure that you save time and fully enjoy the joy of reading.
ebookfinal.com