(*CacheID: 234*) (* Internal cache information: NotebookFileLineBreakTest NotebookFileLineBreakTest NotebookDataPosition[ 0, 0] NotebookDataLength[ 18589, 650] NotebookOptionsPosition[ 14213, 503] NotebookOutlinePosition[ 15033, 532] CellTagsIndexPosition[ 14990, 529] WindowFrame->Normal ContainsDynamic->False*) (* Beginning of Notebook Content *) Notebook[{ Cell["Common Mistakes for Beginners to Mathematica", "Title"], Cell[CellGroupData[{ Cell["Part ONE", "Subtitle"], Cell["\<\ Forgetting or not understanding the differences between (\[CenterEllipsis]) \ {\[CenterEllipsis]} [\[CenterEllipsis]]\ \>", "Section"], Cell["\<\ (\[CenterEllipsis]) parenthesis are for logical grouping and are useful \ when you are unsure which operations take precedence\t\ \>", "Text"], Cell[CellGroupData[{ Cell["Three Examples of common mistakes:", "Subsubsection", CellChangeTimes->{{3.394513397693561*^9, 3.3945134013937683`*^9}}], Cell[BoxData[ RowBox[{"Cos", RowBox[{"(", RowBox[{"k", " ", "x"}], ")"}]}]], "Input"], Cell[BoxData[ RowBox[{"Plot", "[", RowBox[{ RowBox[{"Sin", "[", "x", "]"}], ",", RowBox[{"(", RowBox[{"x", ",", "0", ",", " ", "\[Pi]"}], ")"}]}], "]"}]], "Input", EmphasizeSyntaxErrors->True], Cell[BoxData[ RowBox[{"Sort", "[", RowBox[{"(", RowBox[{"x", ",", "y", ",", "z"}], ")"}], "]"}]], "Input", EmphasizeSyntaxErrors->True], Cell["\<\ {\[CenterEllipsis]} curlies are for lists, iterators, and variable bounds\ \>", "Text"] }, Open ]], Cell[CellGroupData[{ Cell["Example of a common mistake:", "Subsubsection", CellChangeTimes->{{3.3945134101314173`*^9, 3.3945134170300283`*^9}}], Cell[BoxData[ RowBox[{ RowBox[{"{", FractionBox[ SqrtBox["2"], "2"], "}"}], RowBox[{"{", RowBox[{"a", ",", "b", ",", "c"}], "}"}]}]], "Input"], Cell["\<\ [\[CenterEllipsis]] single brackets are for lists, iterators, and variable \ bounds \t\tCommon Mistakes:\ \>", "Text"] }, Open ]], Cell[CellGroupData[{ Cell["Examples of common mistakes:", "Subsubsection"], Cell[BoxData[{ RowBox[{ RowBox[{ RowBox[{"SomeList", " ", "=", " ", RowBox[{"{", RowBox[{"a", ",", "b", ",", "c", ",", "d"}], "}"}]}], ";"}], "\[IndentingNewLine]"}], "\[IndentingNewLine]", RowBox[{"SomeList", "[", "1", "]"}]}], "Input"], Cell[BoxData[ RowBox[{ RowBox[{"[", RowBox[{ RowBox[{ RowBox[{"(", RowBox[{ SuperscriptBox["z", "2"], " ", "+", " ", SuperscriptBox["y", "2"]}], ")"}], "c"}], " ", "+", " ", RowBox[{"b", " ", SuperscriptBox["y", "3"]}]}], "]"}], "a"}]], "Input", EmphasizeSyntaxErrors->True], Cell["\<\ [[\[CenterEllipsis]]] double brackets are for lists, iterators, and variable \ bounds\ \>", "Text"] }, Open ]], Cell[CellGroupData[{ Cell["Example of common mistake:", "Subsubsection", CellChangeTimes->{{3.394513425217382*^9, 3.394513427766623*^9}}], Cell[BoxData[ RowBox[{"Exp", "[", RowBox[{"[", "1", "]"}], "]"}]], "Input"] }, Open ]], Cell[CellGroupData[{ Cell[TextData[{ "Forgetting ", StyleBox["Mathematica's convention of capitalization of Functions", FontSlant->"Italic"] }], "Section"], Cell[CellGroupData[{ Cell["Examples of common mistakes:", "Subsubsection"], Cell[BoxData[ RowBox[{"arccos", "[", "1", "]"}]], "Input"], Cell[BoxData[ RowBox[{"Arccos", "[", "1", "]"}]], "Input"] }, Open ]] }, Open ]], Cell[CellGroupData[{ Cell["Forgetting to use patterns in function definitions", "Section"], Cell[CellGroupData[{ Cell["Examples of common mistakes:", "Subsubsection"], Cell[BoxData[ RowBox[{ RowBox[{"MyFunction", "[", RowBox[{"x", ",", "y", ",", "z"}], "]"}], " ", ":=", " ", RowBox[{ RowBox[{"Sin", "[", "x", "]"}], " ", RowBox[{"Sin", "[", "y", "]"}], " ", RowBox[{"Sin", "[", "z", "]"}]}]}]], "Input"], Cell[BoxData[ RowBox[{"MyFunction", "[", RowBox[{"\[Pi]", ",", RowBox[{"\[Pi]", "/", "2"}], ",", "0"}], "]"}]], "Input"] }, Open ]] }, Open ]], Cell["\<\ Forgetting to delayed evaluation, :=, in function definitions when the \ placeholders have been previously defined.\ \>", "Section"], Cell["Example of common mistake:", "Subsubsection", CellChangeTimes->{{3.394513442772594*^9, 3.394513445381937*^9}}], Cell[BoxData[{ RowBox[{ RowBox[{"x", "=", " ", RowBox[{"\[Pi]", "/", "2"}]}], ";"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"AbsSin", "[", "x_", "]"}], " ", "=", " ", RowBox[{"Abs", "[", RowBox[{"Sin", "[", RowBox[{"Abs", "[", "x", "]"}], "]"}], "]"}]}]}], "Input"], Cell[BoxData[ RowBox[{ RowBox[{"Plot", "[", RowBox[{ RowBox[{"AbsSin", "[", "z", "]"}], ",", RowBox[{"{", RowBox[{"z", ",", RowBox[{ RowBox[{"-", "2"}], "\[Pi]"}], ",", RowBox[{"2", "\[Pi]"}]}], "}"}], ",", RowBox[{"PlotStyle", "->", "Thick"}]}], "]"}], " "}]], "Input", CellChangeTimes->{{3.394513208736352*^9, 3.39451325211065*^9}}] }, Open ]], Cell[CellGroupData[{ Cell["Part TWO", "Subtitle"], Cell[" The difference between assignment = and equality testing ==", "Section"], Cell[CellGroupData[{ Cell["Examples of common mistakes:", "Subsubsection"], Cell[BoxData[ RowBox[{"Solve", "[", RowBox[{ RowBox[{"{", RowBox[{ RowBox[{"h", "=", " ", RowBox[{ RowBox[{"3", " ", "p"}], " ", "+", " ", RowBox[{"4", " ", "q"}]}]}], ",", " ", RowBox[{"k", " ", "=", " ", RowBox[{ RowBox[{"5", "p"}], " ", "-", " ", "q"}]}]}], "}"}], ",", RowBox[{"{", RowBox[{"p", ",", "q"}], "}"}]}], "]"}]], "Input", CellChangeTimes->{{3.3947901031398706`*^9, 3.394790107013185*^9}}], Cell[BoxData[ RowBox[{"\[IndentingNewLine]", RowBox[{"\[Delta]", " ", "\[Equal]", " ", "24"}]}]], "Input"] }, Open ]], Cell[CellGroupData[{ Cell[" Not using enough commas", "Section"], Cell[CellGroupData[{ Cell["Example of a common mistake:", "Subsubsection", CellChangeTimes->{{3.3945134665658092`*^9, 3.394513477143373*^9}}], Cell[BoxData[ RowBox[{"Plot", "[", RowBox[{ RowBox[{"Sin", "[", RowBox[{"x", " ", "+", " ", RowBox[{"Exp", "[", RowBox[{"-", "x"}], "]"}]}], "]"}], " ", RowBox[{"{", RowBox[{"x", ",", "0", ",", "Pi"}], "}"}]}], "]"}]], "Input"] }, Open ]] }, Open ]], Cell["7. Forgetting that a variable has been defined", "Section"], Cell["Example of common mistake:", "Subsubsection", CellChangeTimes->{{3.394513480382175*^9, 3.3945134837514668`*^9}}], Cell[BoxData[ RowBox[{"A", " ", "=", " ", SuperscriptBox["\[ExponentialE]", FractionBox[ RowBox[{"-", "1.2"}], RowBox[{"k", " ", "373"}]]]}]], "Input"], Cell[CellGroupData[{ Cell["\<\ \tPractical Advice 1: \t\tClear Variables\ \>", "Subsection"], Cell[BoxData[{ RowBox[{ RowBox[{"Clear", "[", "k", "]"}], ";"}], "\[IndentingNewLine]", RowBox[{"A", " ", "=", " ", SuperscriptBox["\[ExponentialE]", FractionBox[ RowBox[{"-", "1.2"}], RowBox[{"k", " ", "373"}]]]}]}], "Input"] }, Open ]], Cell[CellGroupData[{ Cell["\<\ \tPractical Advice 2: \t\tSecond to last resort, clear everything\ \>", "Subsection"], Cell[BoxData[ RowBox[{ RowBox[{"Clear", "[", "\"\\"", "]"}], ";"}]], "Input"] }, Open ]], Cell["\<\ \tPractical Advice 3: \tLast resort, kill the kernel and restart it Use menu: Evaluation\ \>", "Subsection", CellChangeTimes->{{3.394512151873313*^9, 3.394512154106518*^9}}] }, Closed]], Cell[CellGroupData[{ Cell["Part THREE", "Subtitle"], Cell["Using a function from a package, before loading the package", "Text", CellChangeTimes->{{3.3945119517318487`*^9, 3.394511969492754*^9}}], Cell[BoxData[ RowBox[{"Histogram3D", "[", RowBox[{"Table", "[", RowBox[{ RowBox[{"{", RowBox[{ RowBox[{"RandomReal", "[", "]"}], ",", RowBox[{"RandomReal", "[", "]"}]}], "}"}], ",", RowBox[{"{", "5", "}"}]}], "]"}], "]"}]], "Input", CellChangeTimes->{{3.394511986871756*^9, 3.394512048193028*^9}, { 3.3945121030317307`*^9, 3.394512103242836*^9}, {3.3945150988387747`*^9, 3.3945151048457117`*^9}}], Cell["To load the package ... ", "Text", CellChangeTimes->{{3.394512070415207*^9, 3.394512074254125*^9}, 3.394514414637168*^9}], Cell[BoxData[ RowBox[{"<<", "Histogram`"}]], "Input", CellChangeTimes->{{3.394512058697629*^9, 3.394512064575*^9}, { 3.394513915567964*^9, 3.39451392777351*^9}}], Cell["\<\ find the correct name (The package directories are located in \"Packages\" in \ \"AddOns\" the $InstallationDirectory, on macintosh:\ \>", "Text", CellChangeTimes->{{3.3945144181704884`*^9, 3.394514437216378*^9}, { 3.3945145191428127`*^9, 3.3945145428009577`*^9}, {3.394514586012114*^9, 3.394514623868305*^9}, {3.394514765384046*^9, 3.3945147729783573`*^9}, { 3.394514839028302*^9, 3.394514859214596*^9}}], Cell[BoxData[ RowBox[{"SetDirectory", "[", "$InstallationDirectory", "]"}]], "Input", CellChangeTimes->{{3.394514656077148*^9, 3.39451465851298*^9}, { 3.3945147550395412`*^9, 3.394514781890153*^9}}], Cell[BoxData[ RowBox[{"FileNames", "[", "]"}]], "Input", CellChangeTimes->{{3.394514798828648*^9, 3.394514823427208*^9}}], Cell[BoxData[{ RowBox[{"SetDirectory", "[", "\"\\"", "]"}], "\[IndentingNewLine]", RowBox[{"FileNames", "[", "]"}]}], "Input", CellChangeTimes->{{3.394514866555945*^9, 3.394514903568454*^9}}], Cell[BoxData[{ RowBox[{"SetDirectory", "[", "\"\\"", "]"}], "\[IndentingNewLine]", RowBox[{"FileNames", "[", "]"}]}], "Input", CellChangeTimes->{{3.394514866555945*^9, 3.394514921293035*^9}}], Cell["Doing this correctly now ...", "Text", CellChangeTimes->{{3.394514948907947*^9, 3.3945149620863743`*^9}}], Cell[BoxData[ RowBox[{"<<", "Histograms`"}]], "Input", CellChangeTimes->{{3.394514374184905*^9, 3.394514382665016*^9}}], Cell[BoxData[ RowBox[{"Histogram3D", "[", RowBox[{"Table", "[", RowBox[{ RowBox[{"{", RowBox[{ RowBox[{"RandomReal", "[", "]"}], ",", RowBox[{"RandomReal", "[", "]"}]}], "}"}], ",", RowBox[{"{", "20", "}"}]}], "]"}], "]"}]], "Input", CellChangeTimes->{ 3.3945121128304*^9, {3.394514986002219*^9, 3.394514987466075*^9}, { 3.394515137937269*^9, 3.394515145619211*^9}, {3.3945151797557983`*^9, 3.394515191220696*^9}}], Cell[CellGroupData[{ Cell[" Using formatting commands in assignments", "Section"], Cell[CellGroupData[{ Cell["Examples of common mistakes:", "Subsubsection"], Cell[BoxData[ RowBox[{"mymat", " ", "=", " ", RowBox[{ RowBox[{"{", "\[IndentingNewLine]", " ", RowBox[{ RowBox[{"{", RowBox[{"1", ",", "3", ",", "7"}], "}"}], ",", "\[IndentingNewLine]", " ", RowBox[{"{", RowBox[{"3", ",", "2", ",", "4"}], "}"}], ",", "\[IndentingNewLine]", " ", RowBox[{"{", RowBox[{"7", ",", " ", "4", " ", ",", " ", "3"}], "}"}]}], "\[IndentingNewLine]", " ", "}"}], "//", "MatrixForm"}]}]], "Input"], Cell[BoxData[ RowBox[{"Eigenvalues", "[", "mymat", "]"}]], "Input"] }, Open ]], Cell[CellGroupData[{ Cell["\<\ \t\tPractical advice, define and display with separate commands\ \>", "Subsection"], Cell[BoxData[{ RowBox[{ RowBox[{"mymat", " ", "=", " ", RowBox[{"{", "\[IndentingNewLine]", " ", RowBox[{ RowBox[{"{", RowBox[{"1", ",", "3", ",", "7"}], "}"}], ",", "\[IndentingNewLine]", " ", RowBox[{"{", RowBox[{"3", ",", "2", ",", "4"}], "}"}], ",", "\[IndentingNewLine]", " ", RowBox[{"{", RowBox[{"7", ",", " ", "4", " ", ",", " ", "3"}], "}"}]}], "\[IndentingNewLine]", " ", "}"}]}], ";"}], "\[IndentingNewLine]", RowBox[{"mymat", "//", "MatrixForm"}]}], "Input"], Cell[BoxData[ RowBox[{ RowBox[{"Eigenvalues", "[", "mymat", "]"}], "//", "N"}]], "Input"] }, Open ]] }, Open ]], Cell[CellGroupData[{ Cell[TextData[{ "Older versions of ", StyleBox["Mathematica", FontSlant->"Italic"], " (previous to 6.0) required that the functions begin plotted had to be \ evaluated first. If you use older notebooks, you will see this. Post 6.0, \ using evaluate still works but affects the behavior, notive the time to \ compute and the appearance of the following two plots. As you will see below, \ using Evaluate still improves the behavior..." }], "Section", CellChangeTimes->{{3.394512287992833*^9, 3.394512412795245*^9}, { 3.3945124490656977`*^9, 3.3945124702891417`*^9}}], Cell["Not using Evaluate : slow and monochrome.", "Text", CellChangeTimes->{{3.394512423345728*^9, 3.3945124324127483`*^9}, { 3.394512474382621*^9, 3.394512492718807*^9}}], Cell[BoxData[ RowBox[{"Plot", "[", RowBox[{ RowBox[{"Table", "[", RowBox[{ RowBox[{"LegendreP", "[", RowBox[{"i", ",", "z"}], "]"}], ",", RowBox[{"{", RowBox[{"i", ",", "1", ",", "11", ",", "2"}], "}"}]}], "]"}], ",", RowBox[{"{", RowBox[{"z", ",", RowBox[{"-", "1"}], ",", "1"}], "}"}], ",", RowBox[{"PlotStyle", "\[Rule]", RowBox[{"Thickness", "[", "0.01", "]"}]}]}], "]"}]], "Input", CellChangeTimes->{{3.394512189558803*^9, 3.394512238423911*^9}}], Cell["Using Evaluate : Fast and multicolored.", "Text", CellChangeTimes->{{3.394512423345728*^9, 3.3945124324127483`*^9}, { 3.394512474382621*^9, 3.394512492718807*^9}, {3.394512524085293*^9, 3.3945125361516027`*^9}}], Cell[CellGroupData[{ Cell["\<\ \t\tPractical advice: \t\t\tUse Evaluate in Plot when in doubt\ \>", "Subsection", CellChangeTimes->{{3.394512505278337*^9, 3.394512515280488*^9}}], Cell[BoxData[ RowBox[{"Plot", "[", RowBox[{ RowBox[{"Evaluate", "[", RowBox[{"Table", "[", RowBox[{ RowBox[{"LegendreP", "[", RowBox[{"i", ",", "z"}], "]"}], ",", RowBox[{"{", RowBox[{"i", ",", "1", ",", "11", ",", "2"}], "}"}]}], "]"}], "]"}], ",", RowBox[{"{", RowBox[{"z", ",", RowBox[{"-", "1"}], ",", "1"}], "}"}], ",", RowBox[{"PlotStyle", "\[Rule]", RowBox[{"Thickness", "[", "0.01", "]"}]}]}], "]"}]], "Input", CellChangeTimes->{{3.3945122764508553`*^9, 3.3945122770817204`*^9}}] }, Open ]] }, Open ]] }, Closed]] }, ScreenStyleEnvironment->"Presentation", PrintingStyleEnvironment->"ColorPrintout", ShowPageBreaks->True, CellGrouping->Manual, WindowSize->{1017, 731}, WindowMargins->{{34, Automatic}, {Automatic, 11}}, WindowTitle->"Lecture 01 MIT 3.016 (Fall 2007) \[Copyright] W. Craig Carter \ 2003-2007", PrintingCopies->1, PrintingPageRange->{1, Automatic}, PrintingOptions->{"PaperOrientation"->"Portrait", "PrintCellBrackets"->False, "PrintMultipleHorizontalPages"->False, "PrintRegistrationMarks"->False, "PrintingMargins"->0}, CellLabelAutoDelete->True, FrontEndVersion->"6.0 for Mac OS X PowerPC (32-bit) (April 20, 2007)", StyleDefinitions->"3016-Carter.nb" ] (* End of Notebook Content *) (* Internal cache information *) (*CellTagsOutline CellTagsIndex->{} *) (*CellTagsIndex CellTagsIndex->{} *) (*NotebookFileOutline Notebook[{ Cell[423, 14, 61, 0, 32, "Title"], Cell[CellGroupData[{ Cell[509, 18, 28, 0, 32, "Subtitle"], Cell[540, 20, 145, 3, 24, "Section"], Cell[688, 25, 154, 3, 16, "Text"], Cell[CellGroupData[{ Cell[867, 32, 127, 1, 28, "Subsubsection"], Cell[997, 35, 93, 3, 22, "Input"], Cell[1093, 40, 209, 6, 22, "Input"], Cell[1305, 48, 144, 4, 22, "Input"], Cell[1452, 54, 98, 2, 16, "Text"] }, Open ]], Cell[CellGroupData[{ Cell[1587, 61, 123, 1, 28, "Subsubsection"], Cell[1713, 64, 160, 6, 39, "Input"], Cell[1876, 72, 129, 4, 24, "Text"] }, Open ]], Cell[CellGroupData[{ Cell[2042, 81, 53, 0, 28, "Subsubsection"], Cell[2098, 83, 259, 7, 49, "Input"], Cell[2360, 92, 324, 11, 24, "Input"], Cell[2687, 105, 110, 3, 16, "Text"] }, Open ]], Cell[CellGroupData[{ Cell[2834, 113, 117, 1, 28, "Subsubsection"], Cell[2954, 116, 79, 2, 22, "Input"] }, Open ]], Cell[CellGroupData[{ Cell[3070, 123, 138, 4, 24, "Section"], Cell[CellGroupData[{ Cell[3233, 131, 53, 0, 28, "Subsubsection"], Cell[3289, 133, 59, 1, 22, "Input"], Cell[3351, 136, 59, 1, 22, "Input"] }, Open ]] }, Open ]], Cell[CellGroupData[{ Cell[3459, 143, 69, 0, 24, "Section"], Cell[CellGroupData[{ Cell[3553, 147, 53, 0, 28, "Subsubsection"], Cell[3609, 149, 257, 7, 22, "Input"], Cell[3869, 158, 128, 3, 22, "Input"] }, Open ]] }, Open ]], Cell[4024, 165, 142, 3, 38, "Section"], Cell[4169, 170, 117, 1, 20, "Subsubsection"], Cell[4289, 173, 289, 8, 36, "Input"], Cell[4581, 183, 383, 11, 22, "Input"] }, Open ]], Cell[CellGroupData[{ Cell[5001, 199, 28, 0, 32, "Subtitle"], Cell[5032, 201, 79, 0, 77, "Section"], Cell[CellGroupData[{ Cell[5136, 205, 53, 0, 28, "Subsubsection"], Cell[5192, 207, 472, 14, 54, "Input"], Cell[5667, 223, 110, 2, 85, "Input"] }, Open ]], Cell[CellGroupData[{ Cell[5814, 230, 43, 0, 77, "Section"], Cell[CellGroupData[{ Cell[5882, 234, 121, 1, 36, "Subsubsection"], Cell[6006, 237, 261, 8, 54, "Input"] }, Open ]] }, Open ]], Cell[6294, 249, 65, 0, 77, "Section"], Cell[6362, 251, 119, 1, 28, "Subsubsection"], Cell[6484, 254, 168, 5, 63, "Input"], Cell[CellGroupData[{ Cell[6677, 263, 71, 3, 78, "Subsection"], Cell[6751, 268, 247, 7, 94, "Input"] }, Open ]], Cell[CellGroupData[{ Cell[7035, 280, 95, 3, 78, "Subsection"], Cell[7133, 285, 91, 2, 54, "Input"] }, Open ]], Cell[7239, 290, 185, 4, 78, "Subsection"] }, Closed]], Cell[CellGroupData[{ Cell[7461, 299, 30, 0, 32, "Subtitle"], Cell[7494, 301, 143, 1, 34, "Text"], Cell[7640, 304, 438, 11, 54, "Input"], Cell[8081, 317, 132, 2, 34, "Text"], Cell[8216, 321, 165, 3, 54, "Input"], Cell[8384, 326, 423, 7, 57, "Text"], Cell[8810, 335, 202, 3, 54, "Input"], Cell[9015, 340, 123, 2, 54, "Input"], Cell[9141, 344, 207, 4, 85, "Input"], Cell[9351, 350, 209, 4, 85, "Input"], Cell[9563, 356, 112, 1, 34, "Text"], Cell[9678, 359, 121, 2, 54, "Input"], Cell[9802, 363, 460, 12, 54, "Input"], Cell[CellGroupData[{ Cell[10287, 379, 60, 0, 77, "Section"], Cell[CellGroupData[{ Cell[10372, 383, 53, 0, 36, "Subsubsection"], Cell[10428, 385, 553, 14, 175, "Input"], Cell[10984, 401, 68, 1, 54, "Input"] }, Open ]], Cell[CellGroupData[{ Cell[11089, 407, 93, 2, 57, "Subsection"], Cell[11185, 411, 602, 15, 205, "Input"], Cell[11790, 428, 92, 2, 54, "Input"] }, Open ]] }, Open ]], Cell[CellGroupData[{ Cell[11931, 436, 574, 11, 161, "Section"], Cell[12508, 449, 174, 2, 34, "Text"], Cell[12685, 453, 513, 14, 85, "Input"], Cell[13201, 469, 223, 3, 34, "Text"], Cell[CellGroupData[{ Cell[13449, 476, 158, 4, 78, "Subsection"], Cell[13610, 482, 563, 16, 85, "Input"] }, Open ]] }, Open ]] }, Closed]] } ] *)