Maple Programming Guide

Maple Programming Guide

Maple Programming Guide L. Bernardin P. Chin P. DeMarco K. O. Geddes D. E. G. Hare K. M. Heal G. Labahn J. P. May J. McCarron M. B. Monagan D. Ohashi S. M. Vorkoetter Copyright © Maplesoft, a division of Waterloo Maple Inc. 2011 Maple Programming Guide by L. Bernardin, P. Chin, P. DeMarco, K. O. Geddes, D. E. G. Hare, K. M. Heal, G. Labahn, J. P. May, J. McCarron, M. B. Monagan, D. Ohashi, and S. M. Vorkoetter Copyright Maplesoft, Maple, MapleNet, MaplePrimes, Maplet, Maple T.A., and OpenMaple are all trademarks of Waterloo Maple Inc. © Maplesoft, a division of Waterloo Maple Inc. 1996-2011. All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transcribed, in any form or by any means — electronic, mechanical, photocopying, recording, or otherwise. 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. Adobe and Acrobat are either registered trademarks or trademarks of Adobe Systems Incorporated in the United States and/or other countries. Java is a registered trademarks of Oracle and/or its affiliates. MATLAB is a registered trademark of The MathWorks, Inc. Microsoft and Windows are registered trademarks of Microsoft Corporation. NAG is a registered trademark of The Numerical Algorithms Group Ltd. All other trademarks are the property of their respective owners. This document was produced using a special version of Maple and DocBook. Printed in Canada ISBN 978-1-926902-08-1 Contents Preface ....................................................................................................... xxi 1 Introduction to Programming in Maple .............................................................. 1 1.1 In This Chapter ...................................................................................... 1 1.2 The Maple Software ................................................................................ 1 The User Interface .................................................................................. 1 The Computation Engine .......................................................................... 1 1.3 Maple Statements ................................................................................... 2 Getting Help .......................................................................................... 2 Displaying a Text String ........................................................................... 2 Performing an Arithmetic Operation ........................................................... 3 Assigning to a Name ............................................................................... 3 Using Maple Library Commands .............................................................. 3 1.4 Procedures ............................................................................................ 4 Defining a Simple Procedure ..................................................................... 4 Entering a Procedure Definition ................................................................. 4 Adding Comments to a Procedure .............................................................. 7 Calling a Procedure ................................................................................. 8 Maple Library Commands, Built-In Commands, and User-Defined Proced- ures ....................................................................................................... 8 Full Evaluation and Last Name Evaluation .................................................. 9 Viewing Procedure Definitions and Maple Library Code ............................... 10 1.5 Interrupting Computations and Clearing the Internal Memory ........................ 11 Interrupting a Maple Computation ............................................................ 11 Clearing the Maple Internal Memory ........................................................ 12 1.6 Avoiding Common Problems ................................................................... 12 Unexpected End of Statement .................................................................. 12 Missing Operator .................................................................................. 13 Invalid, Wrong Number or Type of Arguments ........................................... 14 Unbalanced Parentheses ......................................................................... 14 Assignment Versus Equality .................................................................... 14 1.7 Exercises ............................................................................................. 16 2 Maple Language Elements ............................................................................ 17 2.1 In This Chapter ..................................................................................... 17 2.2 Character Set ....................................................................................... 17 2.3 Tokens ................................................................................................ 18 Reserved Words .................................................................................... 18 Programming-Language Operators ........................................................... 19 Names ................................................................................................ 22 2.4 Natural Integers .................................................................................... 23 2.5 Strings ................................................................................................ 24 Length of a String ................................................................................. 24 iii iv • Contents Substrings ............................................................................................ 24 Searching a String ................................................................................. 25 String Concatenation ............................................................................. 25 Mutability of Strings .............................................................................. 26 Special Characters in Strings ................................................................... 27 Parsing Strings ..................................................................................... 27 Converting Expressions to Strings ............................................................ 28 2.6 Using Special Characters ........................................................................ 29 Token Separators .................................................................................. 29 Blank Spaces, New Lines, Comments, and Continuation ............................... 29 Punctuation Marks ................................................................................ 30 Escape Characters ................................................................................. 33 2.7 Types and Operands .............................................................................. 34 DAGs ................................................................................................. 34 Maple Types ........................................................................................ 35 Operands and op ................................................................................... 36 2.8 Avoiding Common Problems ................................................................... 40 Attempting to Assign to a Protected Name ................................................. 40 Invalid Left-Hand Assignment ................................................................. 41 Incorrect Syntax in Parse ........................................................................ 41 White Space Characters within a Token ..................................................... 41 Incorrect Use of Double and Single Quotes ................................................ 41 Avoid Using Maple Keywords as Names ................................................... 42 2.9 Exercises ............................................................................................. 43 3 Maple Expressions ....................................................................................... 45 3.1 In This Chapter ..................................................................................... 45 3.2 Introduction ......................................................................................... 45 Expressions and Statements .................................................................... 45 Automatic Simplification and Evaluation ................................................... 45 Syntax and Constructors ........................................................................ 45 3.3 Names ................................................................................................ 47 Creating Names: Lexical Conventions ....................................................... 48 3.4 Unevaluated Expressions ........................................................................ 52 Protecting Names and Options ................................................................. 53 Generic Expressions .............................................................................. 54 Pass by Reference ................................................................................

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    704 Page
  • File Size
    -

Download

Channel Download Status
Express Download Enable

Copyright

We respect the copyrights and intellectual property rights of all users. All uploaded documents are either original works of the uploader or authorized works of the rightful owners.

  • Not to be reproduced or distributed without explicit permission.
  • Not used for commercial purposes outside of approved use cases.
  • Not used to infringe on the rights of the original creators.
  • If you believe any content infringes your copyright, please contact us immediately.

Support

For help with questions, suggestions, or problems, please contact us