(*********************************************************************** Mathematica-Compatible Notebook This notebook can be used on any computer system with Mathematica 3.0, MathReader 3.0, or any compatible application. The data for the notebook starts with the line of 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[ 7821, 372]*) (*NotebookOutlinePosition[ 8659, 399]*) (* CellTagsIndexPosition[ 8615, 395]*) (*WindowFrame->Normal*) Notebook[{ Cell[CellGroupData[{ Cell["\<\ Linear Algebra functions in Mathematica\ \>", "Title"], Cell[TextData[{ "A matrix in ", StyleBox["Mathematica", FontSlant->"Italic"], " is a list of lists. For example, the matrix\n\n1 2 3\n0 5 6\n0 0 7\n\ \nis inputted like this:" }], "Text"], Cell[CellGroupData[{ Cell[BoxData[ \(a = {{1, 2, 3}, {0, 5, 6}, {0, 0, 7}}\)], "Input"], Cell[BoxData[ \({{1, 2, 3}, {0, 5, 6}, {0, 0, 7}}\)], "Output"] }, Open ]], Cell[TextData[{ StyleBox["Mathematica", FontSlant->"Italic"], " has routines to find the determinant and inverse:" }], "Text"], Cell[CellGroupData[{ Cell[BoxData[ \(Det[a]\)], "Input"], Cell[BoxData[ \(35\)], "Output"] }, Open ]], Cell[CellGroupData[{ Cell[BoxData[ \(Inverse[a]\)], "Input"], Cell[BoxData[ \({{1, \(-\(2\/5\)\), \(-\(3\/35\)\)}, {0, 1\/5, \(-\(6\/35\)\)}, {0, 0, 1\/7}}\)], "Output"] }, Open ]], Cell["You can also find the eigenvalues and eigenvectors:", "Text"], Cell[CellGroupData[{ Cell[BoxData[ \(Eigensystem[a]\)], "Input"], Cell[BoxData[ \({{1, 5, 7}, {{1, 0, 0}, {1, 2, 0}, {3, 6, 2}}}\)], "Output"] }, Open ]], Cell["\<\ The output gives you first the eigenvalues 1, 5 and 7, and then the \ eigenvectors which correspond to these eigenvalues. Products of matrices or matrices and vectors are denoted by a dot. For \ example: \ \>", "Text"], Cell[CellGroupData[{ Cell[BoxData[ \(b = {1, 2, 3}\)], "Input"], Cell[BoxData[ \({1, 2, 3}\)], "Output"] }, Open ]], Cell[CellGroupData[{ Cell[BoxData[ \(a . b\)], "Input"], Cell[BoxData[ \({14, 28, 21}\)], "Output"] }, Open ]], Cell["You can solve linear systems as follows:", "Text"], Cell[CellGroupData[{ Cell[BoxData[ \(x = {x1, x2, x3}\)], "Input"], Cell[BoxData[ \({x1, x2, x3}\)], "Output"] }, Open ]], Cell[CellGroupData[{ Cell[BoxData[ \(Solve[a . x == b, x]\)], "Input"], Cell[BoxData[ \({{x1 \[Rule] \(-\(2\/35\)\), x2 \[Rule] \(-\(4\/35\)\), x3 \[Rule] 3\/7}}\)], "Output"] }, Open ]], Cell[TextData[{ "The first command here is necessary to tell ", StyleBox["Mathematica", FontSlant->"Italic"], " that x is a vector, if you do not do\nthis, you get an error message. \ Here is another example.\n" }], "Text"], Cell[CellGroupData[{ Cell[BoxData[ \(a = {{1, 1}, {1, 2}}\)], "Input"], Cell[BoxData[ \({{1, 1}, {1, 2}}\)], "Output"] }, Open ]], Cell[CellGroupData[{ Cell[BoxData[ \(b = {b1, b2}\)], "Input"], Cell[BoxData[ \({b1, b2}\)], "Output"] }, Open ]], Cell[CellGroupData[{ Cell[BoxData[ \(\(x = {x1, x2}\n\)\)], "Input"], Cell[BoxData[ \({x1, x2}\)], "Output"] }, Open ]], Cell[CellGroupData[{ Cell[BoxData[ \(Solve[a . x == b, x]\)], "Input"], Cell[BoxData[ \({{x1 \[Rule] 2\ b1 - b2, x2 \[Rule] \(-b1\) + b2}}\)], "Output"] }, Open ]], Cell["The following example has a singular matrix.", "Text"], Cell[CellGroupData[{ Cell[BoxData[ \(a = {{1, 1}, {1, 1}}\)], "Input"], Cell[BoxData[ \({{1, 1}, {1, 1}}\)], "Output"] }, Open ]], Cell[CellGroupData[{ Cell[BoxData[ \(b = {2, 2}\)], "Input"], Cell[BoxData[ \({2, 2}\)], "Output"] }, Open ]], Cell[CellGroupData[{ Cell[BoxData[ \(Solve[a . x == b, x]\)], "Input"], Cell[BoxData[ \(Solve::"svars" \( : \ \) "Equations may not give solutions for all \"solve\" variables."\)], "Message"], Cell[BoxData[ \({{x1 \[Rule] 2 - x2}}\)], "Output"] }, Open ]], Cell["The solution tells you that x1=2-x2, but x2 is arbitrary.", "Text"], Cell["\<\ The command RowReduce uses row reduction to simplify a system of \ equations. For example, take the augmented matrix for the system a.x=b, with a and b as in the last \ example.\ \>", "Text"], Cell[CellGroupData[{ Cell[BoxData[ \(c = {{1, 1, 2}, {1, 1, 2}}\)], "Input"], Cell[BoxData[ \({{1, 1, 2}, {1, 1, 2}}\)], "Output"] }, Open ]], Cell[CellGroupData[{ Cell[BoxData[ \(RowReduce[c]\)], "Input"], Cell[BoxData[ \({{1, 1, 2}, {0, 0, 0}}\)], "Output"] }, Open ]], Cell["\<\ After row reduction, the system is reduced to x1+x2=2, and the \ second equation has disappeared.\ \>", "Text"], Cell[TextData[{ StyleBox["Mathematica", FontSlant->"Italic"], " has a habit of inserting extraneous parentheses into expressions and this \ can interfere with matrix operations. Here is an example:" }], "Text"], Cell[CellGroupData[{ Cell[BoxData[ \(m11 = x /. Solve[2*x == 4, x]\)], "Input"], Cell[BoxData[ \({2}\)], "Output"] }, Open ]], Cell["Note that the answer is {2}, not simply 2.", "Text"], Cell[CellGroupData[{ Cell[BoxData[ \(m12 = 1\)], "Input"], Cell[BoxData[ \(1\)], "Output"] }, Open ]], Cell[CellGroupData[{ Cell[BoxData[ \(m21 = 4\)], "Input"], Cell[BoxData[ \(4\)], "Output"] }, Open ]], Cell[CellGroupData[{ Cell[BoxData[ \(m22 = 5\)], "Input"], Cell[BoxData[ \(5\)], "Output"] }, Open ]], Cell[CellGroupData[{ Cell[BoxData[ \(m = {{m11, m12}, {m21, m22}}\)], "Input"], Cell[BoxData[ \({{{2}, 1}, {4, 5}}\)], "Output"] }, Open ]], Cell[CellGroupData[{ Cell[BoxData[ \(Det[m]\)], "Input"], Cell[BoxData[ \(Det::"matrix" \( : \ \) "Argument \!\({\({\({2}\), 1}\), \({4, 5}\)}\) at position \!\(1\) is \ not a rectangular matrix."\)], "Message"], Cell[BoxData[ \(Det[{{{2}, 1}, {4, 5}}]\)], "Output"] }, Open ]], Cell["\<\ The problem is that m is not recognized as a 2 by 2 matrix because \ of the extraneous parentheses. The cure is to first use Flatten, which \ transforms a list of list into a single list and then Partition. The command Partition[m,k] divides a list m into sublists of length k.\ \>", "Text"], Cell[CellGroupData[{ Cell[BoxData[ \(m = Flatten[m]\)], "Input"], Cell[BoxData[ \({2, 1, 4, 5}\)], "Output"] }, Open ]], Cell[CellGroupData[{ Cell[BoxData[ \(m = Partition[m, 2]\)], "Input"], Cell[BoxData[ \({{2, 1}, {4, 5}}\)], "Output"] }, Open ]], Cell[CellGroupData[{ Cell[BoxData[ \(Det[m]\)], "Input"], Cell[BoxData[ \(6\)], "Output"] }, Open ]] }, Open ]] }, FrontEndVersion->"Macintosh 3.0", ScreenRectangle->{{0, 640}, {0, 460}}, WindowSize->{520, 365}, WindowMargins->{{4, Automatic}, {Automatic, 1}}, 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[CellGroupData[{ Cell[1731, 51, 64, 3, 174, "Title"], Cell[1798, 56, 203, 6, 128, "Text"], Cell[CellGroupData[{ Cell[2026, 66, 70, 1, 27, "Input"], Cell[2099, 69, 67, 1, 26, "Output"] }, Open ]], Cell[2181, 73, 134, 4, 32, "Text"], Cell[CellGroupData[{ Cell[2340, 81, 39, 1, 27, "Input"], Cell[2382, 84, 36, 1, 26, "Output"] }, Open ]], Cell[CellGroupData[{ Cell[2455, 90, 43, 1, 27, "Input"], Cell[2501, 93, 120, 2, 42, "Output"] }, Open ]], Cell[2636, 98, 67, 0, 30, "Text"], Cell[CellGroupData[{ Cell[2728, 102, 47, 1, 27, "Input"], Cell[2778, 105, 80, 1, 26, "Output"] }, Open ]], Cell[2873, 109, 229, 8, 94, "Text"], Cell[CellGroupData[{ Cell[3127, 121, 46, 1, 27, "Input"], Cell[3176, 124, 43, 1, 26, "Output"] }, Open ]], Cell[CellGroupData[{ Cell[3256, 130, 38, 1, 27, "Input"], Cell[3297, 133, 46, 1, 26, "Output"] }, Open ]], Cell[3358, 137, 56, 0, 30, "Text"], Cell[CellGroupData[{ Cell[3439, 141, 49, 1, 27, "Input"], Cell[3491, 144, 46, 1, 26, "Output"] }, Open ]], Cell[CellGroupData[{ Cell[3574, 150, 53, 1, 27, "Input"], Cell[3630, 153, 116, 2, 42, "Output"] }, Open ]], Cell[3761, 158, 233, 6, 64, "Text"], Cell[CellGroupData[{ Cell[4019, 168, 53, 1, 27, "Input"], Cell[4075, 171, 50, 1, 26, "Output"] }, Open ]], Cell[CellGroupData[{ Cell[4162, 177, 45, 1, 27, "Input"], Cell[4210, 180, 42, 1, 26, "Output"] }, Open ]], Cell[CellGroupData[{ Cell[4289, 186, 51, 1, 43, "Input"], Cell[4343, 189, 42, 1, 26, "Output"] }, Open ]], Cell[CellGroupData[{ Cell[4422, 195, 53, 1, 27, "Input"], Cell[4478, 198, 84, 1, 26, "Output"] }, Open ]], Cell[4577, 202, 60, 0, 30, "Text"], Cell[CellGroupData[{ Cell[4662, 206, 53, 1, 27, "Input"], Cell[4718, 209, 50, 1, 26, "Output"] }, Open ]], Cell[CellGroupData[{ Cell[4805, 215, 43, 1, 27, "Input"], Cell[4851, 218, 40, 1, 26, "Output"] }, Open ]], Cell[CellGroupData[{ Cell[4928, 224, 53, 1, 27, "Input"], Cell[4984, 227, 133, 3, 37, "Message"], Cell[5120, 232, 55, 1, 26, "Output"] }, Open ]], Cell[5190, 236, 73, 0, 30, "Text"], Cell[5266, 238, 201, 5, 46, "Text"], Cell[CellGroupData[{ Cell[5492, 247, 59, 1, 27, "Input"], Cell[5554, 250, 56, 1, 26, "Output"] }, Open ]], Cell[CellGroupData[{ Cell[5647, 256, 45, 1, 27, "Input"], Cell[5695, 259, 56, 1, 26, "Output"] }, Open ]], Cell[5766, 263, 121, 3, 30, "Text"], Cell[5890, 268, 218, 5, 48, "Text"], Cell[CellGroupData[{ Cell[6133, 277, 62, 1, 27, "Input"], Cell[6198, 280, 37, 1, 26, "Output"] }, Open ]], Cell[6250, 284, 58, 0, 30, "Text"], Cell[CellGroupData[{ Cell[6333, 288, 40, 1, 27, "Input"], Cell[6376, 291, 35, 1, 26, "Output"] }, Open ]], Cell[CellGroupData[{ Cell[6448, 297, 40, 1, 27, "Input"], Cell[6491, 300, 35, 1, 26, "Output"] }, Open ]], Cell[CellGroupData[{ Cell[6563, 306, 40, 1, 27, "Input"], Cell[6606, 309, 35, 1, 26, "Output"] }, Open ]], Cell[CellGroupData[{ Cell[6678, 315, 61, 1, 27, "Input"], Cell[6742, 318, 52, 1, 26, "Output"] }, Open ]], Cell[CellGroupData[{ Cell[6831, 324, 39, 1, 27, "Input"], Cell[6873, 327, 164, 3, 37, "Message"], Cell[7040, 332, 57, 1, 26, "Output"] }, Open ]], Cell[7112, 336, 304, 6, 62, "Text"], Cell[CellGroupData[{ Cell[7441, 346, 47, 1, 27, "Input"], Cell[7491, 349, 46, 1, 26, "Output"] }, Open ]], Cell[CellGroupData[{ Cell[7574, 355, 52, 1, 27, "Input"], Cell[7629, 358, 50, 1, 26, "Output"] }, Open ]], Cell[CellGroupData[{ Cell[7716, 364, 39, 1, 27, "Input"], Cell[7758, 367, 35, 1, 26, "Output"] }, Open ]] }, Open ]] } ] *) (*********************************************************************** End of Mathematica Notebook file. ***********************************************************************)