(*********************************************************************** 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[ 12948, 374]*) (*NotebookOutlinePosition[ 13829, 404]*) (* CellTagsIndexPosition[ 13785, 400]*) (*WindowFrame->Normal*) Notebook[{ Cell[CellGroupData[{ Cell[TextData[{ "Step by Step Row-Reduction in ", StyleBox["Mathematica", FontSlant->"Italic"], " " }], "Title", Evaluatable->False, TextAlignment->Center, AspectRatioFixed->True, Background->RGBColor[0, 1, 0]], Cell["\<\ This notebook is by Steven Amgott. Please send any questions or \ comments to samgott1@swarthmore.edu. Feel free to use and distribute this \ notebook, but keep this author information in any copy you use or distribute.\ \ \>", "SmallText"], Cell[CellGroupData[{ Cell["Initialization", "Section"], Cell[TextData[{ "The cells in this section are initialization cells. They will be \ automatically entered into ", StyleBox["Mathematica", FontSlant->"Italic"], ", provided you answer \"Yes\" to the initialization prompt the first time \ you evaluate any input cell. If you do not answer \"Yes\" to this prompt, \ you will have to either evaluate the cells manually, or use the ", StyleBox["Kernel...Evaluation...Evaluate Initialization", FontColor->RGBColor[0, 0, 1]], " menu item." }], "Text"], Cell["\<\ The next cell defines a function which takes a row of the matrix a \ and multiplies it by a scalar. There are two inputs. The first is the \ matrix on which you wish to do a row operation. The second is a vector whose \ first coordinate is the row on which you are working, and whose second \ coordinate is the scalar by which you wish to multiply the row.\ \>", "Text"], Cell[BoxData[{ \(Clear[rowMultiply]\), "\[IndentingNewLine]", \(rowMultiply[a_, v_] := Module[{b}, b = a; b[\([v[\([1]\)]]\)] = v[\([2]\)]\ b[\([v[\([1]\)]]\)]; Print[MatrixForm[b]]; b;]\)}], "Input", InitializationCell->True], Cell["\<\ The next cell defines a function which switches two rows of matrix \ a. There are two inputs. The first is the matrix on which you wish to do a \ row operation. The second is a vector whose first coordinate is the row on \ which you are working, and whose second coordinate is the scalar by which you \ wish to multiply the row.\ \>", "Text"], Cell[BoxData[{ \(Clear[rowSwitch]\), "\[IndentingNewLine]", \(rowSwitch[a_, v_] := Module[{b, c}, b = a; c = a[\([v[\([1]\)]]\)]; b[\([v[\([1]\)]]\)] = b[\([v[\([2]\)]]\)]; b[\([v[\([2]\)]]\)] = c; Print[MatrixForm[b]]; b;]\)}], "Input", InitializationCell->True], Cell["\<\ The next cell defines a function which switches replaces a row by \ the row plus a multiple of a different row. There are two inputs. The first \ is the matrix on which you wish to do a row operation. The second is a \ vector whose first coordinate is the row which you are replacing, whose \ second coordinate is the row you are multiplying and adding, and whose third \ coordinate is the scalar by which you wish to multiply the row being added.\ \ \>", "Text"], Cell[BoxData[{ \(Clear[rowAdd]\), "\[IndentingNewLine]", \(rowAdd[a_, v_] := Module[{b}, b = a; b[\([v[\([1]\)]]\)] = b[\([v[\([1]\)]]\)] + v[\([3]\)]\ b[\([v[\([2]\)]]\)]; Print[MatrixForm[b]]; b;]\)}], "Input", InitializationCell->True], Cell["\<\ In all cases, we use MatrixForm to produce two-dimensional output, \ rather than the \"lists of lists\" form that otherwise appears.\ \>", "Text"] }, Closed]], Cell[CellGroupData[{ Cell["Creating a random matrix", "Section"], Cell[TextData[{ "The function ", StyleBox["randomMatrix", FontColor->RGBColor[1, 0, 0]], " produces a random m by n matrix whose entries are integers. It is \ created by the cell below, which is marked as an initialization cell. (This \ means ", StyleBox["Mathematica", FontSlant->"Italic"], " will ask if you want it evaluated the very first time you evaluate any \ cell. You should answer \"yes.\") This cell only needs to be evaluated once \ during your current ", StyleBox["Mathematica", FontSlant->"Italic"], " session. You will need to specify the shape of the matrix (i.e. m and \ n), and a range of numbers from which to choose. (If you want real entries \ instead of integer entries, you can replace the word ", StyleBox["Integer", FontColor->RGBColor[1, 0, 0]], " below by the word ", StyleBox["Real", FontColor->RGBColor[1, 0, 0]], ".) Bounds is a list of two numbers giving the smallest and the largest \ numbers you want in the matrix. Remember, lists must be enclosed by { }. " }], "Text", Evaluatable->False, AspectRatioFixed->True], Cell[BoxData[{\(Clear[randomMatrix, m, n, bounds]\), "\n", RowBox[{\(randomMatrix[m_, n_, bounds_]\), ":=", RowBox[{"Table", "[", RowBox[{ RowBox[{"Random", "[", RowBox[{ StyleBox["Integer", FontColor->RGBColor[1, 0, 0]], ",", "bounds"}], "]"}], ",", \({m}\), ",", \({n}\)}], "]"}]}]}], "Input", InitializationCell->True] }, Closed]], Cell[CellGroupData[{ Cell["Elementary row operations", "Section"], Cell[TextData[{ "To illustrate the elementary row operations, we will create a random \ matrix, which we will name ", StyleBox["restore", FontColor->RGBColor[1, 0, 0]], ". This will allow us to begin again with the same matrix if we either \ make a mistake, or decide to do it over with a different order of steps. The \ cell below creates a random 4 by 6 matrix whose entries are integers between \ -5 and 5." }], "Text"], Cell[BoxData[{\(Clear[restore]\), "\n", RowBox[{ RowBox[{"restore", "=", RowBox[{"randomMatrix", "[", RowBox[{ StyleBox["4", FontColor->RGBColor[1, 0, 1]], ",", StyleBox["6", FontColor->RGBColor[1, 0, 1]], ",", RowBox[{"{", RowBox[{ StyleBox[\(-5\), FontColor->RGBColor[1, 0, 1]], ",", StyleBox["5", FontColor->RGBColor[1, 0, 1]]}], "}"}]}], "]"}]}], ";", "\n", \(MatrixForm[restore]\)}]}], "Input", AspectRatioFixed->True], Cell[TextData[{ "Here is how we can make ", StyleBox["Mathematica", FontSlant->"Italic"], " perform the basic row-reduction operations. We defined functions to do \ these operations in the Initialization section above. (You might want to \ open that section and look at the functions.) The first takes a row of the \ matrix and multiplies it by a constant. For instance, to multiply row 3 of \ the matrix ", StyleBox["restore", FontColor->RGBColor[1, 0, 0]], " by 2, we input" }], "Text"], Cell[BoxData[ \(rowMultiply[restore, {3, 2}]\)], "Input"], Cell[TextData[{ "Suppose we now want to switch the second and third rows of the result. \ The syntax in the cell below does this. (", StyleBox["Mathematica", FontSlant->"Italic"], " uses ", StyleBox["%", FontColor->RGBColor[1, 0, 0]], " to refer to the last output.)" }], "Text"], Cell[BoxData[ \(rowSwitch[%, {2, 3}]\)], "Input"], Cell["\<\ The last of the elementary row operations is replacing a row by \ that row plus a multiple of another row. The syntax below replaces the first \ row of the previous output by the first row plus 4 times the third row.\ \>", \ "Text"], Cell[BoxData[ \(rowAdd[%, {1, 3, 4}]\)], "Input"], Cell[TextData[{ "If we need to start our row reduction over, we simply use the matrix ", StyleBox["restore", FontColor->RGBColor[1, 0, 0]], " again. For instance, if we change our mind and want the first step to be \ subtracting 4 times the first row from the third row and making that the new \ third row, we can use" }], "Text"], Cell[BoxData[ \(rowAdd[restore, {3, 1, \(-4\)}]\)], "Input"], Cell["Compare that output to the original restore matrix.", "Text"], Cell[BoxData[ \(MatrixForm[restore]\)], "Input"], Cell[TextData[{ "Finally, you can also use previous output as the input (for instance, if \ you only want to go back a few steps). If we wanted to switch the first and \ third rows of output numbered 12, we could input ", StyleBox["rowSwitch[Out[12],{1,3}]", FontColor->RGBColor[1, 0, 0]], ". (This is not set up as an input cell in this notebook since I don't \ know that your ", StyleBox["Out[12]", FontColor->RGBColor[1, 0, 0]], " is even a matrix. You can pick one of your output matrices with which to \ try this.)" }], "Text"] }, Closed]], Cell[CellGroupData[{ Cell["Exercises: Echelon forms", "Section"], Cell[CellGroupData[{ Cell["Row-echelon form", "Subsection"], Cell[TextData[{ "Begin by creating a random 3 by 4 matrix. Make sure to name it ", StyleBox["restore ", FontColor->RGBColor[1, 0, 0]], "as we did above. Row-reduce ", StyleBox["restore", FontColor->RGBColor[1, 0, 0]], " to row-echelon form twice, once starting by interchanging the first and \ second rows (but doing no other row interchanges unless it becomes absolutely \ necessary), the second time without interchanging the rows (unless it becomes \ necessary to do so). Remember, row-echelon form requires three things:\n1)\t\ Any row of all zeros is at the bottom of the matrix.\n2)\tAny column which \ contains a leading non-zero entry of a row must have all zeros below that \ entry.\n3)\tEvery leading non-zero entry of a row is to the right of the \ leading non-zero entry of the row above it.\n\tShow your work in cells \ between this one and the ", StyleBox["Answer:", FontColor->RGBColor[0, 0, 1]], " cell below. Do you get the same row-echelon form each time? Should this \ always happen?" }], "Text"], Cell[TextData[StyleBox["Answer:", FontColor->RGBColor[0, 0, 1]]], "Text", CellFrame->True, Background->GrayLevel[0.849989]] }, Closed]], Cell[CellGroupData[{ Cell["Reduced row-echelon form", "Subsection"], Cell[TextData[{ "Once again, begin by creating a random 3 by 4 matrix. Make sure to name \ it ", StyleBox["restore ", FontColor->RGBColor[1, 0, 0]], "as we did above. This time row-reduce ", StyleBox["restore", FontColor->RGBColor[1, 0, 0]], " to reduced row-echelon form twice, once starting by interchanging the \ first and second rows (but doing no other row interchanges unless it becomes \ absolutely necessary), the second time without interchanging the rows (unless \ it becomes necessary to do so). Remember, reduced row-echelon form requires \ the matrix be in row-echelon form, with two additional requirements:\n1)\tThe \ leading non-zero entry in any row is 1.\n2)\tEach column containing a leading \ 1 has all other entries zero.\n\tShow your work in cells between this one and \ the ", StyleBox["Answer:", FontColor->RGBColor[0, 0, 1]], " cell below. Do you get the same reduced row-echelon form each time? \ Should this always happen?" }], "Text"], Cell[TextData[StyleBox["Answer:", FontColor->RGBColor[0, 0, 1]]], "Text", CellFrame->True, Background->GrayLevel[0.849989]], Cell[TextData[{ StyleBox["Mathematica", FontSlant->"Italic"], " has a built-in command to row-reduce the matrix. Compare the output of \ the next cell to your answers above." }], "Text"], Cell[BoxData[{ \(RowReduce[restore]\), \(MatrixForm[%]\)}], "Input"] }, Closed]] }, Closed]] }, Open ]] }, FrontEndVersion->"4.0 for Microsoft Windows", ScreenRectangle->{{0, 1024}, {0, 720}}, AutoGeneratedPackage->None, WindowToolbars->"EditBar", WindowSize->{507, 466}, WindowMargins->{{22, Automatic}, {Automatic, 13}}, PrivateNotebookOptions->{"ColorPalette"->{RGBColor, -1}}, ShowCellLabel->True, ShowCellTags->False, RenderingOptions->{"ObjectDithering"->True, "RasterDithering"->False} ] (*********************************************************************** 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[CellGroupData[{ Cell[1739, 51, 228, 9, 166, "Title", Evaluatable->False], Cell[1970, 62, 252, 5, 60, "SmallText"], Cell[CellGroupData[{ Cell[2247, 71, 33, 0, 53, "Section"], Cell[2283, 73, 514, 11, 109, "Text"], Cell[2800, 86, 383, 6, 90, "Text"], Cell[3186, 94, 262, 6, 90, "Input", InitializationCell->True], Cell[3451, 102, 355, 6, 90, "Text"], Cell[3809, 110, 299, 6, 110, "Input", InitializationCell->True], Cell[4111, 118, 476, 8, 109, "Text"], Cell[4590, 128, 285, 7, 110, "Input", InitializationCell->True], Cell[4878, 137, 156, 3, 52, "Text"] }, Closed]], Cell[CellGroupData[{ Cell[5071, 145, 43, 0, 33, "Section"], Cell[5117, 147, 1102, 26, 185, "Text", Evaluatable->False], Cell[6222, 175, 408, 9, 70, "Input", InitializationCell->True] }, Closed]], Cell[CellGroupData[{ Cell[6667, 189, 44, 0, 33, "Section"], Cell[6714, 191, 435, 9, 78, "Text"], Cell[7152, 202, 613, 16, 59, "Input"], Cell[7768, 220, 510, 12, 80, "Text"], Cell[8281, 234, 61, 1, 27, "Input"], Cell[8345, 237, 299, 9, 48, "Text"], Cell[8647, 248, 53, 1, 27, "Input"], Cell[8703, 251, 243, 5, 62, "Text"], Cell[8949, 258, 53, 1, 27, "Input"], Cell[9005, 261, 341, 7, 62, "Text"], Cell[9349, 270, 64, 1, 27, "Input"], Cell[9416, 273, 67, 0, 30, "Text"], Cell[9486, 275, 52, 1, 27, "Input"], Cell[9541, 278, 553, 12, 94, "Text"] }, Closed]], Cell[CellGroupData[{ Cell[10131, 295, 44, 0, 33, "Section"], Cell[CellGroupData[{ Cell[10200, 299, 38, 0, 46, "Subsection"], Cell[10241, 301, 1046, 20, 206, "Text"], Cell[11290, 323, 129, 3, 46, "Text"] }, Closed]], Cell[CellGroupData[{ Cell[11456, 331, 46, 0, 30, "Subsection"], Cell[11505, 333, 993, 20, 204, "Text"], Cell[12501, 355, 129, 3, 49, "Text"], Cell[12633, 360, 195, 5, 52, "Text"], Cell[12831, 367, 77, 2, 50, "Input"] }, Closed]] }, Closed]] }, Open ]] } ] *) (*********************************************************************** End of Mathematica Notebook file. ***********************************************************************)