1. Trang chủ
  2. » Công Nghệ Thông Tin

IT training mathematica by example (4th ed ) abell braselton 2008 09 23

577 114 0

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 577
Dung lượng 10,62 MB

Các công cụ chuyển đổi và chỉnh sửa cho tài liệu này

Nội dung

This book is an appropriate ref-erence for all users of Mathematica and, in particular, for beginning userssuch as students, instructors, engineers, businesspeople, and other profes-sion

Trang 2

Example

Trang 4

Example Fourth Edition

Martha L Abell and James P Braselton

Department of Mathematical Sciences

Georgia Southern University

Statesboro, Georgia

AMSTERDAM • BOSTON • HEIDELBERG • LONDON NEW YORK • OXFORD • PARIS • SAN DIEGO SAN FRANCISCO • SINGAPORE • SYDNEY • TOKYO

Trang 5

This book is printed on acid-free paper  ∞

Copyright©2009 by Elsevier Inc All rights reserved.

No part of this publication may be reproduced or transmitted in any form or by any means, electronic or mechanical, including photocopy, recording, or any information storage and retrieval system, without permission in writing from the publisher Permissions may be sought directly from Elsevier’s Science & Technology Rights Department in Oxford, UK: phone: (+44) 1865 843830, fax: (+44) 1865 853333, E-mail: permissions@elsevier.com You may also complete your request on-line via the Elsevier homepage (http://elsevier.com), by selecting “Support & Contact” then

“Copyright and Permission” and then “Obtaining Permissions.”

Library of Congress Cataloging-in-Publication Data

APPLICATION SUBMITTED

British Library Cataloguing-in-Publication Data

A catalogue record for this book is available from the British Library.

ISBN: 978-0-12-374318-3

For information on all Academic Press publications

visit our Web site atwww.books.elsevier.com

Printed in the United States of America

09 10 11 12 9 8 7 6 5 4 3 2 1

Trang 6

Preface ix

CHAPTER 1 Getting Started 1 1.1 Introduction to Mathematica 1

A Note Regarding Different Versions of Mathematica 2

1.1.1 Getting Started with Mathematica 3

Preview 13

Five Basic Rules of Mathematica Syntax 13

1.2 Loading Packages 13

1.2.1 Packages Included with Older Versions of Mathematica 14

1.2.2 Loading New Packages 15

1.3 Getting Help from Mathematica 17

Mathematica Help 24

1.4 Exercises 28

CHAPTER 2 Basic Operations on Numbers, Expressions, and Functions 31 2.1 Numerical Calculations and Built-in Functions 31

2.1.1 Numerical Calculations 31

2.1.2 Built-in Constants 34

2.1.3 Built-in Functions 35

A Word of Caution 38

2.2 Expressions and Functions: Elementary Algebra 39

2.2.1 Basic Algebraic Operations on Expressions 39

2.2.2 Naming and Evaluating Expressions 44

2.2.3 Defining and Evaluating Functions 47

2.3 Graphing Functions, Expressions, and Equations 52

2.3.1 Functions of a Single Variable 52

2.3.2 Parametric and Polar Plots in Two Dimensions 65

2.3.3 Three-Dimensional and Contour Plots: Graphing Equations 71

2.3.4 Parametric Curves and Surfaces in Space 82

2.3.5 Miscellaneous Comments 94

2.4 Solving Equations 100

2.4.1 Exact Solutions of Equations 100

2.4.2 Approximate Solutions of Equations 110 2.5 Exercises 115 v

Trang 7

CHAPTER 3 Calculus 117

3.1 Limits and Continuity 117

3.1.1 Using Graphs and Tables to Predict Limits 117

3.1.2 Computing Limits 121

3.1.3 One-Sided Limits 123

3.1.4 Continuity 124

3.2 Differential Calculus 128

3.2.1 Definition of the Derivative 128

3.2.2 Calculating Derivatives 135

3.2.3 Implicit Differentiation 138

3.2.4 Tangent Lines 139

3.2.5 The First Derivative Test and Second Derivative Test 148

3.2.6 Applied Max/Min Problems 156

3.2.7 Antidifferentiation 164

3.3 Integral Calculus 168

3.3.1 Area 168

3.3.2 The Definite Integral 174

3.3.3 Approximating Definite Integrals 179

3.3.4 Area 180

3.3.5 Arc Length 186

3.3.6 Solids of Revolution 190

3.4 Series 201

3.4.1 Introduction to Sequences and Series 201

3.4.2 Convergence Tests 205

3.4.3 Alternating Series 209

3.4.4 Power Series 210

3.4.5 Taylor and Maclaurin Series 213

3.4.6 Taylor’s Theorem 217

3.4.7 Other Series 220

3.5 Multivariable Calculus 221

3.5.1 Limits of Functions of Two Variables 222

3.5.2 Partial and Directional Derivatives 224

3.5.3 Iterated Integrals 238

3.6 Exercises 246

CHAPTER 4 Introduction to Lists and Tables 251 4.1 Lists and List Operations 251

4.1.1 Defining Lists 251

4.1.2 Plotting Lists of Points 258

4.2 Manipulating Lists: More onPartand Map 269

4.2.1 More on Graphing Lists: Graphing Lists of Points Using Graphics Primitives 277

4.2.2 Miscellaneous List Operations 283

Trang 8

4.3 Other Applications 283

4.3.1 Approximating Lists with Functions 283

4.3.2 Introduction to Fourier Series 287

4.3.3 The Mandelbrot Set and Julia Sets 299

4.4 Exercises 311

CHAPTER 5 Matrices and Vectors: Topics from Linear Algebra and Vector Calculus 317 5.1 Nested Lists: Introduction to Matrices, Vectors, and Matrix Operations 317

5.1.1 Defining Nested Lists, Matrices, and Vectors 317

5.1.2 Extracting Elements of Matrices 322

5.1.3 Basic Computations with Matrices 325

5.1.4 Basic Computations with Vectors 329

5.2 Linear Systems of Equations 337

5.2.1 Calculating Solutions of Linear Systems of Equations 337

5.2.2 Gauss–Jordan Elimination 342

5.3 Selected Topics from Linear Algebra 349

5.3.1 Fundamental Subspaces Associated with Matrices 349

5.3.2 The Gram–Schmidt Process 351

5.3.3 Linear Transformations 355

5.3.4 Eigenvalues and Eigenvectors 358

5.3.5 Jordan Canonical Form 361

5.3.6 The QR Method 364

5.4 Maxima and Minima Using Linear Programming 366

5.4.1 The Standard Form of a Linear Programming Problem 366

5.4.2 The Dual Problem 368

5.5 Selected Topics from Vector Calculus 374

5.5.1 Vector-Valued Functions 374

5.5.2 Line Integrals 384

5.5.3 Surface Integrals 387

5.5.4 A Note on Nonorientability 391

5.5.5 More on Tangents, Normals, and Curvature inR 3 404

5.6 Matrices and Graphics 415

5.7 Exercises 430

CHAPTER 6 Applications Related to Ordinary and Partial Differential Equations 435 6.1 First-Order Differential Equations 435

6.1.1 Separable Equations 435

6.1.2 Linear Equations 442

Trang 9

6.1.3 Nonlinear Equations 450

6.1.4 Numerical Methods 453

6.2 Second-Order Linear Equations 457

6.2.1 Basic Theory 457

6.2.2 Constant Coefficients 458

6.2.3 Undetermined Coefficients 464

6.2.4 Variation of Parameters 470

6.3 Higher-Order Linear Equations 472

6.3.1 Basic Theory 472

6.3.2 Constant Coefficients 473

6.3.3 Undetermined Coefficients 475

6.3.4 Laplace Transform Methods 481

6.3.5 Nonlinear Higher-Order Equations 492

6.4 Systems of Equations 492

6.4.1 Linear Systems 492

6.4.2 Nonhomogeneous Linear Systems 505

6.4.3 Nonlinear Systems 511

6.5 Some Partial Differential Equations 532

6.5.1 The One-Dimensional Wave Equation 532

6.5.2 The Two-Dimensional Wave Equation 537

6.5.3 Other Partial Differential Equations 547

6.6 Exercises 550

Trang 10

Mathematica by Example bridges the gap that exists between the very

elementary handbooks available on Mathematica and those reference bookswritten for the advanced Mathematica users This book is an appropriate ref-erence for all users of Mathematica and, in particular, for beginning userssuch as students, instructors, engineers, businesspeople, and other profes-sionals first learning to use Mathematica This book introduces the verybasic commands and includes typical examples of applications of these com-mands In addition, the text also includes commands useful in areas such ascalculus, linear algebra, business mathematics, ordinary and partial differen-tial equations, and graphics In all cases, however, examples follow the intro-duction of new commands Readers from the most elementary to advancedlevels will find that the range of topics covered addresses their needs

Taking advantage of Version 6 of Mathematica,Mathematica by ple, Fourth Edition, introduces the fundamental concepts of Mathematica

Exam-to solve typical problems of interest Exam-to students, instrucExam-tors, and scientists.The fourth edition is an extensive revision of the text Features that makethis edition easy to use as a reference and as useful as possible for thebeginner include the following:

1 Version 6 compatibility All examples illustrated in this book were

completed using Version 6 of Mathematica Although many putations can continue to be carried out with earlier versions ofMathematica, we have taken advantage of the new features in Version

com-6 as much as possible

2 Applications New applications, many of which are documented by

references from a variety of fields, especially biology, physics, andengineering, are included throughout the text

3 Detailed table of contents The table of contents includes all

chap-ter, section, and subsection headings Along with the comprehensiveindex, we hope that users will be able to locate information quicklyand easily

4 Additional examples We have considerably expanded the topics

throughout the book The results should be more useful to tors, students, businesspeople, engineers, and other professionalsusing Mathematica on a variety of platforms In addition, severalsections have been added to make it easier for the user to locate

Trang 11

5 Comprehensive index In the index, mathematical examples and

applications are listed by topic or name, and commands along withfrequently used options are also listed Particular mathematical exam-ples as well as examples illustrating how to use frequently usedcommands are easy to locate In addition, commands in the indexare cross-referenced with frequently used options Functions avail-able in the various packages are cross-referenced both by package andalphabetically

6 CD included All Mathematica code that appears in this edition is

included on the CD packaged with the text

7 Exercises at the end of each chapter Each chapter of this edition

concludes with a section of exercises that range from easy to difficult

We began Mathematica by Example in 1990 and the first edition was

published in 1991 Back then, we were on top of the world using tosh IIcx’s with 8 megs of RAM and 40-meg hard drives We tried to chooseexamples that we thought would be relevant to beginning users—typically

Macin-in the context of mathematics encountered Macin-in the undergraduate lum Those examples could also be carried out by Mathematica in a timelymanner on a computer as powerful as a Macintosh IIcx

curricu-Now, we are on the top of the world with iMacs with dual Intel cessors complete with 2 gigs of RAM and 250-gig hard drives, which willalmost certainly be obsolete by the time you read this The examples pre-sented in this book continue to be the ones that we think are most similar

pro-to the problems encountered by beginning users and are presented in thecontext of someone familiar with mathematics typically encountered byundergraduates However, for this edition ofMathematica by Example, we

have taken the opportunity to expand on several of our favorite examplesbecause the machines now have the speed and power to explore them ingreater detail

Other improvements to the fourth edition include the following:

1 Throughout the text, we have attempted to eliminate redundant

examples and added several interesting ones The following changesare especially worth noting:

(a) In Chapter 2, we have increased the number of parametric and

polar plots in two and three dimensions For a sample, seeExamples 2.3.17, 2.3.18, 2.3.21, and 2.3.23

(b) In Chapter 3, we have improved many examples by adding

addi-tional graphics that capitalize on Mathematica’s enhanced dimensional graphics capabilities See especially Example 3.3.15

Trang 12

three-(c) Chapter 4 contains several examples illustrating various

tech-niques for quickly creating plots of bifurcation diagrams, Juliasets, and the Mandelbrot set

(d) The graphics discussion in Chapter 5 has been increased

consi-derably with the addition of Section 5.6, Matrices and Graphs,and the improvement of many of the examples regarding curvesand surfaces in space We have also added a brief discussionregarding the Frenet frame field and curvature and torsion ofcurves in space See Examples 5.5.11 and 5.5.12

(e) In Chapter 6, we have taken advantage of the new Manipulate

function to illustrate a variety of situations and expand onmany examples throughout the chapter For example, see Exam-ple 6.2.5 for a comparison of solutions of nonlinear equations totheir corresponding linear approximations

2 We have included references that we find particularly interesting in

the Bibliography, even if they are not specific Mathematica-relatedtexts A comprehensive list of Mathematica-related publications can

be found on the Wolfram website:

http://store.wolfram.com/catalog/books

Also, be sure to investigate, use, and support Wolfram’s MathWorld,which is simply an amazing web resource for mathematics, Mathe-matica, and other information

Finally, we express our appreciation to those who assisted in this project

We express appreciation to our editor, Lauren Schultz, our production editor,Mara Vos-Sarmiento, and our project manager, Phil Bugeau, at Elsevier forproviding a pleasant environment in which to work In addition, WolframResearch, especially Maryka Baraka, has been most helpful in providing usup-to-date information about Mathematica Finally, we thank those close

to us, especially Imogene Abell, Lori Braselton, Ada Braselton, and MattieBraselton, for enduring with us the pressures of meeting a deadline and forgraciously accepting our demanding work schedules We certainly could nothave completed this task without their care and understanding

Martha Abell(email: martha@georgiasouthern.edu)

James Braselton(email: jbraselton@georgiasouthern.edu)

Statesboro, Georgia December 2007

Trang 14

of Mathematica, 28% are engineers, 21% are computer scientists, 20% arephysical scientists, 12% are mathematical scientists, and 12% are business,social, and life scientists Two-thirds of the users are in industry and gov-ernment, and there are a small (8%) but growing number of student users.However, due to its special nature and sophistication, beginning users need

to be aware of the special syntax required to make Mathematica perform

in the way intended You will find that calculations and sequences of culations most frequently used by beginning users are discussed in detailalong with many typical examples In addition, the comprehensive indexnot only lists a variety of topics but also cross-references commands withfrequently used options.Mathematica by Example serves as a valuable tool

cal-and reference to the beginning user of Mathematica as well as to the moresophisticated user, with specialized needs

For information, including purchasing information, about Mathematica,contact:

Corporate Headquarters:

Wolfram Research, Inc

100 Trade Center DriveChampaign, IL 61820USA

telephone: 217-398-0700fax: 217-398-0747email:info@wolfram.com

Trang 15

Wolfram Research Europe Ltd

10 Blenheim Office ParkLower Road, Long HanboroughOxfordshire OX8 8LN

United Kingdomtelephone: +44-(0) 1993-883400fax: +44-(0) 1993-883800email:info-europe@wolfram.com

Asia:

Wolfram Research Asia Ltd

Izumi Building 8F3-2-15 Misaki-choChiyoda-ku, Tokyo 101Japan

telephone: +81-(0)3-5276-0506fax: +81-(0)3-5276-0509email:info-asia@wolfram.com

A Note Regarding Different Versions of Mathematica

With the release of Version 6 of Mathematica, many new functions andfeatures have been added to Mathematica We encourage users of earlierversions of Mathematica to update to Version 6 as soon as possible Allexamples in Mathematica by Example, fourth edition, were completed

with Version 6 In most cases, the same results will be obtained if youare using Version 5.0 or later, although the appearance of your resultswill almost certainly differ from that presented here However, particu-lar features of Version 6 are used, and in those cases, of course, thesefeatures are not available in earlier versions If you are using an earlier

or later version of Mathematica, your results may not appear in a formidentical to those found in this book: Some commands in Version 5 arenot available in earlier versions of Mathematica; in later versions, somecommands will certainly be changed, new commands added, and obso-lete commands removed For details regarding these changes, please refer

to the Documentation Center You can determine the version of

Math-ematica you are using during a given MathMath-ematica session by enteringeither the command $Version or the command $VersionNumber In thistext, we assume that Mathematica has been correctly installed on the com-puter you are using If you need to install Mathematica on your computer,please refer to the documentation that came with the Mathematica softwarepackage

Trang 16

On-line help for upgrading older versions of Mathematica and installingnew versions is available at the Wolfram Research, website http://www.wolfram.com/.

Details regarding what is different in Mathematica 6 from previousversions of Mathematica can be found at

http://www.wolfram.com/products/mathematica/newin6

Also, when you go to the Documentation Center (under Help in the

Mathematica menu) you can chooseNew in 6 to see the major differences.

In addition, the upper right-hand corner of the main help page for eachfunction will tell you if it is new in Version 6 ( ) or has been updated

in Version 6 ( )

1.1.1 Getting Started with Mathematica

We begin by introducing the essentials of Mathematica The examples sented are taken from algebra, trigonometry, and calculus topics that youare familiar with to assist you in becoming acquainted with the Mathematicacomputer algebra system

pre-We assume that Mathematica has been correctly installed on thecomputer you are using If you need to install Mathematica on your com-puter, please refer to the documentation that came with the Mathematicasoftware package

Start Mathematica on your computer system Using Windows orMacintosh mouse or keyboard commands, activate the Mathematica

Trang 17

program by selecting the Mathematica icon or an existing Mathematicadocument (or notebook) and then clicking or double-clicking on the icon.

If you start Mathematica by selecting the Mathematica icon, a blankuntitled notebook is opened, as illustrated in the following screen shot,

along with theStartup Palette.

When you start typing, the thin black horizontal line near the top of thewindow is replaced by what you type

Trang 18

With some operating

Enter Note that pressing Enter or Return evaluates commands and

press-ing Shift-Return yields a new line Output is displayed below input We

illustrate some of the typical steps involved in working with Mathematica

in the calculations that follow In each case, we type the command andpress Enter Mathematica evaluates the command, displays the result, and

inserts a new horizontal line after the result For example, typing N[, thenpressing the ␲ key on the Basic Math Input palette, followed by typing,

50] and pressing the enter key

TheBasic MathInput

The next calculation can then be typed and entered in the same manner

as the first For example, entering

Plot[{Sin[x], 2Cos[2x]}, {x, 0, 3 p }, PlotStyle → {GrayLevel[0], GrayLevel[0.5]}]

graphs the functions y = sin x and y = 2 cos 2x and on the interval [0, 3␲]

FIGURE 1.1

A two-dimensional plot

Trang 19

With Mathematica 6, you can easily add explanation to the graphic Go

toGraphics in the main menu, followed by Drawings Tools You can use

theDrawing Tools palette to quickly enhance a graphic

In this case we select theArrow button to add two arrows

and then theA button

to add some text to help identify each plot The various elementscan be modified by clicking on them and moving and/or typing asneeded

With Mathematica 6, you can use Manipulateto illustrate how changingvarious parameters affects a given function or functions With the following

Trang 20

command, we illustrate how a and b affect the period of sine and cosine

and c affects the amplitude of cosine:

Manipulate[Plot[{Sin[2Pi/ax], cCos[2Pi/bx]}, {x, 0, 4 p },

PlotStyle → {GrayLevel[0], GrayLevel[.5]}, PlotRange → { – 4 p /2, 4 p /2}, AspectRatio → 1], {{a, 2Pi, “Period for Sine”}, 1, 4},

{{b, 2Pi, “Period for Cosine”}, 1, 5},

{{c, 2Pi, “Amplitude for Cosine”}, 1, 5}]

Period for Sine

Period for Cosine

Amplitude for Cosine

Trang 21

Period for Sine

3.305 Period for Cosine

1.22 Amplitude for Cosine

UsePlot3Dto generate basic three-dimensional plots Entering

Plot3D[Sin[x + Cos[y]], {x, 0, 4 p }, {y, 0, 4 p }, Ticks → None, Boxed → False, Axes → None]

graphs the functionz = sin(x + cos y) for 0 ≤ x ≤ 4␲ and 0 ≤ y ≤ 4␲ shown

in Figure 1.2 To view the image from different angles, use the mouse toselect the graphic and then drag to the desired angle

Notice that every

Mathematica

command begins with

capital letters and the

argument is enclosed

by square

brackets [ ]

Trang 22

Basic Math Input

palette, type x in the

base position, and

then click (or tab to)

the exponent position

and type 3 Use the

esc key, tab button, or

mouse to help you

place or remove the

cursor from its

current location

solve the equation x3− 3x + 1 = 0 for x.

Trang 23

In the first case, the input and output are inStandardForm; in the

sec-ond case, the input and output are inInputForm; and in the third case, the

input and output are inTraditionalForm Move the cursor to the

Mathe-matica menu,

selectCell, and then ConvertTo, as illustrated in the following screen shot:

You can change how input and output appear by using ConvertTo or

by changing the default settings Moreover, you can determine the form ofinput/output by looking at the cell bracket that contains the input/output.For example, even though all three of the following commands look differ-ent, all three evaluate2

0 x3sinx dx:

In the first calculation, the input is in InputForm and the output

in OutputForm; in the second, the input and output are in Form; and in the third, the input and output are in TraditionalForm.

Standard-Throughout Mathematica by Example, fourth edition, we display input

and output usingInputForm (for input) or StandardForm (for output),

unless otherwise stated

Trang 24

To enter code inStandardForm, we often take advantage of the Basic Math Input palette, which is accessed by going to Palettes under the

Mathematica menu and then selectingBasicMathInput See Figure 1.3.

Use the buttons to create templates and enter special characters natively, you can access a complete list of typesetting shortcuts fromMathematica help atguide/MathematicalTypesetting in theDocumentation Center.

Alter-Mathematica sessions are terminated by entering Quit[ ] or by ing Quit from the File menu, or by using a keyboard shortcut, such as command-Q, as with other applications They can be saved by referring

select-toSave from the File menu.

Mathematica allows you to save notebooks (as well as combinations

of cells) in a variety of formats, in addition to the standard Mathematicaformat

FIGURE 1.3

Mathematica 6 palettes

Trang 25

Remark 1.1 Input and text regions in notebooks can be edited Editing input can create a

notebook in which the mathematical output does not make sense in the sequence

it appears It is also possible to simply go into a notebook and alter input withoutdoing any recalculation This also creates misleading notebooks Hence, commonsense and caution should be used when editing the input regions of notebooks.Recalculating all commands in the notebook will clarify any confusion

Trang 26

In order for the Mathematica user to take full advantage of this powerfulsoftware, an understanding of its syntax is imperative The goal of Math- ematica by Example is to introduce the reader to the Mathematica com-

mands and sequences of commands most frequently used by beginningusers Although the rules of Mathematica syntax are far too numerous tolist here, knowledge of the following five rules equips the beginner with thenecessary tools to start using the Mathematica program with little trouble

Five Basic Rules of Mathematica Syntax

1 The arguments of all functions (both built-in ones and ones that you

define) are given in brackets [ .] Parentheses ( .) are used forgrouping operations; vectors, matrices, and lists are given in braces

{ .}; and double square brackets [[ .]] are used for indexing listsand tables

2 Every word of a built-in Mathematica function begins with a capital

letter

3 Multiplication is represented by a ∗ or space between characters.Enter 2∗x∗yor2x y to evaluate 2xy not 2xy

4 Powers are denoted by a ∧ Enter(8∗x^3)^(1/3) to evaluate (8x3)1/3=

81/3(x3)1/3= 2x instead of8x^1/3, which returns 8x/3

5 Mathematica follows the order of operations exactly Thus,

enter-ing (1 + x)^1/xreturns (1+x)

1

x , whereas(1 + x)^(1/x)returns (1 +x)1/x.Similarly, entering x^3x returns x3· x = x4

, whereas entering x^(3x)

returnsx3x

Remark 1.2 If you get no response or an incorrect response, you may have entered or executed

the command incorrectly In some cases, the amount of memory allocated toMathematica can cause a crash Like people, Mathematica is not perfect anderrors can occur

Trang 27

or send the message “help” to mathsource@wri.com If desired, you canpurchase MathSource on a CD directly from Wolfram Research, or you canaccess MathSource from the Wolfram Research website.

With Mathematica 6, many packages included with previous versions ofMathematica have been made obsolete because their functionality has beenincorporated into Mathematica, combined into a new package, or elimi-nated altogether In addition toMathSource, you should also think about

investigating Wolfram’sMathWorld website.

1.2.1 Packages Included with Older Versions of

Mathematica

Packages are loaded by entering the command <<directory`packagename`,

Needs[directory`packagename`], <<packagename` or Needs[packagename`],where directory is the location of the package packagename Entering

the command <<directory`Master` makes all the functions contained in allthe packages in directory available In this case, each package need not

be loaded individually

Over time, Wolfram

Research expects that

packages will become

obsolete and that

is a real-valued function for all values of x Nevertheless, when we ask

Mathematica to plot the function withPlot,

Plot[(x – 1) ∧ (1 / 3)(x + 1) ∧ (2 / 3), {x, – 2, 2}, PlotStyle → GrayLevel[0]]

we see in Figure 1.4 that Mathematica does not compute real values forx

values between −1 and 1 because complex roots are selected by matica for the x values between −1 and 1, which is where the values of

0.51.01.52.0

FIGURE 1.4

When computing odd roots of negative numbers, Mathematica returns complex values

Trang 28

output; N[x] returns a numerical approximation of x, and Abs[x] returnsthe absolute value of the numberx.)

To instruct Mathematica to select the real third root, we load the

RealOnly package that is contained in the Miscellenous directory Note

that theRealOnly package has been included with many versions of

Mathe-matica but not included with Mathematica 6 If you need to obtain the

RealOnly package, you need to download it from the Wolfram website.

After loading the package, when we reenter thePlotcommand, ica generates the expected plot, which is shown in Figure 1.5

Mathemat-<< Miscellaneous`RealOnly`

Plot[(x – 1) ∧ (1/3)(x + 1) ∧ (2/3), {x, – 2, 2}, PlotStyle → GrayLevel[0]]

1.2.2 Loading New Packages

One new package included with Mathematica 6 isVectorFieldPlots, which

replaces several packages in previous versions of Mathematica

Trang 29

22 21 1 2 x

21.521.020.5

0.51.01.52.0

y

FIGURE 1.5

We see the real values of f(x) for −1 < x < 1 after loading the RealOnly package

Example 1.2.1 The differential equation dy/dx = cos(y/x) is a first-order homogeneous

differential equation Using DSolve, we see that the solution contains an integral

that does not have a known closed form The result returned by DSolve indicates

Trang 30

that the integral curves for the differential equation satisfy the equation containedwithin the brackets in the output:

DSolve[y  [x] == Cos[y[x]/x], y[x], x]

Solve::tdep: The equations appear to involve the variables to be solvedfor in an essentially nonalgebraic way.

To see how the solutions of the differential equation behave, we plot a

direction field or slope field for the equation For this equation, the slope of

a solution at (x, y) satisfies dy/dx = cos( y/x) A direction field for the equation is generated by selecting a grid of (x, y) points and then plotting line segments at those points with slope dy/dx = cos( y/x) With Mathematica, we can do so with

the VectorFieldPlot function that is contained in the VectorFieldPlots package.

First, we load the package with

<< VectorFieldPlots`;

Now that the package has been loaded, you can can use ? or Options toobtain information about the commands contained in the package Finally, wegenerate a slope field for the equation with

p1 = VectorFieldPlot[{1, f[x, y]}, {x, – 2Pi, 2Pi}, {y, – 2Pi, 2Pi}, PlotPoints → 25];

Show[p1, Axes → Automatic, AxesOrigin → {0, 0}]

Note that Mathematica returns several error messages due to the division by

0 in they/x term that are not displayed here The plot is displayed in Figure 1.6.

From the slope field, we see that solutions of the differential equation can behave

quite strangely near x = 0.

1.3 GETTING HELP FROM MATHEMATICA

Becoming competent with Mathematica can take a serious investment oftime Hopefully, messages that result from syntax errors are viewed light-heartedly Ideally, instead of becoming frustrated, beginning Mathematicausers will find it challenging and fun to locate the source of errors Fre-quently, Mathematica’s error messages indicate where the error(s) hasoccurred In this process, it is natural that you will become more proficient

Trang 31

FIGURE 1.6

Numerically solving a differential equation such as dy / dc = cos(y / x) is difficult To

help us understand how the solutions behave, we use a slope field

with Mathematica In addition to Mathematica’s extensive help facililities,which are described next, a tremendous amount of information is availablefor all Mathematica users at the Wolfram Research website Not only canyou get significant Mathematica help at the Wolfram website but also youcan access outstanding mathematical resources at Wolfram’s MathWorld

resource,

http://mathworld.wolfram.com

One way to obtain information about Mathematica commands and tions, including user-defined functions, is the command ? ?object gives

func-a bfunc-asic description func-and syntfunc-ax informfunc-ation of the Mfunc-athemfunc-aticfunc-a objectobject

??object yields detailed information regarding syntax and options for theobjectobject Equivalently,Information[object]yields the information on theMathematica objectobject returned by both ?object and Options[object] inaddition to a list of attributes of object Note that object may either be

a user-defined object or a built-in Mathematica object

Trang 32

Example 1.3.1 Use ? and ?? to obtain information about the command Plot.

Solution ?Plot uses basic information about the Plot function,

whereas ??Plot includes basic information as well as a list of options and theirdefault values

If you click on the >> button, Mathematica returns its extensive description of

the function Notice that the updated button in Version 6 ( ) shows that

Plot has been updated Click on Show Changes and then More Information to

see the changes in Version 6

Options[object] returns a list of the available options associated withobjects along with their current settings This is quite useful when work-ing with a Mathematica command such asParametricPlot, which has manyoptions Notice that the default value (the value automatically assumed byMathematica) for each option is given in the output

Trang 33

Example 1.3.2 Use Options to obtain a list of the options and their current settings for the

command ParametricPlot

Solution The command Options [ParametricPlot] lists all the options and their current

settings for the command ParametricPlot

Trang 34

The command Names["form"] lists all objects that match the pattern defined

in form For example, Names ["Plot"] returns Plot, Names["∗Plot"] returns allobjects that end with the string Plot, Names["Plot∗"] lists all objects that beginwith the string Plot, and Names["∗Plot∗"] lists all objects that contain the stringPlot Names["form",SpellingCorrection->True] finds those symbols that match thepattern defined in form after a spelling correction

Example 1.3.3 Create a list of all built-in functions beginning with the string Plot.

Solution We use Names to find all objects that match the pattern Plot.

Next, we use Names to create a list of all built-in functions beginning with thestring Plot

In the following, after using? to learn about the new Mathematica 6 tionColorDatawe illustrate its use with aPlotcommand We first go to theMathematica menu

func-and selectPalettes, followed by ColorSchemes.

Trang 35

We are given a variety of choices, which are illustrated throughout

Mathematica by Example.

Remember that on a

computer running

Mathematica, these

graphics will appear

in color rather than

in black-and-white as

seen in this text

We then use the help facilities description of the ColorData function

to help us generate a plot of y = sin x on the interval [0, 2␲] in deep red

on our computer (Of course, the plot is dark gray in a black-and-white textsuch as this)

As we have illustrated, the?function can be used in many ways ing?letters∗gives all Mathematica objects that begin with the string letters;

Enter-?∗letters∗ gives all Mathematica objects that contain the stringletters; and

?∗lettersgives all Mathematica commands that end in the stringletters

Example 1.3.4 What are the Mathematica functions that (a) end in the string Cos, (b) contain the

string Sin, and (c) begin with the string Polynomial?

Trang 36

Solution Entering

returns all functions ending with the string Cos, entering

returns all functions containing the string Sin, and entering

returns all functions that begin with the string Polynomial

Trang 37

Mathematica Help

Additional help features are accessed from the Mathematica menu under

Help For basic information about Mathematica, go to the Mathematica

menu, followed byHelp

and selectDocumentation Center.

Trang 38

If you are a beginning Mathematica user, you may choose to selectFirst Five Minutes with Mathematica.

To obtain information about a particular Mathematica object or function,open the Documentation Center, type the name of the object, func-

tion, or topic, and press the Go (>>) button as we have done here with

ExampleData A typical help window contains not only a detailed tion of the command and its options but also hyperlinked cross-references

descrip-to related commands and can be accessed by clicking on the appropriatelinks

Trang 39

You can also use the Documentation Center to search for help

regarding a particular topic In this case, we enter color schemes in thetop line of theDocumentation Center and then click on the >> button

(or pressEnter) to see all the on-line help regarding “color schemes.”

Clicking on the topic will take you to the documentation for the topic.Here is what we see when we selectColorDataFunction:

Trang 40

As you become more proficient with Mathematica, you will want to learn

to take advantage of its extensive capabilities

Remember that Mathematica contains thousands of functions to performmany tasks If you wish to perform a task that is not discussed here, go

to theDocumentation Center and type a few words related to what you

want to do

Example 1.3.5 In this example, we investigate digit operations Mathematica by Example, fourth

edition, has a copyright in 2008, which has four digits

Ngày đăng: 05/11/2019, 13:14

TỪ KHÓA LIÊN QUAN