(************** Content-type: application/mathematica ************** Mathematica-Compatible Notebook This notebook can be used with any Mathematica-compatible application, such as Mathematica, MathReader or Publicon. 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[ 12433, 376]*) (*NotebookOutlinePosition[ 13481, 409]*) (* CellTagsIndexPosition[ 13437, 405]*) (*WindowFrame->Normal*) Notebook[{ Cell[TextData[{ "\n(* comments are made this way *)\n\n(* This is a ", StyleBox["Mathematica", FontSlant->"Italic"], " \"Notebook.\" The idea behind it is \n to write down a matrix and have \ ", StyleBox["Mathematica", FontSlant->"Italic"], " do various \n things to it, so you can do those things to your own \n \ matrices. Since ", StyleBox["Mathematica", FontSlant->"Italic"], " does not seem to have some\n of the things we use, namely ERO matrices \ (that tell\n ", StyleBox["Mathematica", FontSlant->"Italic"], " what ERO to perform), part of the project \n turned into solving the \ problem of how to construct \n ERO matrices in a useful way. *)\n\n(* Here \ is a matrix, [they are always given by rows] *)" }], "Input", ImageRegion->{{-0, 1}, {0, 1}}], Cell[TextData[{ "A={{1,-1,1,-1},{-1,1,-1,-1},{-1,-1,1,0},{1,1,1,-1}}\n\n(* You can put the \ cursor where you want and enter new \n elements in the matrix. Just be sure \ you make all \n the rows the same length. Suggestion: Select Save As...\n \ and save this Notebook under a new name, then tinker\n with it! *)\n\n\ MatrixForm[A] (* Throughout this session, ", StyleBox["Mathematica", FontSlant->"Italic"], "\n\n\"remembers\" that A means the matrix we entered! *)" }], "Input", ImageRegion->{{-0, 1}, {0, 1}}], Cell["\<\ AT=Transpose[A] MatrixForm[AT] (* These lines were made by typing and pressing RETURN as desired. They stay in a \"cell;\" to break the file into cells, there is a menu item called \"Cell.\" I put the cursor at the end of the line where I want a break, and select \"Divide Cell.\" *)\ \>", "Input", ImageRegion->{{-0, 1}, {0, 1}}], Cell[TextData[{ "\n(* Dividing the cell means the output is divided too,\n so it's not so \ hard to match statement and output. *)\n \n (* To make ", StyleBox["Mathematica", FontSlant->"Italic"], " do the calculations you want done,\n you have to press ENTER or press \ shift-RETURN. But that \n only tells ", StyleBox["Mathematica", FontSlant->"Italic"], " to work on the cells that are \n selected, or the cell you've just \ worked on. You can\n put the cursor in each cell you want done, while \ holding \n the SHIFT key down, and click, to select several cells.\n \ Also, you can go to the Edit menu and select \"Select all \n Cells.\" Then \ when you press ENTER they all \"run.\" \n You can also select \"Evaluation \ -> Evaluate Notebook\" \n in the Kernel menu. *)\n\nB=A.AT (* this is how \ matrices are multiplied *)\n\nMatrixForm[B]" }], "Input", ImageRegion->{{-0, 1}, {0, 1}}], Cell["\<\ C1=AT.A (* Can't use \"C\" as a symbol; it's Protected *) MatrixForm[C1]\ \>", "Input", ImageRegion->{{-0, 1}, {0, 1}}], Cell["\<\ Det[A] (* to \"run\" this, press the \"ENTER\" key, not \"RETURN\" *) (* You can press the ENTER key anywhere inside the cell bracket -> Then you can close the window and open it again to get a \"cleaner\" view of the output *) MatrixForm[Inverse[A]] (* You can combine by nesting *) Det[%] MatrixForm[Inverse[%%]] (* The percent sign is a \"ditto\" so the output for this one should be the inverse of the inverse of A. We can double or triple ditto! *) \ \>", "Input", ImageRegion->{{-0, 1}, {0, 1}}], Cell[TextData[{ " \n(* Here is where the construction of ERO matrices begins, and\nshows \ my false starts. It took a lot of looking up and browsing\nthru Wolfram's \ \"The ", StyleBox["Mathematica", FontSlant->"Italic"], " Book\" to finally find something\nthat worked. *)\n\ni4=IdentityMatrix[4] \ (* How to make a 4 x 4 identity matrix *)\n\ne1=Transpose[i4][[1]]\n\n\ e2=Transpose[i4][[2]]\n\ne12=e1.i4[[2]] (* This shows a problem: ", StyleBox["Mathematica", FontSlant->"Italic"], " does not\ndistinguish between row and column vectors! So I can't form\n\ matrices such as e_1 e_2^T, (4 x 1)(1 x 4) = (4 x 4), which\nis the matrix \ with a one in row 1 and column 2 and zeros \nelsewhere. I need these matrices \ to build ERO matrices!\nIt looks as tho I have to build them by hand! Maybe\n\ build six of them \"by hand,\" use transpose to get six \nmore, and use \ DiagonalMatrix[ list ] four time to get the other\nfour. Maybe there's a \ better way. The next stuff shows how\nthe ERO matrices were constructed with \ parameters, so that\nthey did not have to be created one by one. It shows \ what we\nhave to do to define our own functions in ", StyleBox["Mathematica", FontSlant->"Italic"], ". \n\nTo skip over this part, scroll down, looking for\n \n\"Now we are \ done..\" *)\n\nClear[e12] (* This gets rid of e12; I want to create\n\"eij\" \ so that when I put indices i and j between 1\nand 4 (inclusive), I get \ the matrix with a 1 in row i\nand column j and zeros everywhere else. \ These matrices\ncan be used to build any matrix we want; they form a \n\ \"basis\" for the collection of matrices. *)" }], "Input", ImageRegion->{{-0, 1}, {0, 1}}], Cell[TextData[{ "\n(* Next we will see how to define our own functions. The \"underscores\"\ \n are essential, along with the := below in the function of two var-\n \ iables defined there. We use the If function to give output\n of 1 if \ x=y and output zero if x=y is false. *)\n\nkd[x_,y_]:=If[x==y,1,0] (* The \ Kronecker Delta *)\n\n(* The Kronecker Delta, here kd[x,y] is usually written\ \n \\delta_xy = 1 if x=y, and \\delta_xy = 0 if x and\n y are not \ equal. ", StyleBox["Mathematica", FontSlant->"Italic"], " uses == as the equal sign\n in an e q u a t i o n. *)\n\nkd[1,2]\n\n\ kd[1,1]" }], "Input", ImageRegion->{{-0, 1}, {0, 1}}], Cell["\<\ f12[x_,y_]:=kd[x,1]*kd[y,2] f12[1,2] f12[1,3] e12=Array[f12, {4,4}] (* This is another way to make a matrix -- it works if we know how to define A_ij as F(i,j). In this example, F is the function f12 defined above, and the values of i and j are from 1 to 4. Another example gives a 3 x 4 matrix: *) MatrixForm[Array[ f12, {3,4} ]]\ \>", "Input", ImageRegion->{{-0, 1}, {0, 1}}], Cell["\<\ MatrixForm[e12]\ \>", "Input", ImageRegion->{{-0, 1}, {0, 1}}], Cell["\<\ (* Since I don't want to have to make matrices with f13, f14, f21, etc, I can define a function with parameters (as we did with exp( rx ) ), but I have to group them so that I can use the parameters i and j to name the function as a function of the two variables x and y. *) f[i_,j_][x_,y_]:=kd[x,i]*kd[y,j] f[1,2][1,2] f[1,2][3,4] (* N o w I can make a function whose value is a matrix using Array *) a[i_,j_]:=Array[f[i,j], {4,4} ] MatrixForm[a[2,3]]\ \>", "Input", ImageRegion->{{-0, 1}, {0, 1}}], Cell["\<\ roA[c_,i_,j_]:=i4+c a[j,i] (* roA[c,i,j].A is the matrix obtained from A by adding c times row i of A to row j of A. That is, it's one of the ERO matrices, called A_ij(c) in our text. *) MatrixForm[roA[-3,2,3]]\ \>", "Input", ImageRegion->{{-0, 1}, {0, 1}}], Cell["\<\ (* We can make a matrix that multiplies row i by a non-zero constant c -- we take the 1 out of row i of the identity matrix and replace it by a c: *) roM[i_,c_]:=(i4+(c-1) a[i,i]) MatrixForm[roM[3,-2]]\ \>", "Input", ImageRegion->{{-0, 1}, {0, 1}}], Cell["\<\ (* We need a matrix that switches rows i and j. It looks messy because we have to remove two ones from the identity and put them in row i col j and in row j col i: *) roP[i_,j_]:=i4-a[i,i]-a[j,j]+a[i,j]+a[j,i] MatrixForm[roP[2,4]] (* Now we are done making ERO matrices. What follows shows them being used. *)\ \>", "Input", ImageRegion->{{-0, 1}, {0, 1}}], Cell["\<\ (* Let's use EROs on the matrix A we defined first Here is A: {{1,-1,1,-1},{-1,1,-1,-1},{-1,-1,1,0},{1,1,1,-1}}. we'll want to add row 1 to rows 2 and 3 and subtract row 1 from row 4. To do so, we multiply on the left by an ERO matrix three times. If we have two or more statements on one line, separated by a semicolon, only the last statement's output is shown! *) A1=roA[1,1,2].A MatrixForm[A1] A2=roA[1,1,3].A1; MatrixForm[A2] A3=roA[-1,1,4].A2; MatrixForm[A3]\ \>", "Input", ImageRegion->{{-0, 1}, {0, 1}}], Cell["\<\ (* When we look at A3, it looks as tho we want to add row 4 to row 3 of A3 *) A4=roA[1,4,3].A3; MatrixForm[A4]\ \>", "Input", ImageRegion->{{-0, 1}, {0, 1}}], Cell["\<\ (* Next we want to switch rows 4 and 2 of A4 *) A5=roP[2,4].A4; MatrixForm[A5]\ \>", "Input", ImageRegion->{{-0, 1}, {0, 1}}], Cell[TextData[{ "\n(* To get to REF we have to make sure we have leading\n ones in each \ row. We use roM's for this, but we have \n to be careful! ", StyleBox["Mathematica", FontSlant->"Italic"], " does exact arithmetic with \n fractions, but as soon as we use a \ decimal point,\n ", StyleBox["Mathematica", FontSlant->"Italic"], " thinks our elements are \"approximate\"\n numbers! Here is what \ happens: *)" }], "Input", ImageRegion->{{-0, 1}, {0, 1}}], Cell[TextData[{ " \nA6=roM[4,-1/2].(roM[3,1/2].(roM[2,1/2].A5)); MatrixForm[A6]\n\n(* The \ parentheses seem to be essential; ", StyleBox["Mathematica", FontSlant->"Italic"], " does not seem\nto like a.b.c, but requires (I think) a.(b.c) *)" }], "Input", ImageRegion->{{-0, 1}, {0, 1}}], Cell[TextData[{ "\n \nA6ap=roM[4,-.5].(roM[3,.5].(roM[2,.5].A5)); MatrixForm[A6ap]\n\n(* \ The decimal points even after integers tell us that \n ", StyleBox["Mathematica", FontSlant->"Italic"], " thinks these may only be approximate values. *)\n\n" }], "Input", ImageRegion->{{-0, 1}, {0, 1}}], Cell[TextData[{ "(* You might want to keep going, to get to RREF form, just\n to see on \ your own how using the ERO matrices works. \n However, ", StyleBox["Mathematica", FontSlant->"Italic"], " has a command for doing that. *)\n \nrrefA=RowReduce[A]; \ MatrixForm[rrefA]" }], "Input", ImageRegion->{{-0, 1}, {0, 1}}], Cell["\<\ (* Let's work on solving a system of equations in matrix form: Ax=b. There are two ways here because we know A is invertible: *) b={1,2,3,4}; LinearSolve[A, b] Inverse[A].b\ \>", "Input", ImageRegion->{{-0, 1}, {0, 1}}], Cell[TextData[{ "(* Another way: solve the system of equations. Here is A again:\n\n\ {{1,-1,1,-1},{-1,1,-1,-1},{-1,-1,1,0},{1,1,1,-1}}. Now we can\n\njust write \ down the equations in ", StyleBox["Mathematica", FontSlant->"Italic"], "'s way: *)\n\n\nSolve[{x-y+z-w, -x+y-z-w, -x-y+z, x+y+z-w}=={1,2,3,4}, \ {x,y,z,w} ]\n\n(* Notice we had to list the unknowns we wanted to find. *)\n" }], "Input", ImageRegion->{{-0, 1}, {0, 1}}] }, FrontEndVersion->"4.1 for Macintosh", ScreenRectangle->{{0, 1280}, {0, 1004}}, WindowToolbars->{}, CellGrouping->Manual, WindowSize->{643, 736}, WindowMargins->{{9, Automatic}, {Automatic, 21}}, PrivateNotebookOptions->{"ColorPalette"->{RGBColor, -1}}, ShowCellLabel->True, ShowCellTags->False, RenderingOptions->{"ObjectDithering"->True, "RasterDithering"->False}, MacintoshSystemPageSetup->"\<\ 00<0001804P000000]P2:?oQon82n@960dL5:0?l0080001804P000000]P2:001 0000I00000400`<300000BL?00400@00000000000000060801T1T00000000000 00000000000000000000000000000000\>" ] (******************************************************************* 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[1705, 50, 810, 20, 207, "Input"], Cell[2518, 72, 535, 10, 177, "Input"], Cell[3056, 84, 361, 12, 162, "Input"], Cell[3420, 98, 933, 17, 282, "Input"], Cell[4356, 117, 134, 6, 72, "Input"], Cell[4493, 125, 537, 17, 237, "Input"], Cell[5033, 144, 1707, 29, 537, "Input"], Cell[6743, 175, 684, 13, 252, "Input"], Cell[7430, 190, 399, 15, 207, "Input"], Cell[7832, 207, 75, 4, 42, "Input"], Cell[7910, 213, 540, 20, 282, "Input"], Cell[8453, 235, 290, 10, 132, "Input"], Cell[8746, 247, 287, 11, 147, "Input"], Cell[9036, 260, 389, 13, 177, "Input"], Cell[9428, 275, 534, 19, 267, "Input"], Cell[9965, 296, 176, 7, 87, "Input"], Cell[10144, 305, 143, 5, 57, "Input"], Cell[10290, 312, 487, 12, 117, "Input"], Cell[10780, 326, 303, 7, 87, "Input"], Cell[11086, 335, 310, 7, 132, "Input"], Cell[11399, 344, 336, 8, 87, "Input"], Cell[11738, 354, 245, 9, 132, "Input"], Cell[11986, 365, 443, 9, 177, "Input"] } ] *) (******************************************************************* End of Mathematica Notebook file. *******************************************************************)