Maple Introductory Programming Guide

Total Page:16

File Type:pdf, Size:1020Kb

Maple Introductory Programming Guide Maple Introductory Programming Guide M. B. Monagan K. O. Geddes K. M. Heal G. Labahn S. M. Vorkoetter J. McCarron P. DeMarco Maplesoft, a division of Waterloo Maple Inc. 2009. ii Maplesoft, Maple, and Maplet are all trademarks of Waterloo Maple Inc. © Maplesoft, a division of Waterloo Maple Inc. 2009. All rights reserved. Information in this document is subject to change without notice and does not represent a commitment on the part of the vendor. The software described in this document is furnished under a license agreement and may be used or copied only in accordance with the agreement. It is against the law to copy the software on any medium except as specifically allowed in the agreement. Windows is a registered trademark of Microsoft Corporation. Java and all Java based marks are trademarks or registered trademarks of Sun Microsystems, Inc. in the United States and other countries. Maplesoft is independent of Sun Microsystems, Inc. All other trademarks are the property of their respective owners. This document was produced using a special version of Maple that reads and updates LaTeX files. Printed in Canada ISBN 978-1-897310-73-1 Contents Preface 1 Audience . 1 Worksheet Graphical Interface . 1 Manual Set . 2 Conventions . 2 The Maple Programming Language . 3 Using This Book . 3 Customer Feedback . 4 1 Introduction to Programming in Maple 5 In This Chapter . 5 1.1 The Maple Software . 5 1.2 Maple Statements . 6 Getting Started . 6 Maple Statements . 7 Getting Help . 7 Displaying a Text String . 7 Performing an Arithmetic Operation . 8 Assigning to a Name . 8 Using Maple Library Routines . 9 1.3 Procedures . 9 Defining a Simple Procedure . 9 Maple Library Routines, Built-In Routines, and User- Defined Procedures . 13 1.4 Interrupting Computations and Clearing the Internal Mem- ory . 16 Interrupting a Maple Computation . 16 Clearing the Maple Internal Memory . 17 1.5 Troubleshooting . 17 Unexpected End of Statement . 17 iii iv Contents ¯ Missing Operator . 18 Invalid, Wrong Number or Type of Arguments . 19 Unbalanced Parentheses . 19 Assignment Versus Equality . 20 1.6 Exercises . 21 1.7 Conclusion . 21 2 Maple Language Elements 23 In This Chapter . 23 2.1 Character Set . 23 2.2 Tokens . 24 Reserved Words . 24 Programming-Language Operators . 25 Names . 26 Strings . 38 Natural Integers . 46 2.3 Using Special Characters . 46 Token Separators . 46 Blank Spaces, New Lines, Comments, and Continuation . 46 Punctuation Marks . 48 Escape Characters . 51 2.4 Types and Operands . 51 Integers . 52 Strings . 53 Names . 53 Concatenations . 55 2.5 Troubleshooting . 55 Attempting to Assign to a Protected Name . 55 Invalid Left-Hand Assignment . 56 Incorrect Syntax in Parse . 56 White Space Characters within a Token . 56 Incorrect Use of Double and Single Quotes . 57 2.6 Exercises . 58 2.7 Conclusion . 58 3 Maple Expressions and Statements 59 In This Chapter . 59 3.1 Syntax and Semantics . 59 Syntax . 59 Semantics . 60 3.2 Expressions . 61 Contents v ¯ Constants . 61 Operators . 70 Data Structures . 89 Functions . 92 3.3 Using Expressions . 96 Investigating the Parts of an Expression . 96 Evaluating and Simplifying Expressions . 100 Unevaluated Expressions . 100 Substituting Subexpressions . 103 Displaying Large Expressions: Labels . 105 Structured Types . 106 3.4 Statements . 110 The Assignment Statement . 111 Selection Statements . 114 Repetition Statements . 115 The read and save Statements . 117 The break and next Statements . 118 The error and return Statements . 118 The use Statement . 119 The quit Statement . 119 3.5 Troubleshooting . 119 Syntax Errors . 120 Reserved Word Unexpected . 120 Break or Next Not in Loop . 121 3.6 Exercises . 121 3.7 Conclusion . 122 4 Basic Data Structures 123 In This Chapter . 123 4.1 Sets . 123 Manipulating a Set . 124 4.2 Lists . 126 Manipulating a List . 128 4.3 Tables . 133 An Alternate Method for Generating a Table . 135 Table Evaluation Rules . 135 Manipulating a Table . 136 4.4 arrays and Arrays . 141 Evaluation Rules for arrays . 144 Manipulating arrays and Arrays . 145 4.5 Selecting Elements from a Data Structure . 152 vi Contents ¯ The Selection Operation [] . 152 The op Command . 155 The select, remove, and selectremove Commands . 156 4.6 Converting Between Data Structures . 158 Converting a Sequence to a Set or a List . 158 Converting Other Data Structures . 159 4.7 Other Maple Data Structures . 159 Stacks . 159 Queues . 161 4.8 Troubleshooting . 162 Wrong Number of Parameters in Function . 163 Invalid Subscript Selector . 163 Requires Range or Initialization List for Building arrays . 164 Error in array Bound or Array Index out of Range . 164 4.9 Exercises . 165 4.10 Conclusion . 166 5 Flow Control 167 In This Chapter . 167 5.1 Selection and Conditional Execution . 167 The if Statement . 167 The `if` Operator . 171 5.2 Repetition . 172 The for Loop . 173 The while Loop . 177 Control within Loops . 178 5.3 Looping Commands . 180 The map Command . 180 The select, remove, and selectremove Commands . 181 The zip Command . 182 The seq, add, and mul Commands . 183 Using Specialized Looping Commands . 185 5.4 Troubleshooting . 187 Cannot Evaluate Boolean in if Statement . 188 Value in Loop Must Be Numeric or Character . 188 Variable Previously Assigned . 189 Wrong Parameters in Function $ . 190 5.5 Exercises . 191 5.6 Conclusion . 191 6 Maple Procedures 193 Contents vii ¯ In This Chapter . ..
Recommended publications
  • Sagemath and Sagemathcloud
    Viviane Pons Ma^ıtrede conf´erence,Universit´eParis-Sud Orsay [email protected] { @PyViv SageMath and SageMathCloud Introduction SageMath SageMath is a free open source mathematics software I Created in 2005 by William Stein. I http://www.sagemath.org/ I Mission: Creating a viable free open source alternative to Magma, Maple, Mathematica and Matlab. Viviane Pons (U-PSud) SageMath and SageMathCloud October 19, 2016 2 / 7 SageMath Source and language I the main language of Sage is python (but there are many other source languages: cython, C, C++, fortran) I the source is distributed under the GPL licence. Viviane Pons (U-PSud) SageMath and SageMathCloud October 19, 2016 3 / 7 SageMath Sage and libraries One of the original purpose of Sage was to put together the many existent open source mathematics software programs: Atlas, GAP, GMP, Linbox, Maxima, MPFR, PARI/GP, NetworkX, NTL, Numpy/Scipy, Singular, Symmetrica,... Sage is all-inclusive: it installs all those libraries and gives you a common python-based interface to work on them. On top of it is the python / cython Sage library it-self. Viviane Pons (U-PSud) SageMath and SageMathCloud October 19, 2016 4 / 7 SageMath Sage and libraries I You can use a library explicitly: sage: n = gap(20062006) sage: type(n) <c l a s s 'sage. interfaces .gap.GapElement'> sage: n.Factors() [ 2, 17, 59, 73, 137 ] I But also, many of Sage computation are done through those libraries without necessarily telling you: sage: G = PermutationGroup([[(1,2,3),(4,5)],[(3,4)]]) sage : G . g a p () Group( [ (3,4), (1,2,3)(4,5) ] ) Viviane Pons (U-PSud) SageMath and SageMathCloud October 19, 2016 5 / 7 SageMath Development model Development model I Sage is developed by researchers for researchers: the original philosophy is to develop what you need for your research and share it with the community.
    [Show full text]
  • Introduction to IDL®
    Introduction to IDL® Revised for Print March, 2016 ©2016 Exelis Visual Information Solutions, Inc., a subsidiary of Harris Corporation. All rights reserved. ENVI and IDL are registered trademarks of Harris Corporation. All other marks are the property of their respective owners. This document is not subject to the controls of the International Traffic in Arms Regulations (ITAR) or the Export Administration Regulations (EAR). Contents 1 Introduction To IDL 5 1.1 Introduction . .5 1.1.1 What is ENVI? . .5 1.1.2 ENVI + IDL, ENVI, and IDL . .6 1.1.3 ENVI Resources . .6 1.1.4 Contacting Harris Geospatial Solutions . .6 1.1.5 Tutorials . .6 1.1.6 Training . .7 1.1.7 ENVI Support . .7 1.1.8 Contacting Technical Support . .7 1.1.9 Website . .7 1.1.10 IDL Newsgroup . .7 2 About This Course 9 2.1 Manual Organization . .9 2.1.1 Programming Style . .9 2.2 The Course Files . 11 2.2.1 Installing the Course Files . 11 2.3 Starting IDL . 11 2.3.1 Windows . 11 2.3.2 Max OS X . 11 2.3.3 Linux . 12 3 A Tour of IDL 13 3.1 Overview . 13 3.2 Scalars and Arrays . 13 3.3 Reading Data from Files . 15 3.4 Line Plots . 15 3.5 Surface Plots . 17 3.6 Contour Plots . 18 3.7 Displaying Images . 19 3.8 Exercises . 21 3.9 References . 21 4 IDL Basics 23 4.1 IDL Directory Structure . 23 4.2 The IDL Workbench . 24 4.3 Exploring the IDL Workbench .
    [Show full text]
  • A Comparative Evaluation of Matlab, Octave, R, and Julia on Maya 1 Introduction
    A Comparative Evaluation of Matlab, Octave, R, and Julia on Maya Sai K. Popuri and Matthias K. Gobbert* Department of Mathematics and Statistics, University of Maryland, Baltimore County *Corresponding author: [email protected], www.umbc.edu/~gobbert Technical Report HPCF{2017{3, hpcf.umbc.edu > Publications Abstract Matlab is the most popular commercial package for numerical computations in mathematics, statistics, the sciences, engineering, and other fields. Octave is a freely available software used for numerical computing. R is a popular open source freely available software often used for statistical analysis and computing. Julia is a recent open source freely available high-level programming language with a sophisticated com- piler for high-performance numerical and statistical computing. They are all available to download on the Linux, Windows, and Mac OS X operating systems. We investigate whether the three freely available software are viable alternatives to Matlab for uses in research and teaching. We compare the results on part of the equipment of the cluster maya in the UMBC High Performance Computing Facility. The equipment has 72 nodes, each with two Intel E5-2650v2 Ivy Bridge (2.6 GHz, 20 MB cache) proces- sors with 8 cores per CPU, for a total of 16 cores per node. All nodes have 64 GB of main memory and are connected by a quad-data rate InfiniBand interconnect. The tests focused on usability lead us to conclude that Octave is the most compatible with Matlab, since it uses the same syntax and has the native capability of running m-files. R was hampered by somewhat different syntax or function names and some missing functions.
    [Show full text]
  • Sage 9.4 Reference Manual: Finite Rings Release 9.4
    Sage 9.4 Reference Manual: Finite Rings Release 9.4 The Sage Development Team Aug 24, 2021 CONTENTS 1 Finite Rings 1 1.1 Ring Z=nZ of integers modulo n ....................................1 1.2 Elements of Z=nZ ............................................ 15 2 Finite Fields 39 2.1 Finite Fields............................................... 39 2.2 Base Classes for Finite Fields...................................... 47 2.3 Base class for finite field elements.................................... 61 2.4 Homset for Finite Fields......................................... 69 2.5 Finite field morphisms.......................................... 71 3 Prime Fields 77 3.1 Finite Prime Fields............................................ 77 3.2 Finite field morphisms for prime fields................................. 79 4 Finite Fields Using Pari 81 4.1 Finite fields implemented via PARI’s FFELT type............................ 81 4.2 Finite field elements implemented via PARI’s FFELT type....................... 83 5 Finite Fields Using Givaro 89 5.1 Givaro Finite Field............................................ 89 5.2 Givaro Field Elements.......................................... 94 5.3 Finite field morphisms using Givaro................................... 102 6 Finite Fields of Characteristic 2 Using NTL 105 6.1 Finite Fields of Characteristic 2..................................... 105 6.2 Finite Fields of characteristic 2...................................... 107 7 Miscellaneous 113 7.1 Finite residue fields...........................................
    [Show full text]
  • Why Is C. Diff So Hard to Culture and Kill?
    Why is C. diff so hard to culture and kill? Clostridium difficile, commonly referred to as C. diff, is the #1 nosocomial infection in hospitals (it actually kicked staph infections out of the top spot). At Assurance, we test for this organism as part of our Gastrointestinal (GI) panel. C. diff is a gram-positive anaerobe, meaning it does not like oxygen. Its defensive mechanism is sporulation – where it essentially surrounds itself with a tough outer layer of keratin and can live in water, soil, etc. for over a decade. For reference, anthrax is another organism that sporulates. Once C. diff sporulates, it is very hard to kill and in fact, bleach is one of the only disinfectants that work. Unfortunately, it can spread quickly throughout hospitals. Spores of C. diff are found all over hospital surfaces and even in some hospital water systems. It’s the most threatening for those who are immunocompromised or the elderly, who are the most likely to end up with C. diff infections. With our PCR testing, we’re looking for the C. diff organism itself but we’re also looking at the production of toxin. Unless it produces toxins A AND B together OR toxin B, C. diff doesn’t cause severe disease. Many babies are exposed to it during birth or in the hospitals and may test positive on our GI panel. Unless they are expressing those toxins (both toxin A&B or just toxin B) it is not considered a clinical infection. Studies show that toxins A&B together causes infection, as well as toxin B.
    [Show full text]
  • WEEK 10: FAREWELL to PYTHON... WELCOME to MAPLE! 1. a Review of PYTHON's Features During the Past Few Weeks, We Have Explored
    WEEK 10: FAREWELL TO PYTHON... WELCOME TO MAPLE! 1. A review of PYTHON’s features During the past few weeks, we have explored the following aspects of PYTHON: • Built-in types: integer, long integer, float, complex, boolean, list, se- quence, string etc. • Operations on built-in types: +, −, ∗, abs, len, append, etc. • Loops: N = 1000 i=1 q = [] while i <= N q.append(i*i) i += 1 • Conditional statements: if x < y: min = x else: min = y • Functions: def fac(n): if n==0 then: return 1 else: return n*fac(n-1) • Modules: math, turtle, etc. • Classes: Rational, Vector, Polynomial, Polygon, etc. With these features, PYTHON is a powerful tool for doing mathematics on a computer. In particular, the use of modules makes it straightforward to add greater functionality, e.g. GL (3D graphics), NumPy (numerical algorithms). 2. What about MAPLE? MAPLE is really designed to be an interactive tool. Nevertheless, it can also be used as a programming language. It has some of the basic facilities available in PYTHON: Loops; conditional statements; functions (in the form of “procedures”); good graphics and some very useful additional modules called “packages”: • Built-in types: long integer, float (arbitrary precision), complex, rational, boolean, array, sequence, string etc. • Operations on built-in types: +, −, ∗, mathematical functions, etc. • Loops: 1 2 WEEK 10: FAREWELL TO PYTHON... WELCOME TO MAPLE! Table 1. Some of the most useful MAPLE packages Name Description Example DEtools Tools for differential equations exactsol(ode,y) linalg Linear Algebra gausselim(A) plots Graphics package polygonplot(p,axes=none) stats Statistics package random[uniform](10) N := 1000 : q := array(1..N) : for i from 1 to N do q[i] := i*i : od : • Conditional statements: if x < y then min := x else min := y fi: • Functions: fac := proc(n) if n=0 then return 1 else return n*fac(n-1) fi : end proc : • Packages: See Table 1.
    [Show full text]
  • Practical Estimation of High Dimensional Stochastic Differential Mixed-Effects Models
    Practical Estimation of High Dimensional Stochastic Differential Mixed-Effects Models Umberto Picchinia,b,∗, Susanne Ditlevsenb aDepartment of Mathematical Sciences, University of Durham, South Road, DH1 3LE Durham, England. Phone: +44 (0)191 334 4164; Fax: +44 (0)191 334 3051 bDepartment of Mathematical Sciences, University of Copenhagen, Universitetsparken 5, DK-2100 Copenhagen, Denmark Abstract Stochastic differential equations (SDEs) are established tools to model physical phenomena whose dynamics are affected by random noise. By estimating parameters of an SDE intrin- sic randomness of a system around its drift can be identified and separated from the drift itself. When it is of interest to model dynamics within a given population, i.e. to model simultaneously the performance of several experiments or subjects, mixed-effects mod- elling allows for the distinction of between and within experiment variability. A framework to model dynamics within a population using SDEs is proposed, representing simultane- ously several sources of variation: variability between experiments using a mixed-effects approach and stochasticity in the individual dynamics using SDEs. These stochastic differ- ential mixed-effects models have applications in e.g. pharmacokinetics/pharmacodynamics and biomedical modelling. A parameter estimation method is proposed and computational guidelines for an efficient implementation are given. Finally the method is evaluated using simulations from standard models like the two-dimensional Ornstein-Uhlenbeck (OU) and the square root models. Keywords: automatic differentiation, closed-form transition density expansion, maximum likelihood estimation, population estimation, stochastic differential equation, Cox-Ingersoll-Ross process arXiv:1004.3871v2 [stat.CO] 3 Oct 2010 1. INTRODUCTION Models defined through stochastic differential equations (SDEs) allow for the represen- tation of random variability in dynamical systems.
    [Show full text]
  • Your Performance Task Summary Explanation
    Lab Report: 11.2.5 Manage Files Your Performance Your Score: 0 of 3 (0%) Pass Status: Not Passed Elapsed Time: 6 seconds Required Score: 100% Task Summary Actions you were required to perform: In Compress the D:\Graphics folderHide Details Set the Compressed attribute Apply the changes to all folders and files In Hide the D:\Finances folder In Set Read-only on filesHide Details Set read-only on 2017report.xlsx Set read-only on 2018report.xlsx Do not set read-only for the 2019report.xlsx file Explanation In this lab, your task is to complete the following: Compress the D:\Graphics folder and all of its contents. Hide the D:\Finances folder. Make the following files Read-only: D:\Finances\2017report.xlsx D:\Finances\2018report.xlsx Complete this lab as follows: 1. Compress a folder as follows: a. From the taskbar, open File Explorer. b. Maximize the window for easier viewing. c. In the left pane, expand This PC. d. Select Data (D:). e. Right-click Graphics and select Properties. f. On the General tab, select Advanced. g. Select Compress contents to save disk space. h. Click OK. i. Click OK. j. Make sure Apply changes to this folder, subfolders and files is selected. k. Click OK. 2. Hide a folder as follows: a. Right-click Finances and select Properties. b. Select Hidden. c. Click OK. 3. Set files to Read-only as follows: a. Double-click Finances to view its contents. b. Right-click 2017report.xlsx and select Properties. c. Select Read-only. d. Click OK. e.
    [Show full text]
  • Powerview Command Reference
    PowerView Command Reference TRACE32 Online Help TRACE32 Directory TRACE32 Index TRACE32 Documents ...................................................................................................................... PowerView User Interface ............................................................................................................ PowerView Command Reference .............................................................................................1 History ...................................................................................................................................... 12 ABORT ...................................................................................................................................... 13 ABORT Abort driver program 13 AREA ........................................................................................................................................ 14 AREA Message windows 14 AREA.CLEAR Clear area 15 AREA.CLOSE Close output file 15 AREA.Create Create or modify message area 16 AREA.Delete Delete message area 17 AREA.List Display a detailed list off all message areas 18 AREA.OPEN Open output file 20 AREA.PIPE Redirect area to stdout 21 AREA.RESet Reset areas 21 AREA.SAVE Save AREA window contents to file 21 AREA.Select Select area 22 AREA.STDERR Redirect area to stderr 23 AREA.STDOUT Redirect area to stdout 23 AREA.view Display message area in AREA window 24 AutoSTOre ..............................................................................................................................
    [Show full text]
  • Formal Specification— Z Notation— Syntax, Type and Semantics
    Formal Specification— Z Notation| Syntax, Type and Semantics Consensus Working Draft 2.6 August 24, 2000 Developed by members of the Z Standards Panel BSI Panel IST/5/-/19/2 (Z Notation) ISO Panel JTC1/SC22/WG19 (Rapporteur Group for Z) Project number JTC1.22.45 Project editor: Ian Toyn [email protected] http://www.cs.york.ac.uk/~ian/zstan/ This is a Working Draft by the Z Standards Panel. It has evolved from Consensus Working Draft 2.5 of June 20, 2000 according to remarks received and discussed at Meeting 56 of the Z Panel. ISO/IEC 13568:2000(E) Contents Page Foreword . iv Introduction . v 1 Scope ....................................................... 1 2 Normative references . 1 3 Terms and definitions . 1 4 Symbols and definitions . 3 5 Conformance . 14 6 Z characters . 18 7 Lexis........................................................ 24 8 Concrete syntax . 30 9 Characterisation rules . 38 10 Annotated syntax . 40 11 Prelude . 43 12 Syntactic transformation rules . 44 13 Type inference rules . 54 14 Semantic transformation rules . 66 15 Semantic relations . 71 Annex A (normative) Mark-ups . 79 Annex B (normative) Mathematical toolkit . 90 Annex C (normative) Organisation by concrete syntax production . 107 Annex D (informative) Tutorial . 153 Annex E (informative) Conventions for state-based descriptions . 166 Bibliography . 168 Index . 169 ii c ISO/IEC 2000|All rights reserved ISO/IEC 13568:2000(E) Figures 1 Phases of the definition . 15 B.1 Parent relation between sections of the mathematical toolkit . 90 D.1 Parse tree of birthday book example . 155 D.2 Annotated parse tree of part of axiomatic example .
    [Show full text]
  • Doing More in UNIX HORT 59000 Lab 3 Instructor: Kranthi Varala Today’S Pairs
    Doing more in UNIX HORT 59000 Lab 3 Instructor: Kranthi Varala Today’s pairs Pair #1 Pair #2 Pair #3 Pair #4 Pair #5 Pair #6 Pair #7 Pair #8 Aishwarya, Habte, Chancellor, Rachel F., Rachel H., Michelle, Raquel, Katherine, Shawna Xiaojin Thiti Sara AuditorX Jay Courtney Hannah If your partner is missing, let me know and we’ll adjust the pairs based on availability. Quiz 2 • Open-book policy: You are free to look at all the slides from previous Lectures and labs. • No internet searches for answers. • No talking to others. • You have 20 minutes to complete the quiz. Creating pipelines from commands • The STDIN and STDOUT of each command can be redirected to combine programs together. • For example, the STDOUT of one program can be sent to the STDIN of another program. • STDIN and STDOUT streams can be redirected using the following symbols: 1. > 2. < 3. | Writing vs. Appending to a file $ cat Pasture.txt > Poems.txt Send the contents of Pasture.txt to a new file called Poems.txt. If Poems.txt exists, its contents are over- written. $ cat WoodPile.txt >> Poems.txt Add the contents of WoodPile.txt to the end of the existing file Poems.txt. If Poems.txt does not exist, it will be created. Exercises UNIX commands wget and nano • Search NCBI’s GEO website for the experiment GSE49418. • Find the FTP link for the series matrix file. • Copy the link to the GSE49418_series_matrix.txt.gz file. • Use wget to download the matrix file to a new directory in your scratch folder.
    [Show full text]
  • Tracking Computer Use with the Windows® Registry Dataset Doug
    Tracking Computer Use with the Windows® Registry Dataset Doug White Disclaimer Trade names and company products are mentioned in the text or identified. In no case does such identification imply recommendation or endorsement by the National Institute of Standards and Technology, nor does it imply that the products are necessarily the best available for the purpose. Statement of Disclosure This research was funded by the National Institute of Standards and Technology Office of Law Enforcement Standards, the Department of Justice National Institute of Justice, the Federal Bureau of Investigation and the National Archives and Records Administration. National Software Reference Library & Reference Data Set The NSRL is conceptually three objects: • A physical collection of software • A database of meta-information • A subset of the database, the Reference Data Set The NSRL is designed to collect software from various sources and incorporate file profiles computed from this software into a Reference Data Set of information. Windows® Registry Data Set It is possible to compile a historical list of applications based on RDS metadata and residue files. Many methods can be used to remove application files, but these may not purge the Registry. Examining the Registry for residue can augment a historical list of applications or provide additional context about system use. Windows® Registry Data Set (WiReD) The WiReD contains changes to the Registry caused by application installation, de-installation, execution or other modifying operations. The applications are chosen from the NSRL collection, to be of interest to computer forensic examiners. WiReD is currently an experimental prototype. NIST is soliciting feedback from the computer forensics community to improve and extend its usefulness.
    [Show full text]