105,99 €
A hands-on introduction to the theoretical and computational aspects of linear algebra using Mathematica® Many topics in linear algebra are simple, yet computationally intensive, and computer algebra systems such as Mathematica® are essential not only for learning to apply the concepts to computationally challenging problems, but also for visualizing many of the geometric aspects within this field of study. Principles of Linear Algebra with Mathematica uniquely bridges the gap between beginning linear algebra and computational linear algebra that is often encountered in applied settings, and the commands required to solve complex and computationally challenging problems using Mathematica are provided. The book begins with an introduction to the commands and programming guidelines for working with Mathematica. Next, the authors explore linear systems of equations and matrices, applications of linear systems and matrices, determinants, inverses, and Cramer's rule. Basic linear algebra topics, such as vectors, dot product, cross product, and vector projection are explored, as well as a unique variety of more advanced topics including rotations in space, 'rolling' a circle along a curve, and the TNB Frame. Subsequent chapters feature coverage of linear transformations from Rn to Rm, the geometry of linear and affine transformations, with an exploration of their effect on arclength, area, and volume, least squares fits, and pseudoinverses. Mathematica is used to enhance concepts and is seamlessly integrated throughout the book through symbolic manipulations, numerical computations, graphics in two and three dimensions, animations, and programming. Each section concludes with standard problems in addition to problems that were specifically designed to be solved with Mathematica, allowing readers to test their comprehension of the presented material. All related Mathematica code is available on a corresponding website, along with solutions to problems and additional topical resources. Extensively class-tested to ensure an accessible presentation, Principles of Linear Algebra with Mathematica is an excellent book for courses on linear algebra at the undergraduate level. The book is also an ideal reference for students and professionals who would like to gain a further understanding of the use of Mathematica to solve linear algebra problems.
Sie lesen das E-Book in den Legimi-Apps auf:
Seitenzahl: 663
Veröffentlichungsjahr: 2013
Contents
Preface
Conventions and Notations
Chapter 1: An Introduction to Mathematica
1.1 The Very Basics
1.2 Basic Arithmetic
1.3 Lists and Matrices
1.4 Expressions versus Functions
1.5 Plotting and Animations
1.6 Solving Systems of Equations
1.7 Basic Programming
Chapter 2: Linear Systems of Equations and Matrices
2.1 Linear Systems of Equations
2.2 Augmented Matrix of a Linear System and Row Operations
2.3 Some Matrix Arithmetic
Chapter 3: Gauss—Jordan Elimination and Reduced Row Echelon Form
3.1 Gauss-Jordan Elimination and rref
3.2 Elementary Matrices
3.3 Sensitivity of Solutions to Error in the Linear System
Chapter 4: Applications of Linear Systems and Matrices
4.1 Applications of Linear Systems to Geometry
4.2 Applications of Linear Systems to Curve Fitting
4.3 Applications of Linear Systems to Economics
4.4 Applications of Matrix Multiplication to Geometry
4.5 An Application of Matrix Multiplication to Economics
Chapter 5: Determinants, Inverses, and Cramer’s Rule
5.1 Determinants and Inverses from the Adjoint Formula
5.2 Finding Determinants by Expanding along Any Row or Column
5.3 Determinants Found by Triangularizing Matrices
5.4 LU Factorization
5.5 Inverses from rref
5.6 Cramer’s Rule
Chapter 6: Basic Vector Algebra Topics
6.1 Vectors
6.2 Dot Product
6.3 Cross Product
6.4 Vector Projection
Chapter 7: A Few Advanced Vector Algebra Topics
7.1 Rotations in Space
7.2 “Rolling” a Circle along a Curve
7.3 The TNB Frame
Chapter 8: Independence, Basis, and Dimension for Subspaces of n
8.1 Subspaces of n
8.2 Independent and Dependent Sets of Vectors in n
8.3 Basis and Dimension for Subspaces of n
8.4 Vector Projection onto a Subspace of n
8.5 The Gram-Schmidt Orthonormalization Process
Chapter 9: Linear Maps from n to m
9.1 Basics about Linear Maps
9.2 The Kernel and Image Subspaces of a Linear Map
9.3 Composites of Two Linear Maps and Inverses
9.4 Change of Bases for the Matrix Representation of a Linear Map
Chapter 10: The Geometry of Linear and Affine Maps
10.1 The Effect of a Linear Map on Area and Arclength in Two Dimensions
10.2 The Decomposition of Linear Maps into Rotations, Reflections, and Rescalings in 2
10.3 The Effect of Linear Maps on Volume, Area, and Arclength in 3
10.4 Rotations, Reflections, and Rescalings in Three Dimensions
10.5 Affine Maps
Chapter 11: Least-Squares Fits and Pseudoinverses
11.1 Pseudoinverse to a Nonsquare Matrix and Almost Solving an Overdetermined Linear System
11.2 Fits and Pseudoinverses
11.3 Least-Squares Fits and Pseudoinverses
Chapter 12: Eigenvalues and Eigenvectors
12.1 What Are Eigenvalues and Eigenvectors, and Why Do We Need Them
12.2 Summary of Definitions and Methods for Computing Eigenvalues and Eigenvectors as Well as the Exponential of a Matrix
12.3 Applications of the Diagonalizability of Square Matrices
12.4 Solving a Square First-Order Linear System of Differential Equations
12.5 Basic Facts about Eigenvalues, Eigenvectors, and Diagonalizability
12.6 The Geometry of the Ellipse Using Eigenvalues and Eigenvectors
12.7 A Mathematica Eigen-Function
Bibliographic Material
Indexes
PURE AND APPLIED MATHEMATICS
A Wiley Series of Texts, Monographs, and Tracts
Founded by RICHARD COURANT
Editors Emeriti: MYRON B. ALLEN III, DAVID A. COX, PETER HILTON, HARRY HOCHSTADT, PETER LAX, JOHN TOLAND
A complete list of the titles in this series appears at the end of this volume.
Copyright © 2011 by John Wiley & Sons, Inc. All rights reserved.
Published by John Wiley & Sons, Inc., Hoboken, New Jersey.
Published simultaneously in Canada.
No part of this publication may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, electronic, mechanical, photocopying, recording, scanning, or otherwise, except as permitted under Section 107 or 108 of the 1976 United States Copyright Act, without either the prior written permission of the Publisher, or authorization through payment of the appropriate per-copy fee to the Copyright Clearance Center, Inc., 222 Rosewood Drive, Danvers, MA 01923, (978) 750-8400, fax (978) 750-4470, or on the web at www.copyright.com. Requests to the Publisher for permission should be addressed to the Permissions Department, John Wiley & Sons, Inc., 111 River Street, Hoboken, NJ 07030, (201) 748-6011, fax (201) 748-6008, or online at http://www.wiley.com/go/permission.
Limit of Liability/Disclaimer of Warranty: While the publisher and author have used their best efforts in preparing this book, they make no representations or warranties with respect to the accuracy or completeness of the contents of this book and specifically disclaim any implied warranties of merchantability or fitness for a particular purpose. No warranty may be created or extended by sales representatives or written sales materials. The advice and strategies contained herein may not be suitable for your situation. You should consult with a professional where appropriate. Neither the publisher nor author shall be liable for any loss of profit or any other commercial damages, including but not limited to special, incidental, consequential, or other damages.
For general information on our other products and services or for technical support, please contact our Customer Care Department within the United States at (800) 762-2974, outside the United States at (317) 572-3993 or fax (317) 572-4002.
Wiley also publishes its books in a variety of electronic formats. Some content that appears in print may not be available in electronic formats. For more information about Wiley products, visit our web site at www.wiley.com.
Library of Congress Cataloging-in-Publication Data:
Shiskowski, Kenneth, 1954–Principles of linear algebra with Mathematica / Kenneth Shiskowski, Karl Frinkle.p. cm. — (Pure and applied mathematics) Includes index.ISBN 978-0-470-63795-1 (hardback)1. Algebras, Linear—Data processing. 2. Mathematica (Computer file) I. Frinkle, Karl, 1977– II. Title.QA185.D37S454 2011
512′.5028553—dc222011006420
With all textbooks, one should attempt to be consistent with notation, not only within the text, but also within the field of mathematics on which it is based. For the most part, we have done this.
Preface
This book is an attempt to cross the gap between beginning linear algebra and the computational linear algebra that one encounters more frequently in applied settings. The underlying theory behind many topics in the field of linear algebra is relatively simple to grasp; however, to actually apply this knowledge to nontrivial problems becomes computationally intensive. To do these computations by hand would be tedious at best, and many times simply unrealistic. Furthermore, attempting to solve such problems by the old pencil-and-paper method does not give the average reader any extra insight into the problem. Mathematica® allows readers to overcome these obstacles, giving them the power to perform complex computations that would take hours by hand, and can help to visualize many of the geometric interpretations of linear algebra topics in two and three dimensions in a very intuitive fashion. We hope that this book will challenge the reader to become proficient in both theoretical and computational aspects of linear algebra.
Chapter 1 of this book is a brief introduction to Mathematica and will help the reader become more comfortable with the program. This chapter focuses on the commands and programming most commonly used when studying linear algebra and its applications. Mathematica commands will always be in bold, with output (if any) displayed in a left-justified fashion below each Mathematica command. Readers can enter these commands and obtain the same results, assuming that they have entered the commands correctly. Note also that all of the images in this book were produced with Mathematica. The overall intent of this book is to use Mathematica to enhance the concepts of linear algebra, and therefore Mathematica is integrated into this book in a very casual manner. Where one normally explains how to perform some operation by hand in a standard text, we often simply use Mathematica commands to perform the same task. Thus, the reader should attempt to become familiar with the Mathematica syntax as quickly as possible.
At the end of each section, you will find two types of problems: “Homework problems” and “Mathematica problems”. The former consists of strictly pen-and-pencil computation problems, inquiries into theory, and questions about concepts discussed in the section. The idea behind these problems is to ensure that the reader has an understanding of the concepts introduced and can put them to use in problems that can be worked out by hand. For example, Mathematica can multiply matrices together much faster than any person can and without any algebraic mistakes, so why should the reader ever perform these tasks by hand? The answer is simple: In order to fully grasp the mechanics of matrix multiplication, simple problems must be worked out by hand. This manual labor, although usually deemed tedious, is an important tool in learning reinforcement. The “Mathematica problems” portion of the homework typically involves problems that would take too long, or would be too computationally complex, to solve by hand. There are many problems in the “Mathematica problems” portion that simply ask you to verify your answers to questions from the preceding “Homework problems”, implying that you can think of Mathematica as a “solutions manual” for a large percentage of this text. You will also notice that several sections are missing the “Homework problems” section. These sections correspond to special topics that are discussed because they can be explored in detail only with Mathematica.
We suggest that students and instructors alike visit the book’s companion Website, which can be found at either of the following addresses:
http://carmine.se.edu/kfrinkle/PrinciplesOfLinearAlgebraWithMathematica
http://people.emich.edu/kshiskows/PrinciplesOfLinearAlgebraWithMathematica
At these locations, you can download Mathematica notebooks, corresponding to each section’s Mathematica commands, along with many other resources. These files can be used with the book to enable the reader to do problems or practice the material without retyping the entire Mathematica code. We highly suggest that all readers unfamiliar with Mathematica (and even those who are) read over the relevant sections of the “Introduction to Mathematica” notebook before they get too far into the book in order to understand the Mathematica code more fully. Specifically, we suggest looking at plotting/graphing material, differences between sets, lists and strings, and expressions versus functions and how Mathematica uses each. “Homework problems” solutions and “Mathematica problems” notebooks are also available for download.
It would be nice if we could always cover all of the topics that we wanted to in a given course. This rarely happens, but there are obviously core topics that should be covered. Furthermore, some of the advanced topics require knowledge beyond what students in a basic linear algebra course may have. The appropriate prerequisites for this course would be trigonometry and a precalculus course in algebra. Also, a computer programming course would be helpful because we are using Mathematica. A year-long course in calculus would also be beneficial in regard to several topics. Here is a list of sections that require advanced knowledge:
We suggest that as much of the book be covered as possible, but here is the minimum suggested course outline:
On inspection of this outline, you will notice that Chapters 4, 7, and 10 have been completely omitted. Chapter 4 has interesting applications of matrix multiplication to geometry, business, finance, and curve fitting, and we highly suggest covering Sections 4.1 and 4.4. Curve fitting is covered in Section 4.2, but is covered in greater depth in Chapter 11, where pseudoinverses and the method of least-squared deviation are introduced. Chapter 7 contains applications of the information learned about vectors in Chapter 6. If you wish to cover any of the topics in Chapter 10, we highly suggest that you cover Section 7.1. Chapter 10 is a fun chapter on linear maps and how they affect geometric objects. Affine maps are included in this chapter and should be given serious consideration as a topic to cover.
We hope that both students and instructors will find this book to be a unique read. Our goal was to tell a story, rather than follow the standard textbook formula of definition, theorem, example, and then repeat for 500 pages. We also hope that you really enjoy using Mathematical both to explore the geometric and computational aspects of linear algebra, and to verify your pencil-and-paper work. We very much would like to hear your comments. Some of the questions we would always like answered, from both the student and the instructor, follow:
It would be wonderful if this text, in its first edition, were free of errors: both grammatical and mathematical. However, no matter how many times we read and proofread this text, it is a certainty that something will be missed. We hope you contact us with any and all mistakes that you have found, along with any comments and suggestions that you may have.
First, we would like to express our thanks to Jacqueline Palmieri, Kellsee Chu, Stephen Quigley, and Susanne Steitz-Filler of John Wiley & Sons, Inc. for making the entire process, from the original proposal, to project approval, to final submission, incredibly smooth. The four of you were supportive, encouraging, very enthusiastic, and quick to respond to any questions that arose over the course of this project. We appreciate this very much. We would also like to thank the following individuals who were involved in the original peer review process:
In addition, Chris Moretti spent a significant amount of time patiently answering many of our questions and wrote numerous manipulation procedures and standalone notebooks for the Website, some of which appear in this text. His comments and suggestions really made this book more seamlessly integrate with Mathematica. A special thanks also goes to Bobbi Page, who took the time to read large portions of early drafts of this book, pored over the copious copyedits, and made many invaluable suggestions. The four successive spring semester linear algebra students at Southeastern Oklahoma State University deserve a warm round of applause for being guinea pigs and error hunters. Thanks also goes out to the countless students from the many courses that Dr. Shiskowski has taught at Eastern Michigan University. We would also like to thank Mark Bickham, whose idea for a title to this book finally made both authors happy. Thanks again to everyone who was involved in this project, at any point, at any time. If we forgot to add your name this time around, perhaps you will make it into the second edition.
Kenneth Shiskowski
Karl Frinkle
Eastern Michigan University
Southeastern Oklahoma State University
Mathematica is an extremely powerful mathematical software package (or computer algebra system) that incorporates text editing, mathematical computation, and programming as well as 2D and 3D graphics capabilities. You can literally write a complete mathematics textbook using only Mathematica where your book includes all of the text and graphics in one smoothly flowing document. If you have never or only slightly used Mathematica before, then it will take some effort to learn how it works—believe me that it is well worth the time expended for the ability to do mathematically almost anything you can dream of that a computer might be able to do for you. In this introduction to Mathematica, you will see only a fraction of its capabilities, but hopefully enough to get you well on your way in doing 2D and 3D graphics, solving of equations, defining and using functions, lists and matrices, along with some basic mathematical programming.
This chapter discusses the fundamentals of using Mathematica for the novice user. If you are already familiar with Mathematica, you may wish to skip this chapter, although we warn you that to do so would be at your own risk. The new user of Mathematica will find it quite difficult in the beginning, but with practice and patience, you will master all of the basics and in time come to enjoy using Mathematica.
Mathematica files are called notebooks, and in a notebook you can place text along with input commands and their associated outputs which can be literally anything such as graphics, tables or lists, and functions. You can group the material in a notebook into different types of cells that are indicated on the right side of the notebook by brackets. At the top of the notebook you will see the tab Palettes and under it is the Writing Assistant, which will allow you to create new cells and/or modify cells. You can use Writing Assistant to change the font, color, and size of the text in your cells and you can also do this using the Format tab at the top of the notebook. The word processing capabilities of Mathematica are very similar to those of Microsoft Word with as copy and as paste, as delete and copy, which can be pasted elsewhere.
The commands and will create Input and Text cells, respectively, after a horizontal line break between cells. Almost all Mathematica cells are Input or Text cells, or Output cells that are created when you activate an Input cell. Input and Output cells are normally in pairs with Output second directly following its Input. You can also create a new cell after a line break by typing in some text where you can control the type of cell you are writing in by using the menu which is open at the upper left of the screen next to the Save (or disk) icon.
Each section or chapter of a notebook file in Mathematica should be created as a section where the first cell of the section is a Subtitle cell that can be created by placing a horizontal bar between or just after a cell and then choosing Subtitle from the pulldown menu at the very top left of the lower ruler at the top of your screen. In order to create a subsection of this section (or chapter), do the same as just described but choose the Subsection from this menu. If you have not already used the Window tab to insert the Toolbar in your notebook, then please do so now. With the Toolbar in place, you can now change the type of cell you are in by using the pulldown menu at its far left. The Ruler can also be inserted into your notebook if you want it from the Window tab. Note that for those of us who like our text in a larger style, Window also has a Magnification feature that is quite handy.
If you wish to delete a cell (use ) or modify its entire contents in some way, then click on the cell tag or bracket on the right and then carry out the desired operation using Writing Assistant or the tabs at the top of the screen or simply for a complete deletion. In text, in order to create a new paragraph in a cell, use . To do the same in an Input cell where commands are placed, use as well. If you wish to split a cell, then use with the cursor at the location of the split. In using Writing Assistant or any pulldown tab, if you click on the triangles on the left you will open or close one of the sections inside this tab. Note that text paragraphs are not necessarily indented automatically, so you must indent them yourself manually if you want this to happen.
If you wish to close a group of cells and see only the first cell of the group (which should be the title cell of the group), then double-click on the far-right bracket for the group. You will then see a cell bracket with an arrow to the right of the cell bracket of the title or first cell of the group. If you double-click on this arrow, then you can open all the cells of this group. The copy and paste features of Mathematica are the same as those of Microsoft Word and other software. If you wish to change the size, font, or other feature of a collection of cells, select one of them by clicking on its bracket and then hold the key down while you select the rest of the cells—now go to the Format tab or other location and carry out your change.
It is strongly recommended that you save (use ) your work constantly since, like all software, Mathematica can glitch, which could cause you to loose some or all of your material. You should have backup copies of all of your work on a separate computer or flash drive since from our own personal experience, we know that unfortunate problems can occur.
If you are using Mathematica to do homework problems, it is strongly suggested that you place each problem in a single group of cells with the first cell as the title of the problem. This will make it much easier to organize your work both for yourself and the instructor who may read your material. After you have finished working in a particular Mathematica notebook, it is also recommended that you delete all of your output from the file unless it will take too long to recompute it. Most, if not all, of the size of a Mathematica file will be due to graphics, especially 3D graphics, and such files can become very large and consequently take Mathematica quite a while to open or save, and at such times an error can occur. Under the tab Cell, you have the command Delete All Output, which removes all output from the entire file—you might use this periodically while working in a notebook in order to shorten the file. When you reopen a notebook where all output has been deleted, you can reconstruct it all by going to the tab Evaluation and using the command Evaluate Cells; the Input cells will then be evaluated from the first one of the notebook to the last one.
If a Mathematica calculation is taking too long and/or you notice that there is an error in the input, then, in order to terminate the calculation, you should go to the Evaluation tab at the top of the screen and select Abort Evaluation. This should immediately halt the calculation in its tracks unless Mathematica is stuck in some enormous loop and cannot find its way out—then your only alternative might be to use and/or turn your computer off, that is, gently pull the plug on the machine, while apologizing to it.
Beware of using capital letters to define a quantity in Mathematica as it might already be a built-in command name that you cannot override with something else. You should also avoid using the capital letters C, D and N for any kind of variable or name in Mathematica as they are also command names. The commands Clear and Clear All will undefine a quantity that you have named. If you use the command Exit[], it should clear everything from memory that you have defined and Mathematica has produced as output by quitting the Mathematica kernel, which is the core of Mathematica.
If you are using a Mathematica command, but have forgotten how to use it, then place the cursor in the middle of the command name and hit the key to have Mathematica bring up the Help file for this command name. You can also go directly to Help and type in the command name yourself, especially if you have forgotten its correct spelling. Don’t forget that every command name in Mathematica has its first letter capitalized.
If you place a semicolon (;) at the end of a named input, then Mathematica will not give any associated output even though it internally carried out your command and stored it to the name given it. This feature can be useful when the output would be very long and you do not need to see it all displayed, only have it computed and/or stored.
Mathematica can use standard mathematical notation for powers k2 and fractions where after the base k is typed will give a power location and after a numerator is typed will create a fraction and placement for the denominator—both keys must be used simultaneously. If you use these keys after a space, then Mathematica creates blank shells and for the appropriate quantities to be inserted.
Finally, if you are a novice or beginner at using Mathematica, then besides this introductory material there are many videos on YouTube that explain most of the basic features of Mathematica. It is strongly suggested that you seek these out and hopefully will find a few useful ones for doing what you are interested in. Mathematica itself has tutorials that you should consider using if you find them useful.
In this section, we will start to use Mathematica to do some basic arithmetic and algebra computations. In the arithmetic, which is done first, we will add and multiply, factor positive integers into products of powers of primes, find the greatest common divisor (GCD) and the least common multiple (LCM) of two positive integers, and more. In the algebra, we will factor polynomials, divide one polynomial into another to get their quotient and remainder, solve for the roots of a polynomial and also solve equations for their unknowns, and perform other algebraic operations.
In order to create an Input cell where you can do your calculations, go to the tab Palettes and bring up Classroom Assistant. Now click on the tab CreateInput Cell with the cursor at the end of our prior work. Now you will have a new Input cell as part of your current group of cells. Both palettes, Classroom Assistant and Basic Math Assistant, have symbols such as π in them as well as the natural number e.
In the first input cell below, you will find the command 1 + 1. If you hit with the cursor on this line, then Mathematica will carry out your command and produce 2 as an output. After you get the output, Mathematica automatically assumes that you want another Input cell, and so typing right after an output will be in a new Input cell. You can also go back and insert a new Input cell by creating a horizontal bar between two Input cells by clicking on the region between the two cells, and then using while creates a text cell. You can insert a Text cell between Input cells by creating the horizontal line divider between cells by clicking on the space between the cells and then using Text Cell out of the tab Text Cells in Writing Assistant In addition, if you type in a Mathematica command name such as FactorInteger, but now you have forgotten precisely how it works and need its help file, then put the cursor in the command name and hit .
Note that Mathematica will also recognize a space in a product as multiplication, although for safety sake you might want to put in all of your multiplications directly. Mathematica gives exact answers in a calculation if the inputs are all also exact values, but any value with a decimal point in it is treated by Mathematica as an approximation and it gives an approximate answer back. The command N[V, m] will give the approximate value of the quantity V to m digits of accuracy. Mathematica can answer most computational questions to an arbitrary number of digits of precision—look up the command WorkingPrecision to see how it can be done as an alternative to the use of the command N. In the last example of this arithmetic section we also multiply three complex numbers using Product—a complex number in Mathematica is expressed as a + bi for a and b real numbers.
In order to get a power of something in Mathematica that is placing a superscript, use together to get an exponent location after you have already typed in the base. If you want a fraction in the same standard way, then type the numerator followed by and then the denominator in the location created:
Now we switch from arithmetic to algebra. Our algebra will be mainly polynomial and similar to what we did in the arithmetic part above, although we will find the roots of polynomials as well. After the first two computations of multiplying out two polynomials and then dividing the one of larger degree by the smaller-degree one, we will name or define the two polynomials as Poly1 and Poly2, and then repeat the process to see that Mathematica understands what we want. Also, we define the list called QR below which is the quotient first and remainder second in our division of Poly2 by Poly1—a list is an ordered collection of objects that Mathematica places {} around its elements, with commas between the elements. Then QR[[l]] is the quotient and QR[[2]] is the remainder in the division. We will discuss lists and matrices in the next chapter.
One last bit of useful information is that Mathematica uses the percent sign % to refer to the last computed output and %% to refer to the next to last computed output. This can be helpful, as we will see below. We will use the % below when we want to change the roots of Poly1 to a set of rules that can then be substituted back into Poly1 to see that we get 0 (or very close to 0) back. As well, it is probably better to assign a name to your quantities in order to be better able to use them later and know what you are specifically talking about, and we do this for the roots of Poly2:
A sequence or table in Mathematica is a list of objects created from a formula such as {1,4,9} can be created as the output from the input Table [k2, {k,i,3}].
In order to define a matrix M and have it displayed in the proper matrix format as rows and columns, use round parentheses around your definition of M followed by // MatrixForm. Then if you wish to manipulate M with other matrices so defined, there will be no problems, but remember to always use // MatrixForm after your computations or definitions to get the proper matrix format:
As the last topic of this section, let’s do an example of a piecewise function and its graph (see Fig. 1.1). A piecewise function is one whose rule is given in parts or pieces where each part is used only when certain conditions are satisfied. Happily, Mathematica has a Piecewise command that we can utilize. Note that in defining the function f(x) below that && is the Mathematica notation for the logical AND in joining two statements:
Figure 1.1: Plot of the piecewise function f.
Let’s begin with simple function or expression plotting, and then move on to parametric curve plotting. In the first example, remember to get base e for the exponential function from the palette Basic Math Assistant. Also, in order to get a superscript or exponent, use together after the base is already in place. In order to create a fraction, first type the numerator and then hit to be able to place the denominator.
The plot option of Plot Style can control color and thickness for graphics and control whether the graph lines are solid or dashed except when doing implicit plotting of equations using ContourPlot when PlotStyle switches to ContourStyle (see Figs. 1.2–1.7).
Figure 1.2: Output of the Plot command with various options.
Figure 1.3: Plot of f and g together with separate options for each curve.
Figure 1.4: Plot of the parametric equation (sin(2t), sin(3t)).
Figure 1.5: Two parametric curves plotted together.
Figure 1.6: Example of the ContourPlot command with two implicitly defined relations.
Figure 1.7: Second example of the ContourPlot command with two implicitly defined relations.
We next do an animation (see Fig. 1.10) involving implicit plotting of an ellipse where the center is moving along the circle with center at the origin and radius 10. Here we make use of the Epilog option to put into each frame of our movie the circle of the ellipses’ centers:
Figure 1.11: Plot of two surfaces.
Figure 1.12: Plot of a spacecurve.
Figure 1.13: Plot of a helical spacecurve.
Figure 1.14: Plot of the torus, a parametric surface.
Figure 1.15: Three intersecting tori.
Next, we do implicit plotting of equations in the three variables x, y, and z, whose resulting plot gives a surface. We will start with a cylindrical surface, which is a surface whose equation has only two of the three space variables in it. This equation is really a curve in the plane, with certain radially symmetric properties, of its two variables, while adding the third variable (direction) results in a surface (see Figs. 1.16–1.18).
Figure 1.16: A cylinder defined implicitly.
Figure 1.17: A cylinder intersecting a sphere.
A word of warning in doing 3D animations. This type of animation can use a great deal of memory, so we highly recommend that you delete the output from memory before closing the file unless it took a great deal of time to produce the animation and you do not want to have to do it again. We animated the torus with three animation parameters. Play around with each slider, corresponding to the three parameters, to see how they affect the shape of the torus.
Mathematica can solve single equations as well as simultaneous systems of equations, both linear and nonlinear. It can also find approximate or exact solutions, although for exact solutions the equation or system must be capable of being solved for exact solutions by some known method. Also, Mathematica can find both real and complex solutions. The solution given by the command Solve will give a list of replacements for the variables solved for in your solution. In order to get the actual values of the solutions as a list and only for a specific variable solved for like z, you must use the input z /. soln, where soln is the result of Solve and z is one of the variables solved for in Solve. The command Solve seeks exact solutions while NSolve always gives approximate solutions.
We begin by solving some single polynomial equations for real and complex solutions, both approximate and exact. Solve will give all real and complex solutions to a single polynomial equation, that is, it will find all of the real and complex roots of any complex coefficient polynomial:
Now we look at some examples of solving systems of equations that are both linear and nonlinear. We begin by finding the intersection point of two lines in the ху-рlаnе (Fig. 1.19) followed by finding the intersection points of two circles (Fig. 1.20):
Figure 1.19: Solution to the system of two lines is a point.
Figure 1.20: Intersection of two circles is a pair of points.
In this final section of Chapter 1, we will discuss some basic mathematical programming concepts such as the For loop command, the use of commands such as While and Do, and the general concept of a procedure in Mathematica that consists a series of commands with semicolons following each step of the procedure. A procedure’s steps will be executed in order from left to right if they appear all on the same line or from first to last if they are on successive lines in the same cell. In general, by design, the output of a procedure is the result of its final step.
The second For loop will compute and display the sums of the reciprocals of the factorial function. The results get closer and closer to the number e which is approximately 2.71828.
The next two procedures will do an addition of the first 10 positive integers and then a multiplication of the same integers using the Do loop command:
Sometimes the most convenient way to create a somewhat complicated function is to use a procedure for its rule. We will first look at two simple examples that create the factorial function and the add function using the procedures of the previous section to do it. Remember to place parentheses around all of the steps in your procedure. The output of the function will be the result of the last step of your procedure, which is the function’s rule. The variable n in both the factorial and add functions below takes on only a positive integer value:
Now we turn to a more sophisticated example involving piecewise functions and the use of the nested If command. Mathematica has a Piecewise command to build piecewise functions, but it is not always sufficient or convenient for all purposes. Let’s create a function called quadrant that takes a point in the plane and tells us which quadrant it is in or if it is on an axis and thus is not in any quadrant. Note that && is the Mathematica logical AND for joining two conditions so that both must be true for them together to be true. The logical OR is || with no space between the two vertical bars. The Return command used below will return an output as well as terminate the If, While, For or Do loop that you might be in. There is also a command Break which terminates loops.
Be very careful in Mathematica to avoid using the letters С, D and N as variables in your functions or anywhere else as they are Mathematica command names. It is better to stick to using lowercase letters as your variable names and output for any function or procedure:
Lesen Sie weiter in der vollständigen Ausgabe!
Lesen Sie weiter in der vollständigen Ausgabe!
Lesen Sie weiter in der vollständigen Ausgabe!
Lesen Sie weiter in der vollständigen Ausgabe!
Lesen Sie weiter in der vollständigen Ausgabe!
Lesen Sie weiter in der vollständigen Ausgabe!
Lesen Sie weiter in der vollständigen Ausgabe!
Lesen Sie weiter in der vollständigen Ausgabe!
Lesen Sie weiter in der vollständigen Ausgabe!
Lesen Sie weiter in der vollständigen Ausgabe!
Lesen Sie weiter in der vollständigen Ausgabe!
Lesen Sie weiter in der vollständigen Ausgabe!
Lesen Sie weiter in der vollständigen Ausgabe!