Symbolic Math Toolbox™ 5 MuPAD® Tutorial

Download Symbolic Math Toolbox™ 5 MuPAD® Tutorial

Post on 02-Jan-2017

218 views

Category:

Documents

4 download

Embed Size (px)

TRANSCRIPT

  • Symbolic Math Toolbox 5MuPAD Tutorial

  • How to Contact The MathWorks

    www.mathworks.com Webcomp.soft-sys.matlab Newsgroupwww.mathworks.com/contact_TS.html Technical Support

    suggest@mathworks.com Product enhancement suggestionsbugs@mathworks.com Bug reportsdoc@mathworks.com Documentation error reportsservice@mathworks.com Order status, license renewals, passcodesinfo@mathworks.com Sales, pricing, and general information

    508-647-7000 (Phone)

    508-647-7001 (Fax)

    The MathWorks, Inc.3 Apple Hill DriveNatick, MA 01760-2098For contact information about worldwide offices, see the MathWorks Web site.

    Symbolic Math Toolbox MuPAD Tutorial

    COPYRIGHT 19972008 by SciFace Software GmbH & Co. KG.The software described in this document is furnished under a license agreement. The software may be usedor copied only under the terms of the license agreement. No part of this manual may be photocopied orreproduced in any form without prior written consent from The MathWorks, Inc.

    FEDERAL ACQUISITION: This provision applies to all acquisitions of the Program and Documentationby, for, or through the federal government of the United States. By accepting delivery of the Program orDocumentation, the government hereby agrees that this software or documentation qualifies as commercialcomputer software or commercial computer software documentation as such terms are used or definedin FAR 12.212, DFARS Part 227.72, and DFARS 252.227-7014. Accordingly, the terms and conditions ofthis Agreement and only those rights specified in this Agreement, shall pertain to and govern the use,modification, reproduction, release, performance, display, and disclosure of the Program and Documentationby the federal government (or other entity acquiring for or through the federal government) and shallsupersede any conflicting contractual terms or conditions. If this License fails to meet the governmentsneeds or is inconsistent in any respect with federal procurement law, the government agrees to return theProgram and Documentation, unused, to The MathWorks, Inc.

    Trademarks

    MuPAD is a registered trademark of SciFace Software GmbH & Co. KG. MATLAB and Simulinkare registered trademarks of The MathWorks, Inc. See www.mathworks.com/trademarks for a listof additional trademarks. Other product or brand names may be trademarks or registeredtrademarks of their respective holders.

    Patents

    The MathWorks products are protected by one or more U.S. patents. Please seewww.mathworks.com/patents for more information.

    http://www.mathworks.com/trademarkshttp://www.mathworks.com/patents

  • Preface

    This book explains the basic use of the MuPAD computer algebra system, andgives some insight into the power of the system. MuPAD is available as part of theSymbolic Math Toolbox in MATLAB.

    This introduction addresses mathematicians, engineers, computer scientists,natural scientists and, more generally, all those in need of mathematicalcomputations for their education or their profession. Generally speaking, thisbook addresses anybody who wants to use the power of a modern computeralgebra package.

    There are two ways to use a computer algebra system. On the one hand, you mayuse the mathematical knowledge it incorporates by calling system functionsinteractively. For example, you can compute symbolic integrals or generate andinvert matrices by calling appropriate functions. They comprise the systemsmathematical intelligence and may implement sophisticated algorithms.Chapters 2 through 14 discuss this way of using the MuPAD engine.

    On the other hand, with the help of the MuPAD programming language, you caneasily add functionality to the system by implementing your own algorithms asMuPAD procedures. This is useful for special purpose applications if noappropriate system functions exist. Chapters 15 through 17 are an introduction toMuPAD programming.

    You can read this book in the standard way linearly from the first to the lastpage. However, there are reasons to proceed otherwise. This may be the case, e.g.,if you are interested in a particular problem, or if you already know somethingabout MuPAD.

    For beginners, we recommend to start reading Chapter 2, which gives a firstsurvey of MuPAD. The description of the online help system in Section 2.2 isprobably the most important part of this chapter. The help system providesinformation about details of system functions, their syntax, their callingparameters, etc. It is available online whenever the MuPAD notebook interface isrunning. In the beginning, requesting a help page is probably your most frequentquery to the system. After you have grown familiar with the help system, you maystart to experiment with MuPAD. Chapter 2 demonstrates some of the mostimportant system functions at work. You will find further details about thesefunctions in later parts of the book or in the help pages. For a deeper

  • Preface

    understanding of the data structures involved, you may consult the correspondingsections in Chapter 4.

    Chapter 3 discusses the MuPAD libraries and their use. They contain manyfunctions and algorithms for particular mathematical topics.

    The basic data types and the most important system functions for theirmanipulation are introduced in Chapter 4. It is not necessary to study all of themin the same depth. Depending on your intended application, you may selectivelyread only the passages about the relevant topics.

    Chapter 5 explains how MuPAD evaluates objects; we strongly recommend to readthis chapter.

    Chapters 6 through 11 discuss the use of some particularly important systemfunctions: substitution, differentiation, symbolic integration, equation solving,random number generation, and graphic commands.

    Several useful features such as the history mechanism, input and output routines,or the definition of user preferences are described in Chapters 13.2 through 13.Preferences can be used to configure the systems interactive behavior after theusers fancy to a certain extent.

    Chapters 15 through 17 give an introduction to the basic concepts of the MuPADprogramming language.

    MuPAD provides algorithms that can handle a large class of mathematical objectsand computational tasks related to them. Upon reading this introduction, it ispossible that you encounter unknown mathematical notions such as rings orfields. This introduction is not intended to explain the mathematical backgroundfor such objects. Basic mathematical knowledge is helpful but not mandatory tounderstand the text. Sometimes you may ask what algorithm MuPAD uses tosolve a particular problem. The internal mode of operation of the MuPADprocedures is not addressed here: we do not intend to give a general introductionto computer algebra and its algorithms. The interested reader may consult textbooks such as, e.g., [GCL 92] or [GG 99].

    This book gives an elementary introduction to MuPAD. Somewhat more abstractmathematical objects such as, e.g., field extensions, are easy to describe and tohandle in MuPAD. However, such advanced aspects of the system are notdiscussed here. The mathematical applications that are mentioned in the text are

    ii

  • Preface

    intentionally kept on a rather elementary level. This is to keep this text plain forreaders with little mathematical background and to make it applicable at schoollevel.

    We cannot explain the complete functionality of MuPAD in this introduction.Some parts of the system are mentioned only briefly. It is beyond the scope of thistutorial to go into the details of the full power of the MuPAD programminglanguage. You find these in the MuPAD help system, available online during aMuPAD session.

    This tutorial refers to MuPAD version 5 and later. Since the development of thesystem advances continuously, some of the details described may change in thefuture. Future versions will definitely provide additional functionality throughnew system functions and application packages. In this tutorial, we mainlypresent the basic tools and their use, which will probably remain essentiallyunchanged. We try to word all statements in the text in such a way that they staybasically valid for future MuPAD versions.

    iii

  • Contents

    Preface

    i

    Introduction

    1Numerical Computations . . . . . . . . . . . . . . . . . . . . . . . . . . 1-2Computer Algebra . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-3Characteristics of Computer Algebra Systems . . . . . . . . . . . . . . . 1-5MuPAD Software . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-6

    First Steps in MuPAD

    2Notebook interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-2Explanations and Help . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-4Computing with Numbers . . . . . . . . . . . . . . . . . . . . . . . . . . 2-5

    Exact Computations . . . . . . . . . . . . . . . . . . . . . . . . . 2-6Numerical Approximations . . . . . . . . . . . . . . . . . . . . . 2-7Complex Numbers . . . . . . . . . . . . . . . . . . . . . . . . . . 2-9

    Symbolic Computation . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-11Introductory Examples . . . . . . . . . . . . . . . . . . . . . . . . 2-11Curve Sketching . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-21Elementary Number Theory . . . . . . . . . . . . . . . . . . . . . 2-24

  • Contents

    The MuPAD Libraries

    3Information About a Particular Library . . . . . . . . . . . . . . . . . . 3-2Exporting Libraries . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-4The Standard Library . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-6

    MuPAD Objects

    4Operands: the Functions op and nops . . . . . . . . . . . . . . . . . . . 4-3Numbers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-6Identifiers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-8Symbolic Expressions . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-12

    Operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-12Expression Trees . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-19Operands . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-21

    Sequences . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-24Lists . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-28Sets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-36Tables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-40Arrays . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-44Boolean Expressions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-47Strings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-49Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-52Series Expansions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-56Algebraic Structures: Fields, Rings, etc. . . . . . . . . . . . . . . . . . . 4-60Vectors and Matrices . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-64

    Definition of Matrices and Vectors . . . . . . . . . . . . . . . . . 4-64Computing with Matrices . . . . . . . . . . . . . . . . . . . . . . 4-70Special Methods for Matrices . . . . . . . . . . . . . . . . . . . . 4-72The Libraries linalg and numeric . . . . . . . . . . . . . . . . . 4-74Sparse Matrices . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-77An Application . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-78

    Polynomials . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-81

    vi

  • Contents

    Definition of Polynomials . . . . . . . . . . . . . . . . . . . . . . 4-81Computing with Polynomials . . . . . . . . . . . . . . . . . . . . 4-85

    Hardware Float Arrays . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-92Interval Arithmetic . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-94Null Objects: null(), NIL, FAIL, undefined . . . . . . . . . . . . . . . . 4-99

    Evaluation and Simplification

    5Identifiers and Their Values . . . . . . . . . . . . . . . . . . . . . . . . . 5-1Complete, Incomplete, and Enforced Evaluation . . . . . . . . . . . . . 5-4Automatic Simplification . . . . . . . . . . . . . . . . . . . . . . . . . . 5-10Evaluation at a Point . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-13

    Substitution: subs, subsex, and subsop6

    Differentiation and Integration

    7Differentiation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-2Integration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-4

    Solving Equations: solve8

    Polynomial Equations . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-2General Equations and Inequalities . . . . . . . . . . . . . . . . . . . . 8-9Differential Equations . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-12

    vii

  • Contents

    Recurrence Equations . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-15

    Manipulating Expressions

    9Transforming Expressions . . . . . . . . . . . . . . . . . . . . . . . . . 9-3Simplifying Expressions . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-13Assumptions about Mathematical Properties . . . . . . . . . . . . . . . 9-18

    Chance and Probability

    10

    Graphics

    11Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11-1Easy Plotting: Graphs of Functions . . . . . . . . . . . . . . . . . . . . 11-2

    2D Function Graphs . . . . . . . . . . . . . . . . . . . . . . . . . 11-23D Function Graphs . . . . . . . . . . . . . . . . . . . . . . . . . 11-18

    Advanced Plotting: Principles and First Examples . . . . . . . . . . . . 11-33General Principles . . . . . . . . . . . . . . . . . . . . . . . . . . 11-33Some Examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11-39

    The Full Picture: Graphical Trees . . . . . . . . . . . . . . . . . . . . . 11-46Viewer, Browser, and Inspector: Interactive Manipulation . . . . . . . 11-50Primitives . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11-54Attributes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11-57

    Default Values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11-57Inheritance of Attributes . . . . . . . . . . . . . . . . . . . . . . . 11-58Primitives Requesting Scene Attributes: Hints . . . . . . . . . 11-62The Help Pages of Attributes . . . . . . . . . . . . . . . . . . . . . 11-65

    viii

  • Contents

    Colors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11-67RGB Colors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11-67HSV Colors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11-69

    Animations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11-71Generating Simple Animations . . . . . . . . . . . . . . . . . . . 11-71Playing Animations . . . . . . . . . . . . . . . . . . . . . . . . . . 11-75The Number of Frames and the Time Range . . . . . . . . . . . . 11-76What Can Be Animated? . . . . . . . . . . . . . . . . . . . . . . . 11-78Advanced Animations: The Synchronization Model ....

Recommended

View more >