(*********************************************************************** Mathematica-Compatible Notebook This notebook can be used on any computer system with Mathematica 4.0, MathReader 4.0, or any compatible application. The data for the notebook starts with the line containing stars above. To get the notebook into a Mathematica-compatible application, do one of the following: * Save the data starting with the line of stars above into a file with a name ending in .nb, then open the file inside the application; * Copy the data starting with the line of stars above to the clipboard, then use the Paste menu command inside the application. Data for notebooks contains only printable 7-bit ASCII and can be sent directly in email or through ftp in text mode. Newlines can be CR, LF or CRLF (Unix, Macintosh or MS-DOS style). NOTE: If you modify the data for this notebook not in a Mathematica- compatible application, you must delete the line below containing the word CacheID, otherwise Mathematica-compatible applications may try to use invalid cache data. For more information on notebooks and Mathematica-compatible applications, contact Wolfram Research: web: http://www.wolfram.com email: info@wolfram.com phone: +1-217-398-0700 (U.S.) Notebook reader applications are available free of charge from Wolfram Research. ***********************************************************************) (*CacheID: 232*) (*NotebookFileLineBreakTest NotebookFileLineBreakTest*) (*NotebookOptionsPosition[ 16828, 497]*) (*NotebookOutlinePosition[ 17538, 522]*) (* CellTagsIndexPosition[ 17494, 518]*) (*WindowFrame->Normal*) Notebook[{ Cell["Solving Equations One Step at a Time", "Title"], Cell["\<\ How Greek mythology and modern mathematics come to the rescue and allow us to \ do really neat things.\ \>", "Subtitle"], Cell[CellGroupData[{ Cell[TextData[{ "Using the ", StyleBox["Mathematica", FontSlant->"Italic"], " Solve Routine. Nice but we would rather do it ourselves, thank you." }], "Section"], Cell[TextData[{ StyleBox["Mathematica", FontSlant->"Italic"], " has powerful routines for solving equations. For regular equations we can \ use Solve. Here is an equation." }], "Text"], Cell[BoxData[ \(eqn = 3 x + 4 y/b \[Equal] 6 \((x - y)\)\)], "Input"], Cell[TextData[{ "Solve will automatically solve for one of the variables. Suppose we wish \ to solve for ", Cell[BoxData[ \(y\)]], "..." }], "Text"], Cell[BoxData[ \(Solve[eqn, y]\)], "Input"], Cell["\<\ Everything has been done automatically. But suppose we wish to solve the \ equation ourselves. Suppose we want to manipulate the equation step by step \ to see how it is done. There are many cases where we may wish to manipulate \ an equation, rather than formally solve it. How do we do that?\ \>", "Text"], Cell[TextData[{ "Well, in order to do that using ", StyleBox["Mathematica", FontSlant->"Italic"], ", and not somehow having it done for us automatically, we have to learn \ about two new kinds of operations in ", StyleBox["Mathematica", FontSlant->"Italic"], ". These operations may at first seem strange. But each really does a very \ simple thing. Furthermore they are each powerful operations and so well worth \ learning. Furthermore they are really 20th century mathematics. Most high \ school students are plodding along with 17th century mathematics. So join the \ in crowd!" }], "Text"] }, Closed]], Cell[CellGroupData[{ Cell["Pure Functions - The first really really in operation", "Section"], Cell[TextData[{ "A regular function like ", Cell[BoxData[ \(Sin[x]\)]], " has a name, Sin, and an argument, x. We put in an x and ", StyleBox["Mathematica", FontSlant->"Italic"], " grinds away and gives us an answer. In fact, calculating ", Cell[BoxData[ \(Sin[x]\)]], " is fairly complicated and most of us wouldn't want to know the details. " }], "Text"], Cell[TextData[{ "A pure function is all action. It has no name. Its argument is only \ indicated in the most symbolic of ways. Pure functions were invented when \ mathematicians realized that in many cases what is actually done is the \ important thing. In ", StyleBox["Mathematica", FontSlant->"Italic"], " pure functions are useful when we just want to do something and not go to \ all the bother of setting up a definition for the action. So suppose we want \ to add 1 to something. We can do it this way with a pure function..." }], "Text"], Cell[BoxData[ RowBox[{ StyleBox[\(# + 1 &\), FontColor->RGBColor[0, 0, 1]], "[", "x", "]"}]], "Input"], Cell["\<\ The # sign stands for whatever is going to be acted upon. When we follow the \ pure function with [x], then it is x that is acted upon. All pure functions \ have to end with an &. Suppose we want to multiply something by 3...\ \>", "Text"], Cell[BoxData[ RowBox[{ StyleBox[\(3 # &\), FontColor->RGBColor[0, 0, 1]], "[", "x", "]"}]], "Input"], Cell["Suppose we want to square something and add 3...", "Text"], Cell[BoxData[ RowBox[{ StyleBox[\(#\^2 + 3 &\), FontColor->RGBColor[0, 0, 1]], "[", "x", "]"}]], "Input"], Cell["\<\ Don't forget the &! (I am always forgetting the &.) This is what happens when \ you forget it...\ \>", "Text"], Cell[BoxData[ RowBox[{ StyleBox[\(#\^2\), FontColor->RGBColor[0, 0, 1]], StyleBox["+", FontColor->RGBColor[0, 0, 1]], RowBox[{ StyleBox["3", FontColor->RGBColor[0, 0, 1]], "[", "x", "]"}]}]], "Input"], Cell[TextData[{ "You get a completely useless result. ", StyleBox["Mathematica", FontSlant->"Italic"], " absolutely needs the & to know that it is a pure function." }], "Text"], Cell["\<\ Notice that a pure function is very much like a name of a function. It stands \ in the same place that you would usually have a name. You can think of pure \ functions as throw-away functions. Use them once and throw them away.\ \>", "Text"], Cell["\<\ So now you have mastered one of the significant pieces of 20th century \ mathematics. Let's go on to the next piece.\ \>", "Text"] }, Closed]], Cell[CellGroupData[{ Cell["Map - The second really really in operation", "Section"], Cell["\<\ The second operation we have to learn about is Map. Suppose we want to do \ something to a whole bunch of stuff. We could do it to each thing \ individually, but if we are going to always be doing the same thing, why not \ do it all at once. Suppose you have collected a number of items in mystuff \ and you want to take the Sin of each of the items. We can do it my \ \"mapping\" Sin onto the items.\ \>", "Text"], Cell[BoxData[ RowBox[{ StyleBox["Map", FontColor->RGBColor[1, 0, 0]], "[", \(Sin, mystuff[x, y, 0, \[Pi]/2, 90 \[Degree]]\), "]"}]], "Input"], Cell[TextData[{ "Notice that Sin was applied to each item in mystuff. This is such a useful \ operation, and such an efficient way of doing things, that ", StyleBox["Mathematica", FontSlant->"Italic"], " has a special notation that can also be used. We can do the same thing as \ above this way." }], "Text"], Cell[BoxData[ RowBox[{"Sin", StyleBox["/@", FontColor->RGBColor[1, 0, 0]], \(mystuff[x, y, 0, \[Pi]/2, 90 \[Degree]]\)}]], "Input"], Cell[TextData[{ "The symbols ", Cell[BoxData[ \( /@ \)]], " stands for Map. It tells ", StyleBox["Mathematica", FontSlant->"Italic"], " to Map the function which precedes ", Cell[BoxData[ \( /@ \)]], " onto the items in the thing that follows ", Cell[BoxData[ \( /@ \)]], "." }], "Text"], Cell["\<\ Did I say that Map was efficient? It is really efficient! Map will do things \ many times faster than more mundane ways of doing things. So, if you can \ think in terms of using Map, when you get to some real number crunching \ problems you will be way ahead of the game. \ \>", "Text"], Cell["\<\ Now you know another great piece of 20th century mathematics. And since we \ also know about pure functions let's put them together. Suppose we want to \ square a number of items...\ \>", "Text"], Cell[BoxData[ RowBox[{ StyleBox[\(#\^2 &\), FontColor->RGBColor[0, 0, 1]], StyleBox["/@", FontColor->RGBColor[1, 0, 0]], \(mystuff[x, y, 1, 2, 3, 4]\)}]], "Input"], Cell["\<\ So now we have all the tools we need, pure functions and Map, for solving \ equations step by step.\ \>", "Text"] }, Closed]], Cell[CellGroupData[{ Cell["At last - Solving an Equation", "Section"], Cell["Here is an equation...", "Text"], Cell[BoxData[ \(y + x \[Equal] 3\)], "Input"], Cell[TextData[{ "What do we do when we solve an equation? The usual procedure is to perform \ the same operation on each side of the equation. We add the same thing to \ each side, subtract the same thing from each side, multiply both sides by the \ same thing or divide both sides by the same thing. Each operation transforms \ the equation and we continue until we get what we want. In ", StyleBox["Mathematica", FontSlant->"Italic"], " it is often useful to look at the FullForm of an expression. So let's \ look at the full form of our equation." }], "Text"], Cell[BoxData[ \(y + x \[Equal] 3 // FullForm\)], "Input"], Cell["\<\ Comparing to the example in Map, we see that Equal is like mystuff. The two \ sides of the equation are like the items that were in mystuff. If we want to \ do the same action on both sides of the equation, then we can Map that action \ onto the equation. Lastly, the action we want to do can be specified with a \ pure function. So if we want to solve for y, then we want to subtract x from \ each side of the equation...\ \>", "Text"], Cell[BoxData[ RowBox[{ StyleBox[\(# - x &\), FontColor->RGBColor[0, 0, 1]], StyleBox["/@", FontColor->RGBColor[1, 0, 0]], \((y + x \[Equal] 3)\)}]], "Input"], Cell["\<\ The parenthesis around the equation were necessary because otherwise the \ function is mapped onto y which doesn't even have any parts. Here is another \ way to do it. It shows the equation at each step of solving. Here there is \ only the initial equation and one step. Remember that % always stands for the \ output of the last expression that was evaluated.\ \>", "Text"], Cell[BoxData[{\(y + x \[Equal] 3\), "\[IndentingNewLine]", RowBox[{ StyleBox[\(# - x &\), FontColor->RGBColor[0, 0, 1]], StyleBox["/@", FontColor->RGBColor[1, 0, 0]], "%"}]}], "Input"] }, Closed]], Cell[CellGroupData[{ Cell["\<\ And now we are really going to unleash the power! Watch out below!\ \>", "Section"], Cell["\<\ This was the equation used as an example in the first section.\ \>", "Text"], Cell[BoxData[ \(eqn = 3 x + 4 y/b \[Equal] 6 \((x - y)\)\)], "Input"], Cell["\<\ Let's solve this equation for y. We want to get y by itself on the left hand \ side and everything else on the right hand side. So let's start by \ subtracting 3x from each side.\ \>", "Text"], Cell[BoxData[ RowBox[{ StyleBox[\(# - 3 x &\), FontColor->RGBColor[0, 0, 1]], StyleBox["/@", FontColor->RGBColor[1, 0, 0]], "eqn"}]], "Input"], Cell["\<\ Now it looks like we are going to have to expand out the left hand side.\ \>", "Text"], Cell[BoxData[ RowBox[{ StyleBox["Expand", FontColor->RGBColor[0, 0, 1]], StyleBox["/@", FontColor->RGBColor[1, 0, 0]], "%"}]], "Input"], Cell[TextData[{ "Wait! Why didn't we have to use an & here? Because Expand is not a pure \ function that we made up, but the name of an existing function in ", StyleBox["Mathematica", FontSlant->"Italic"], ". Remember that a pure function just takes the place of a name of a \ function. So wherever we might use a pure function we could also use the name \ of an existing defined function. Notice that ", StyleBox["Mathematica", FontSlant->"Italic"], " automatically simplified. Now we have to add 6y to each side." }], "Text"], Cell[BoxData[ RowBox[{ StyleBox[\(# + 6 y &\), FontColor->RGBColor[0, 0, 1]], StyleBox["/@", FontColor->RGBColor[1, 0, 0]], "%"}]], "Input"], Cell[TextData[{ "Now we need to collect the y terms. We can do that by taking the regular \ ", StyleBox["Mathematica", FontSlant->"Italic"], " Collect function and turning it into a pure function. (We don't actually \ have to collect y terms on the right hand side, but it does no harm.)" }], "Text"], Cell[BoxData[ RowBox[{ StyleBox[\(Collect[#, y] &\), FontColor->RGBColor[0, 0, 1]], StyleBox["/@", FontColor->RGBColor[1, 0, 0]], "%"}]], "Input"], Cell[TextData[{ "Now we need to divide by ", Cell[BoxData[ \(\((6 + 4/b)\)\)]], ". Don't forget to put the parenthesis around the whole divisor." }], "Text"], Cell[BoxData[ RowBox[{ StyleBox[\(#/\((6 + 4/b)\) &\), FontColor->RGBColor[0, 0, 1]], StyleBox["/@", FontColor->RGBColor[1, 0, 0]], "%"}]], "Input"], Cell["This is the answer, but perhaps you wish to \"simplify\" it.", "Text"], Cell[BoxData[ RowBox[{ StyleBox["Simplify", FontColor->RGBColor[0, 0, 1]], StyleBox["/@", FontColor->RGBColor[1, 0, 0]], "%"}]], "Input"], Cell["\<\ Instead of doing the work in multiple cells, it is nice to do all the work in \ one cell. You can reevaluate as you add each step. And the % always refers to \ just what you intend because everything is initialized when you reevaluate \ the cell. Here the color coding is dropped because by now you should know \ what the various parts of each expression do.\ \>", "Text"], Cell[BoxData[{ \(eqn\), "\[IndentingNewLine]", \(\(# - 3 x &\) /@ %\), "\[IndentingNewLine]", \(Expand /@ %\), "\[IndentingNewLine]", \(\(# + 6 y &\) /@ %\), "\[IndentingNewLine]", \(\(Collect[#, y] &\) /@ %\), "\[IndentingNewLine]", \(\(#/\((6 + 4/b)\) &\) /@ %\), "\[IndentingNewLine]", \(Simplify /@ %\)}], "Input"], Cell[TextData[{ "Doesn't it all look very arcane? But once you see that each step is just a \ pure function, or function name, mapped onto each side of the equation, \ transforming the equation, there is nothing mysterious at all. Now you can \ perform operations on equations, step by step, and solve things ", StyleBox["Mathematica", FontSlant->"Italic"], " might not be so good at, such as manipulating inequalities." }], "Text"], Cell[TextData[{ "Now cast your eye over the last set of outputs. What do you see? A whole \ bunch of equations? No, they are all the same equation! They are all equally \ valid. They are all true. They all contain exactly the same information. Try \ to think of them all as ", StyleBox["one", FontWeight->"Bold"], " object that can take many different forms." }], "Text"], Cell["\<\ Here is a story. In Greek mythology, Proteus was \"The Old Man of the Sea\". \ Proteus was very wise. If you had a question, Proteus could give you the \ answer. But Proteus was ornery. He didn't necessarily want to answer people's \ questions. So, when he was approached, he would try to escape. He could \ change his form. He would change into a goat thinking people would never ask \ a question of a goat. Then he would change into a lion thinking to scare \ people off. Then he would change into a snake thinking to slip away. Then he \ might change into a river, or a cloud, or the wind. But if the person held on \ tight, and never let Proteus escape, eventually Proteus would have to yield \ and give the answer.\ \>", "Text"], Cell[TextData[{ "So think of the equation as being Proteus. Proteus is actually doing us a \ favor by changing form. Because ", StyleBox["the form is the answer", FontWeight->"Bold"], ". If we can grab hold of Proteus, and make him change his form the way we \ want, then we will eventually get the form we desire. We change the form \ until we get the one that we think is \"nicest\". In our case we thought that \ the \"nicest\" form was one that had y on one side of the equation and \ everything else on the other side. But there may be reasons to pick some \ other form. This is a common theme in mathematics. Often we will have some \ object that can take many forms. We want to learn how to force it into a form \ which we think is \"nicest\", perhaps a form that is most useful, or a form \ that is most beautiful." }], "Text"], Cell["\<\ So now you have not only learned some old mythology but some very modern \ mathematics which can be applied to many kinds of problems. Leave that 17th \ century mathematics to the kiddies.\ \>", "Text"] }, Closed]] }, FrontEndVersion->"4.0 for Microsoft Windows", ScreenRectangle->{{0, 1024}, {0, 683}}, WindowSize->{785, 617}, WindowMargins->{{0, Automatic}, {Automatic, 0}}, Magnification->1.25, StyleDefinitions -> "Classroom.nb" ] (*********************************************************************** Cached data follows. If you edit this Notebook file directly, not using Mathematica, you must remove the line containing CacheID at the top of the file. The cache data will then be recreated when you save this file from within Mathematica. ***********************************************************************) (*CellTagsOutline CellTagsIndex->{} *) (*CellTagsIndex CellTagsIndex->{} *) (*NotebookFileOutline Notebook[{ Cell[1717, 49, 53, 0, 69, "Title"], Cell[1773, 51, 130, 3, 80, "Subtitle"], Cell[CellGroupData[{ Cell[1928, 58, 171, 5, 95, "Section"], Cell[2102, 65, 192, 5, 33, "Text"], Cell[2297, 72, 75, 1, 60, "Input"], Cell[2375, 75, 160, 6, 33, "Text"], Cell[2538, 83, 46, 1, 60, "Input"], Cell[2587, 86, 317, 5, 75, "Text"], Cell[2907, 93, 612, 13, 96, "Text"] }, Closed]], Cell[CellGroupData[{ Cell[3556, 111, 72, 0, 43, "Section"], Cell[3631, 113, 386, 11, 54, "Text"], Cell[4020, 126, 554, 10, 96, "Text"], Cell[4577, 138, 120, 3, 60, "Input"], Cell[4700, 143, 250, 4, 54, "Text"], Cell[4953, 149, 119, 3, 60, "Input"], Cell[5075, 154, 64, 0, 33, "Text"], Cell[5142, 156, 123, 3, 61, "Input"], Cell[5268, 161, 120, 3, 33, "Text"], Cell[5391, 166, 258, 8, 61, "Input"], Cell[5652, 176, 186, 5, 33, "Text"], Cell[5841, 183, 251, 4, 54, "Text"], Cell[6095, 189, 140, 3, 33, "Text"] }, Closed]], Cell[CellGroupData[{ Cell[6272, 197, 62, 0, 43, "Section"], Cell[6337, 199, 424, 7, 96, "Text"], Cell[6764, 208, 167, 4, 60, "Input"], Cell[6934, 214, 318, 7, 54, "Text"], Cell[7255, 223, 160, 4, 60, "Input"], Cell[7418, 229, 327, 14, 54, "Text"], Cell[7748, 245, 296, 5, 75, "Text"], Cell[8047, 252, 205, 4, 54, "Text"], Cell[8255, 258, 205, 6, 61, "Input"], Cell[8463, 266, 123, 3, 33, "Text"] }, Closed]], Cell[CellGroupData[{ Cell[8623, 274, 48, 0, 43, "Section"], Cell[8674, 276, 38, 0, 33, "Text"], Cell[8715, 278, 49, 1, 60, "Input"], Cell[8767, 281, 572, 10, 117, "Text"], Cell[9342, 293, 61, 1, 60, "Input"], Cell[9406, 296, 446, 7, 96, "Text"], Cell[9855, 305, 190, 5, 60, "Input"], Cell[10048, 312, 384, 6, 75, "Text"], Cell[10435, 320, 218, 5, 81, "Input"] }, Closed]], Cell[CellGroupData[{ Cell[10690, 330, 93, 2, 43, "Section"], Cell[10786, 334, 86, 2, 33, "Text"], Cell[10875, 338, 75, 1, 60, "Input"], Cell[10953, 341, 202, 4, 54, "Text"], Cell[11158, 347, 176, 5, 60, "Input"], Cell[11337, 354, 96, 2, 33, "Text"], Cell[11436, 358, 168, 5, 60, "Input"], Cell[11607, 365, 545, 11, 96, "Text"], Cell[12155, 378, 174, 5, 60, "Input"], Cell[12332, 385, 310, 7, 54, "Text"], Cell[12645, 394, 179, 5, 60, "Input"], Cell[12827, 401, 169, 5, 33, "Text"], Cell[12999, 408, 181, 5, 60, "Input"], Cell[13183, 415, 76, 0, 33, "Text"], Cell[13262, 417, 170, 5, 60, "Input"], Cell[13435, 424, 382, 6, 75, "Text"], Cell[13820, 432, 354, 7, 186, "Input"], Cell[14177, 441, 442, 8, 75, "Text"], Cell[14622, 451, 381, 8, 76, "Text"], Cell[15006, 461, 743, 11, 138, "Text"], Cell[15752, 474, 845, 14, 161, "Text"], Cell[16600, 490, 212, 4, 54, "Text"] }, Closed]] } ] *) (*********************************************************************** End of Mathematica Notebook file. ***********************************************************************)