(* Content-type: application/mathematica *) (*** Wolfram Notebook File ***) (* http://www.wolfram.com/nb *) (* CreatedBy='Mathematica 6.0' *) (*CacheID: 234*) (* Internal cache information: NotebookFileLineBreakTest NotebookFileLineBreakTest NotebookDataPosition[ 145, 7] NotebookDataLength[ 16480, 627] NotebookOptionsPosition[ 12774, 522] NotebookOutlinePosition[ 13253, 541] CellTagsIndexPosition[ 13210, 538] WindowFrame->Normal ContainsDynamic->False*) (* Beginning of Notebook Content *) Notebook[{ Cell["Getting Started, Constants, and Functions", "Title"], Cell["\<\ Tuesday, January 24, 2006 Created by Jason Sherman\ \>", "Subsubtitle"], Cell[TextData[{ "Getting around - Using ", StyleBox["Mathematica", FontSlant->"Italic"], " as a calculator" }], "Subsubsection"], Cell["\<\ To enter an expression, just start typing! You can enter multiple \ expressions by pressing the \"Enter\" key after each one. To evaluate \ expressions, press \"Shift+Enter\". If you don't want to see the output of \ your expression, follow the expression with a semi-colon, \" ; \"\ \>", "Text"], Cell[BoxData[{ RowBox[{"1", "+", "2"}], "\[IndentingNewLine]", RowBox[{"2", "+", "2"}]}], "Input"], Cell[BoxData[ RowBox[{ RowBox[{"3", "^", "2"}], "+", RowBox[{"4", "^", "2"}]}]], "Input"], Cell["\<\ All functions, commands, and mathematical constants start with a capital \ letter. Common examples are Sin, Cos, Sqrt, Pi, E, etc.\ \>", "Text"], Cell[TextData[{ "All functions and commands use ", StyleBox["square brackets", FontSlant->"Italic"], " ", StyleBox["not", FontWeight->"Bold"], " ", StyleBox["parentheses", FontSlant->"Italic"], ". Parentheses are used ", StyleBox["only", FontWeight->"Bold", FontSlant->"Italic", FontVariations->{"Underline"->True}], " to show order of operations." }], "Text"], Cell[BoxData[ RowBox[{"Sqrt", "[", "9", "]"}]], "Input"], Cell[BoxData[ RowBox[{"Sin", "[", RowBox[{"Pi", "/", "2"}], "]"}]], "Input"], Cell[BoxData[ RowBox[{"ArcCos", "[", "0", "]"}]], "Input"], Cell[BoxData[ RowBox[{"Exp", "[", "4", "]"}]], "Input"], Cell[BoxData[ RowBox[{"Exp", "[", RowBox[{"I", "*", "Pi"}], "]"}]], "Input"], Cell[BoxData[ RowBox[{"Sqrt", "[", "5", "]"}]], "Input"], Cell[TextData[{ "Notice in the last expression, we asked ", StyleBox["Mathematica", FontSlant->"Italic"], " what the square root of 5 was. It responded by telling us that it is the \ square root of 5! What we really wanted was a numerical approximation to the \ square root of 5. To do this, use the N[ ] command. " }], "Text"], Cell[BoxData[ RowBox[{"N", "[", RowBox[{"Sqrt", "[", "5", "]"}], "]"}]], "Input"], Cell["\<\ What if we wanted more digits? Lets look at the help file for the command N \ [ ]\ \>", "Text"], Cell[BoxData[ RowBox[{"?", "N"}]], "Input"], Cell[BoxData[ RowBox[{"N", "[", RowBox[{ RowBox[{"Sqrt", "[", "5", "]"}], ",", "20"}], "]"}]], "Input"], Cell[TextData[{ "Lets see if ", StyleBox["Mathematica", FontSlant->"Italic"], " knows Pi to 100 digits!" }], "Text"], Cell[BoxData[ RowBox[{"N", "[", RowBox[{"Pi", ",", "100"}], "]"}]], "Input"], Cell[TextData[{ "The percent sign in ", StyleBox["Mathematica", FontSlant->"Italic"], " means 'the previous output', and it is sometimes quite handy. For \ example," }], "Text"], Cell[BoxData[ RowBox[{"Sqrt", "[", "924", "]"}]], "Input"], Cell[BoxData[ RowBox[{"N", "[", RowBox[{"%", ",", "10"}], "]"}]], "Input"], Cell["Cells", "Subsubsection"], Cell[TextData[{ "Information within a ", StyleBox["Mathematica", FontSlant->"Italic"], " notebook is contained in cells. Different cells have different \ properties. The default cell type is \"Input\". When an input cell is \ evaluated, it produces an \"Output\" cell. This is what the small colored \ In[ ]:= and Out[ ]:= mean on the left side of the notebook. To create a new \ cell, move the mouse cursor until it becomes horizontal, click, and then \ start typing. \nCreate a new cell between this line ---------------" }], "Text"], Cell["and this line ----------------------------------------------", "Text"], Cell[TextData[{ "To create a text cell, (like this one), move the mouse until it becomes \ horizontal, click, then select the menu item:", StyleBox[" ", FontVariations->{"Underline"->True}], StyleBox["Format", FontWeight->"Bold", FontSlant->"Italic", FontVariations->{"Underline"->True}], StyleBox[",", FontVariations->{"Underline"->True}], " then ", StyleBox["Style", FontWeight->"Bold", FontSlant->"Italic", FontVariations->{"Underline"->True}], ", then ", StyleBox["Text", FontWeight->"Bold", FontSlant->"Italic", FontVariations->{"Underline"->True}], ", then type away! Try inserting a text cell right after this one. " }], "Text"], Cell[TextData[{ "To change the type of a cell, click on the blue cell marker on the right of \ the screen, then go to ", StyleBox["Format", FontWeight->"Bold", FontSlant->"Italic", FontVariations->{"Underline"->True}], ", ", StyleBox["Style", FontWeight->"Bold", FontSlant->"Italic", FontVariations->{"Underline"->True}], ", and choose a type." }], "Text"], Cell["Defining constants and vectors", "Subsubsection"], Cell["\<\ To define constants (numbers or vectors) use a single equals sign.\ \>", "Text"], Cell[BoxData[ RowBox[{"a", "=", "5"}]], "Input"], Cell[BoxData[ RowBox[{"b", "=", "2"}]], "Input"], Cell[TextData[{ "Vectors are entered using ", StyleBox["curly brackets", FontSlant->"Italic"], ". For example, the vector ", StyleBox["v", FontWeight->"Bold"], " = ", StyleBox["i ", FontWeight->"Bold"], "+ 3 ", StyleBox["j ", FontWeight->"Bold"], "- 2 ", StyleBox["k ", FontWeight->"Bold"], "would be entered as" }], "Text"], Cell[BoxData[ RowBox[{"v", "=", RowBox[{"{", RowBox[{"1", ",", "3", ",", RowBox[{"-", "2"}]}], "}"}]}]], "Input"], Cell["\<\ Once defined, you can use your constants anywhere in the notebook!\ \>", "Text"], Cell[BoxData[ RowBox[{"a", "+", "b"}]], "Input"], Cell[BoxData[ RowBox[{"a", "*", "v"}]], "Input"], Cell[BoxData[ RowBox[{"a", "^", "2"}]], "Input"], Cell[TextData[{ StyleBox["Mathematica", FontSlant->"Italic"], " can do dot and cross products for vectors. It can also find the length of \ a vector by using the command Norm[ ]" }], "Text"], Cell[BoxData[ RowBox[{"u", "=", RowBox[{"{", RowBox[{"2", ",", RowBox[{"-", "1"}], ",", "1"}], "}"}]}]], "Input"], Cell[BoxData[ RowBox[{"Dot", "[", RowBox[{"u", ",", "v"}], "]"}]], "Input"], Cell[BoxData[ RowBox[{"Cross", "[", RowBox[{"u", ",", "v"}], "]"}]], "Input"], Cell[BoxData[ RowBox[{ RowBox[{"Norm", "[", "u", "]"}], "\[IndentingNewLine]"}]], "Input"], Cell["\<\ To clear a constant so it is again a symbolic variable, use \" = . \".\ \>", "Text"], Cell[BoxData[ RowBox[{"a", "=."}]], "Input"], Cell[BoxData[ RowBox[{"a", "+", "b"}]], "Input"], Cell[BoxData[ RowBox[{"b", "=."}]], "Input"], Cell[BoxData[ RowBox[{"a", "+", "b"}]], "Input"], Cell["\<\ If you want to clear everything you have done from memory, use the command \ Quit\ \>", "Text"], Cell[BoxData["u"], "Input"], Cell[BoxData["Quit"], "Input"], Cell[BoxData["u"], "Input"], Cell["\<\ Notice how the numbers in the In[ ] and Out[ ] were reset to 1.\ \>", "Text"], Cell["Defining functions", "Subsubsection"], Cell["\<\ To define a function, use an underscore after each argument name on the left \ hand side of the = but not on the right.\ \>", "Text"], Cell[BoxData[ RowBox[{ RowBox[{"f", "[", "x_", "]"}], "=", RowBox[{ RowBox[{"x", "^", "2"}], "-", "1"}]}]], "Input"], Cell["We can now evaluate f for any x value.", "Text"], Cell[BoxData[ RowBox[{"f", "[", "5", "]"}]], "Input"], Cell[BoxData[ RowBox[{"f", "[", RowBox[{"Sqrt", "[", "9", "]"}], "]"}]], "Input"], Cell[BoxData[ RowBox[{"f", "[", RowBox[{"a", "+", "b"}], "]"}]], "Input"], Cell["\<\ We can define functions of multiple variables in the same way.\ \>", "Text"], Cell[BoxData[ RowBox[{ RowBox[{"g", "[", RowBox[{"x_", ",", "y_"}], "]"}], "=", RowBox[{ RowBox[{"x", "^", "2"}], "+", RowBox[{"y", "^", "2"}], "-", "1"}]}]], "Input"], Cell[BoxData[ RowBox[{"g", "[", RowBox[{"0", ",", "0"}], "]"}]], "Input"], Cell[BoxData[ RowBox[{"g", "[", RowBox[{"1", ",", "1"}], "]"}]], "Input"], Cell[BoxData[ RowBox[{"g", "[", RowBox[{"x", ",", "1"}], "]"}]], "Input"], Cell[BoxData[ RowBox[{"g", "[", RowBox[{"2", ",", "y"}], "]"}]], "Input"], Cell["Working with expressions", "Subsubsection"], Cell["\<\ There are five commands that are very helpful when you want to simplify \ expressions. They are Factor[ ] , Expand[ ] , Together[ ] , Apart[ ] , and \ Simplify[ ].\ \>", "Text"], Cell["\<\ Factor[ ] and Expand[ ] do just what they sound like - they factor or expand \ polynomials.\ \>", "Text"], Cell[BoxData[ RowBox[{"Factor", "[", RowBox[{ RowBox[{"x", "^", "3"}], "-", RowBox[{"7", RowBox[{"x", "^", "2"}]}], "+", RowBox[{"16", "x"}], "-", "12"}], "]"}]], "Input"], Cell[BoxData[ RowBox[{"Factor", "[", RowBox[{"f", "[", "x", "]"}], "]"}]], "Input"], Cell[BoxData[ RowBox[{"Expand", "[", RowBox[{ RowBox[{"(", RowBox[{"x", "-", "3"}], ")"}], "^", "2"}], "]"}]], "Input"], Cell[BoxData[ RowBox[{"Expand", "[", RowBox[{ RowBox[{"(", RowBox[{"x", "-", "1"}], ")"}], "^", "9"}], "]"}]], "Input"], Cell["\<\ If you want the powers of x in decreasing order, you can add the command \" \ //TraditionalForm \"\ \>", "Text"], Cell[BoxData[ RowBox[{ RowBox[{"Expand", "[", RowBox[{ RowBox[{"(", RowBox[{"x", "-", "1"}], ")"}], "^", "9"}], "]"}], "//", "TraditionalForm"}]], "Input"], Cell["\<\ The commands Apart[ ] and Together[ ] are helpful when working with \ fractions.\ \>", "Text"], Cell[BoxData[ RowBox[{"Together", "[", RowBox[{ RowBox[{"a", "/", "b"}], "+", RowBox[{"c", "/", "d"}]}], "]"}]], "Input"], Cell[BoxData[ RowBox[{"Apart", "[", RowBox[{ RowBox[{"(", RowBox[{ RowBox[{"b", "*", "c"}], "+", RowBox[{"a", "*", "d"}]}], ")"}], "/", RowBox[{"(", RowBox[{"b", "*", "d"}], ")"}]}], "]"}]], "Input"], Cell["\<\ Remember Partial fractions? What is the Partial Fraction Decomposition of 1 \ / ( (x-1)(x+1) ) ?\ \>", "Text"], Cell[BoxData[ RowBox[{"Apart", "[", RowBox[{"1", "/", RowBox[{"(", RowBox[{ RowBox[{"(", RowBox[{"x", "-", "1"}], ")"}], "*", RowBox[{"(", RowBox[{"x", "+", "1"}], ")"}]}], ")"}]}], "]"}]], "Input"], Cell["\<\ The last command, Simplify[ ], tries to find the \"Simplest\" form of an \ expression.\ \>", "Text"], Cell[BoxData[ RowBox[{"Simplify", "[", RowBox[{ RowBox[{"(", RowBox[{ RowBox[{"x", "^", "2"}], "+", RowBox[{"2", "*", "x", "*", "y"}], "+", RowBox[{"y", "^", "2"}]}], ")"}], "/", RowBox[{"(", RowBox[{"x", "+", "y"}], ")"}]}], "]"}]], "Input"], Cell[BoxData[ RowBox[{ RowBox[{ RowBox[{"Sin", "[", "x", "]"}], "^", "2"}], "+", RowBox[{ RowBox[{"Cos", "[", "x", "]"}], "^", "2"}]}]], "Input"], Cell["\<\ OK, this should be equal to 1, right? Remember that % means 'previous \ output', and lets use Simplify[ ]\ \>", "Text"], Cell[BoxData[ RowBox[{"Simplify", "[", "%", "]"}]], "Input"], Cell["How do I save?", "Subsubsection"], Cell[TextData[{ "Before saving, go to the menu item ", StyleBox["Cell", FontWeight->"Bold", FontSlant->"Italic", FontVariations->{"Underline"->True}], ", then ", StyleBox["Delete all output", FontWeight->"Bold", FontSlant->"Italic", FontVariations->{"Underline"->True}], ", then click OK. This is ", StyleBox["very", FontWeight->"Bold"], " important, especially if your ", StyleBox["Mathematica", FontSlant->"Italic"], " notebook has graphs. Doing this will delete the graphs and other output, \ but it will leave all of your commands. This ", StyleBox["greatly", FontWeight->"Bold"], " reduces the size of the file. If you send me a file without doing this \ first, I will not accept it (if it is too large, it won't even reach me) and \ you will be asked to submit again." }], "Text", CellChangeTimes->{{3.452861876496085*^9, 3.452861890413157*^9}}], Cell[TextData[{ "To save, go to ", StyleBox["File", FontWeight->"Bold", FontSlant->"Italic", FontVariations->{"Underline"->True}], ", then ", StyleBox[" Save as", FontWeight->"Bold", FontSlant->"Italic", FontVariations->{"Underline"->True}], ". If you are in the lab, you should save to the desktop, e-mail the file \ to yourself and your instructor, then delete the file from the desktop." }], "Text"] }, ScreenStyleEnvironment->"Working", WindowSize->{961, 858}, WindowMargins->{{-2, Automatic}, {Automatic, 0}}, DockedCells->FEPrivate`FrontEndResource[ "FEExpressions", "CompatibilityToolbar"], ShowSelection->True, FrontEndVersion->"6.0 for Mac OS X PowerPC (32-bit) (May 21, 2008)", StyleDefinitions->"DemoText.nb" ] (* End of Notebook Content *) (* Internal cache information *) (*CellTagsOutline CellTagsIndex->{} *) (*CellTagsIndex CellTagsIndex->{} *) (*NotebookFileOutline Notebook[{ Cell[568, 21, 58, 0, 50, "Title"], Cell[629, 23, 81, 3, 69, "Subsubtitle"], Cell[713, 28, 133, 5, 41, "Subsubsection"], Cell[849, 35, 310, 5, 37, "Text"], Cell[1162, 42, 101, 2, 50, "Input"], Cell[1266, 46, 95, 3, 34, "Input"], Cell[1364, 51, 155, 3, 22, "Text"], Cell[1522, 56, 382, 16, 22, "Text"], Cell[1907, 74, 57, 1, 34, "Input"], Cell[1967, 77, 80, 2, 34, "Input"], Cell[2050, 81, 59, 1, 34, "Input"], Cell[2112, 84, 56, 1, 34, "Input"], Cell[2171, 87, 80, 2, 34, "Input"], Cell[2254, 91, 57, 1, 34, "Input"], Cell[2314, 94, 336, 7, 37, "Text"], Cell[2653, 103, 85, 2, 34, "Input"], Cell[2741, 107, 106, 3, 22, "Text"], Cell[2850, 112, 44, 1, 34, "Input"], Cell[2897, 115, 110, 3, 34, "Input"], Cell[3010, 120, 121, 5, 22, "Text"], Cell[3134, 127, 80, 2, 34, "Input"], Cell[3217, 131, 183, 6, 22, "Text"], Cell[3403, 139, 59, 1, 34, "Input"], Cell[3465, 142, 78, 2, 34, "Input"], Cell[3546, 146, 30, 0, 41, "Subsubsection"], Cell[3579, 148, 546, 10, 79, "Text"], Cell[4128, 160, 76, 0, 22, "Text"], Cell[4207, 162, 668, 22, 37, "Text"], Cell[4878, 186, 373, 13, 22, "Text"], Cell[5254, 201, 55, 0, 41, "Subsubsection"], Cell[5312, 203, 90, 2, 22, "Text"], Cell[5405, 207, 49, 1, 34, "Input"], Cell[5457, 210, 49, 1, 34, "Input"], Cell[5509, 213, 346, 17, 22, "Text"], Cell[5858, 232, 126, 4, 34, "Input"], Cell[5987, 238, 90, 2, 22, "Text"], Cell[6080, 242, 49, 1, 34, "Input"], Cell[6132, 245, 49, 1, 34, "Input"], Cell[6184, 248, 49, 1, 34, "Input"], Cell[6236, 251, 195, 5, 22, "Text"], Cell[6434, 258, 126, 4, 34, "Input"], Cell[6563, 264, 79, 2, 34, "Input"], Cell[6645, 268, 81, 2, 34, "Input"], Cell[6729, 272, 93, 2, 50, "Input"], Cell[6825, 276, 94, 2, 22, "Text"], Cell[6922, 280, 45, 1, 34, "Input"], Cell[6970, 283, 49, 1, 34, "Input"], Cell[7022, 286, 45, 1, 34, "Input"], Cell[7070, 289, 49, 1, 34, "Input"], Cell[7122, 292, 105, 3, 22, "Text"], Cell[7230, 297, 27, 0, 34, "Input"], Cell[7260, 299, 30, 0, 34, "Input"], Cell[7293, 301, 27, 0, 34, "Input"], Cell[7323, 303, 88, 2, 22, "Text"], Cell[7414, 307, 43, 0, 41, "Subsubsection"], Cell[7460, 309, 143, 3, 22, "Text"], Cell[7606, 314, 125, 4, 34, "Input"], Cell[7734, 320, 54, 0, 22, "Text"], Cell[7791, 322, 54, 1, 34, "Input"], Cell[7848, 325, 85, 2, 34, "Input"], Cell[7936, 329, 77, 2, 34, "Input"], Cell[8016, 333, 86, 2, 22, "Text"], Cell[8105, 337, 184, 6, 34, "Input"], Cell[8292, 345, 77, 2, 34, "Input"], Cell[8372, 349, 77, 2, 34, "Input"], Cell[8452, 353, 77, 2, 34, "Input"], Cell[8532, 357, 77, 2, 34, "Input"], Cell[8612, 361, 49, 0, 41, "Subsubsection"], Cell[8664, 363, 188, 4, 22, "Text"], Cell[8855, 369, 115, 3, 22, "Text"], Cell[8973, 374, 191, 6, 34, "Input"], Cell[9167, 382, 87, 2, 34, "Input"], Cell[9257, 386, 131, 4, 34, "Input"], Cell[9391, 392, 131, 4, 34, "Input"], Cell[9525, 398, 122, 3, 22, "Text"], Cell[9650, 403, 175, 6, 34, "Input"], Cell[9828, 411, 104, 3, 22, "Text"], Cell[9935, 416, 132, 4, 34, "Input"], Cell[10070, 422, 231, 8, 34, "Input"], Cell[10304, 432, 121, 3, 22, "Text"], Cell[10428, 437, 236, 8, 34, "Input"], Cell[10667, 447, 110, 3, 22, "Text"], Cell[10780, 452, 280, 9, 34, "Input"], Cell[11063, 463, 157, 5, 34, "Input"], Cell[11223, 470, 130, 3, 22, "Text"], Cell[11356, 475, 61, 1, 34, "Input"], Cell[11420, 478, 39, 0, 41, "Subsubsection"], Cell[11462, 480, 885, 25, 52, "Text"], Cell[12350, 507, 420, 13, 22, "Text"] } ] *) (* End of internal cache information *)