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—dc22
2011006420

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.

Overview of the Text

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.

Website and Supplemental Material

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.

Suggested Course Outlines

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:

• Section 7.2: Differentiation

• Section 7.3: Multivariable calculus

• Section 10.1: Green’s theorem

• Section 10.3: Divergence theorem and double integrals

• Section 11.3: Gradients and Lagrange multipliers

• Section 12.4: Linear differential equations

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.

Final Remarks

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:

1. Were there topics that were difficult to grasp from the explanation and examples given? If so, what would you suggest that we add or change to help make comprehension easier?

2. How did you enjoy the mixture of homework and Mathematica problems? Did you gain anything from verifying your answers to the homework problems with Mathematica?

3. What were some of your favorite or least favorite sections, and why?

4. Do you feel there were important topics, integral to a first semester course in linear algebra, that were missing from this text?

5. Did embedding Mathematica commands and output within the actual explanation of topics help to illustrate the topics?

6. Overall, what worked the best for you in this text, and what really did not work?

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.

Acknowledgments

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:

Derek Martinez, Central New Mexico University

Dror Varolin, Stony Brook University

Gian Mario Besana, DePaul University

Chris Moretti, Southeastern Oklahoma State University

Andrew Ross, Eastern Michigan University

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

kenneth.shiskowski@emich.edu

kfrinkle@se.edu

Chapter 1

An Introduction to Mathematica

1.1 The Very Basics

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.

In order to define or name a quantity in Mathematica, you must first decide on an appropriate name that cannot be a previously used name or Mathematica command name, nor should it be a common variable name like x, y, and z, which you might use in equations or functions/expressions as a variable symbol. You can never use the same symbol or name in Mathematica for more than one thing. Once you decide on a name such as TrialName, then in an Input cell say TrialName = (or :=) where, after the equal sign, you must give the expression that is the definition of TrialName. In Mathematica, an equal sign = is used for definitions, while a double equal sign = = is used in equations. You can use != for not equals. The := is often used for defining functions since it suppresses output and evaluation of the named quantity.

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 k² 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.

1.2 Basic Arithmetic

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 Create Input 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.

Mathematica expresses its equations with a double equal sign = = while it uses a single equal sign to make a definition or assignment of a quantity to a name such as in the use of Poly1 and Poly2 below. Hence, 5x + 3y == 9 is an equation in Mathematica, while Eqn1 =5x + 3y == 9 assigns the name Eqn1 to this equation for the time you are using this notebook unless you decide to change it. In Mathematica, you do not need to insert a multiplication sign, as Mathematica usually places a space between objects, which indicates multiplication.

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:

1.3 Lists and Matrices

Now we look more closely at the different ways in which we can organize information into lists and matrices (a list of lists), and how these different structures work and can be manipulated. In Mathematica, there are no sets, since Mathematica requires that an ordering be placed on its data, and so it deals with lists that can be treated as sets if you ignore the order of the elements in the list. The list L of the elements a, b, and с in this order is given as L = {a, b, c} in Mathematica. Shortly, we will look at taking the union, intersection, complement, and concatenation (or joining) of lists as well as taking out parts of a list. The empty list is { }, and L[[k]] is the kth element of list L.

A string S is a grouping or ordered collection of characters or symbols with quotes around them such as S = “Mary had a little lamb”. The string assigned to the name S is the sentence between the two double quotes. Strings often show up as the title to Mathematica plots and similar structures.

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 [k², {k,i,3}].

Now we switch to matrices or two dimensional arrays of rows and columns of entries. Mathematica considers a matrix M to be a list of lists where each element of M is one of the rows of the matrix M, and the rows must all have the same length. As such, M = {{1,2,3}, {4,5,6}, {7,8,9}} has {1,2,3} as its first row, {4,5,6} as its second row, and finally {7,8,9} as its third row. We will look at examples of adding, multiplying, inverting, transposing, and finding determinants of matrices where multiplication of matrices is indicated by a period or dot (.) between their names as given in the fifth line of input below.

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:

1.4 Expressions versus Functions

This section will look at the differences in Mathematica between expressions and functions and how to manipulate and evaluate both. You should think of an expression as the rule for some function f; that is, if f(x) = 5x + 9, then 5x + 9 is an expression which is the rule of the function f. Mathematica treats a function very differently than it treats an expression—you should think of an expression as a string of symbols while a function is a string of symbols (its rule or expression) with a method of evaluating its expression at different values of the variable(s) in the expression.

Let’s now look at the difference in Mathematica between the expression g = 5x + 9 and the function f with rule f(x) = 5x + 9, and how each of them can be evaluated at x = 1. Note that normal function evaluation can be done so that f evaluated at x = 1 is f[1] while the expression g can be evaluated at x = 1 by the substitution command g /. x→1. If you want to compose the function f with the built-in function Sin[x], then f[Sin[x]] will do it—this composition can also be done using f@Sin[x] or Nest[f, Sin[x], 1], and its result is an expression, not a function. If you want f to be composed with itself k times, then use Nest[f, f[x], k].

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.

1.5 Plotting and Animations

We begin our investigation into plotting with the basic 2D plotting of the graphs of functions y = f(x) and expressions as well as plotting parametric curves x = f(t), y = g(t). We will plot single functions and parametric curves as well as several together and in combination in different colors. Besides these two types of curves, we will implicitly plot equations in the two variables x and y such as the unit circle with equation x² + y² = 1 or something more complicated. The implicit plotting of equations can be done using the ContourPlot command and Contour Style option to control color, thickness, etc. of the plot.

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.

Now we turn our attention to creating a movie or animation in the xy-plane whose frames consist of plots of the three different types. Let’s begin by plotting the function y = sin(x) from x = 0 to x = A where the animation parameter A goes from 0 to 4π (see Figs. 1.8 and 1.9). It is followed by running two у = sin(x) animations at once based on the same animation parameter A:

Figure 1.8: Animation of the plot of sin(x) for x ∈ [0, A], here A = 2.6π.

Figure 1.9: Animation of sin(x) and sin(x + A), x ∈ [0, A]. Here A = 2.6π.

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.10: Animation of the rotation of the ellipse, here B = π.

It is time to move function, parametric, and implicit plotting from the xy-plane to xyz-space. We begin by plotting functions z = f(x, у), which give surfaces in xyz-space (see Fig. 1.11). This is followed by parametric curve and surface plotting:

Figure 1.11: Plot of two surfaces.

Now we examine parametric curve plotting in space. A parametric curve, or spacecurve (see Figs. 1.12 and 1.13), is of the form x = f(t), y = g(t), z = h(t) with one independent variable t. For spacecurves, we use the ParametricPlot3D command which is nearly identical to the ParamatricPlot command that was previously introduced.

Figure 1.12: Plot of a spacecurve.

Figure 1.13: Plot of a helical spacecurve.

A parametric surface is given by x = f(u,v), y = g(u,v), z = h(u,v) with two independent variables и and v. We first plot a torus (Fig. 1.14) followed by three interlocking mutually perpendicular tori (Fig. 1.15).

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.

Figure 1.18: Animation of parameters in the graph of a torus. The parameter values for this frame are A = 1.5, B = 2, and С = 6.5.

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.

1.6 Solving Systems of Equations

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.

1.7 Basic Programming

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.

Let’s begin by doing a few examples involving For loops such as printing values, doing sums and products, and using the commands Do and If. The first For loop will print zk + z starting with z = x² as k goes from 1 to 4, where at each step it takes the previous value of z and plugs it into zk + z for the next value of k. The semicolons in the For loop separate the main parts of the procedure inside the For command, which are first the initialization of the loop variable k, the instructions to be carried out successively as к increases in implementing the loop, and finally the output that you desire at each step (value of k) of the loop.

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:

Chapter 2

Linear Systems of Equations and Matrices

2.1 Linear Systems of Equations

The basic idea behind a general linear system of equations is that of a system of two xy-plane line equations ax + by = c and dx + ey = f, for real constants a through f. Such a system of two-line equations in the xy-plane has a simultaneous solution, the intersection set of the two lines. In general, we consider a simultaneous solution to be the collection of points that simultaneously satisfies all equations in a given system of equations. In the two-line equation system example we have only three possibilities. If the two lines are not parallel, then their intersection set is a single point P; hence the simultaneous solution will simply be {P}. If the two lines are parallel and distinct, then their intersection set is empty and there is no simultaneous solution. Last, if the two lines are the same, the simultaneous solution is simply the entire line, which consists of an infinite number of points. We now give an example of each of these three situations. As you will see, the solution points of each of these three systems are where each pair of lines intersect. In these systems, in order to solve by hand for the solution points, we must try to solve for one of the variables or by itself without the other variable. In essence, we are assuming each pair of lines intersect at a single point unless we discover otherwise.

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!