(* 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[ 14756, 547] NotebookOptionsPosition[ 11988, 467] NotebookOutlinePosition[ 12354, 483] CellTagsIndexPosition[ 12311, 480] WindowFrame->Normal*) (* Beginning of Notebook Content *) Notebook[{ Cell["Functions, Derivatives, and Plots", "Title"], Cell["", "Subsubtitle", CellChangeTimes->{{3.455364888875*^9, 3.455364889171875*^9}}], Cell["Functions (a quick review)", "Subsubsection"], Cell[TextData[{ "Remember when defining your own functions, use an ", StyleBox["underscore ", FontSlant->"Italic"], "after each variable on the left side of the equals sign, not on the right." }], "Text"], Cell[BoxData[ RowBox[{ RowBox[{"f", "[", "x_", "]"}], "=", RowBox[{ RowBox[{"E", "^", RowBox[{"-", "x"}]}], "*", RowBox[{"Sin", "[", "x", "]"}]}]}]], "Input"], Cell[TextData[{ "When using the function, ", StyleBox["do not", FontSlant->"Italic"], " use an underscore. The underscore is ", StyleBox["only", FontSlant->"Italic"], " used in the function definition." }], "Text"], Cell[BoxData[ RowBox[{"f", "[", "t", "]"}]], "Input"], Cell[BoxData[ RowBox[{"f", "[", "0", "]"}]], "Input"], Cell[BoxData[ RowBox[{"f", "[", RowBox[{"Pi", "/", "2"}], "]"}]], "Input"], Cell["Vectors and vector functions", "Subsubsection"], Cell[TextData[{ "Remember, to enter a vector like ", StyleBox["v", FontWeight->"Bold", FontSlant->"Italic"], " = 2", StyleBox[" i ", FontWeight->"Bold", FontSlant->"Italic"], "- 3 ", StyleBox["j", FontWeight->"Bold", FontSlant->"Italic"], " + 7 ", StyleBox["k", FontWeight->"Bold", FontSlant->"Italic"], ", we use curly braces {}" }], "Text", CellChangeTimes->{{3.4545190589375*^9, 3.454519060546875*^9}}], Cell[BoxData[ RowBox[{"v", "=", RowBox[{"{", RowBox[{"2", ",", RowBox[{"-", "3"}], ",", "7"}], "}"}]}]], "Input"], Cell[TextData[{ "To access the i-th component, use ", StyleBox["double square brackets", FontSlant->"Italic"] }], "Text"], Cell[BoxData[ RowBox[{"v", "[", RowBox[{"[", "1", "]"}], "]"}]], "Input"], Cell[BoxData[ RowBox[{"v", "[", RowBox[{"[", "2", "]"}], "]"}]], "Input"], Cell[BoxData[ RowBox[{"v", "[", RowBox[{"[", "3", "]"}], "]"}]], "Input"], Cell["\<\ You can define vector functions in pretty much the same way you define vectors\ \>", "Text", CellChangeTimes->{{3.454519071734375*^9, 3.454519072328125*^9}}], Cell["For example,r(t)=Sin(t)i+Cos(t)j+tkcould be entered by", "Text"], Cell[BoxData[ RowBox[{ RowBox[{"r", "[", "t_", "]"}], "=", RowBox[{"{", " ", RowBox[{ RowBox[{"Sin", "[", "t", "]"}], " ", ",", " ", RowBox[{"Cos", "[", "t", "]"}], " ", ",", " ", "t"}], " ", "}"}]}]], "Input"], Cell[TextData[{ "How could we get the second component (the ", StyleBox["j", FontWeight->"Bold", FontSlant->"Italic"], " component) of ", StyleBox["r ", FontWeight->"Bold", FontSlant->"Italic"], "?" }], "Text"], Cell[BoxData[ RowBox[{"(*", " ", RowBox[{"Enter", " ", "the", " ", "command", " ", "here"}], " ", "*)"}]], "Input"], Cell["Derivatives", "Subsubsection"], Cell["\<\ The command to take a derivative is D. Let's get some help for D.\ \>", "Text"], Cell[BoxData[ RowBox[{"?", "D"}]], "Input"], Cell["Here are some examples:", "Text"], Cell[BoxData[ RowBox[{"f", "[", "x", "]"}]], "Input"], Cell[TextData[{ "The derivative of f( x ). Note, we have to tell ", StyleBox["Mathematica", FontSlant->"Italic"], " what our variable is!" }], "Text"], Cell[BoxData[ RowBox[{"D", "[", RowBox[{ RowBox[{"f", "[", "x", "]"}], ",", "x"}], "]"}]], "Input"], Cell["We can use % (previous output) to take a second derivative.", "Text"], Cell[BoxData[ RowBox[{"D", "[", RowBox[{"%", ",", "x"}], "]"}]], "Input"], Cell["But, there is an easier way!", "Text"], Cell[BoxData[ RowBox[{"D", "[", RowBox[{ RowBox[{"f", "[", "x", "]"}], ",", RowBox[{"{", RowBox[{"x", ",", "2"}], "}"}]}], "]"}]], "Input"], Cell[BoxData[ RowBox[{"D", "[", RowBox[{ RowBox[{"ArcSin", "[", "x", "]"}], ",", RowBox[{"{", RowBox[{"x", ",", "1"}], "}"}]}], "]"}]], "Input"], Cell["------ ! ! ! Important ! ! ! ------", "Subtitle"], Cell["\<\ We can create a function that is the derivative of another function! Just \ use square brackets and an underscore! Let's define g( x ) as the derivative of f( x ), and h( x ) as the second \ derivative of f( x )\ \>", "Text"], Cell[BoxData[ RowBox[{ RowBox[{"g", "[", "x_", "]"}], "=", RowBox[{"D", "[", RowBox[{ RowBox[{"f", "[", "x", "]"}], ",", "x"}], "]"}]}]], "Input"], Cell[BoxData[ RowBox[{ RowBox[{"h", "[", "x_", "]"}], "=", RowBox[{"D", "[", RowBox[{ RowBox[{"f", "[", "x", "]"}], ",", RowBox[{"{", RowBox[{"x", ",", "2"}], "}"}]}], "]"}]}]], "Input"], Cell[BoxData[ RowBox[{"g", "[", RowBox[{"Pi", "/", "6"}], "]"}]], "Input"], Cell[BoxData[ RowBox[{"h", "[", RowBox[{"Pi", "/", "6"}], "]"}]], "Input"], Cell["D also works for vector functions!", "Text"], Cell[BoxData[ RowBox[{"D", "[", RowBox[{ RowBox[{"r", "[", "t", "]"}], ",", "t"}], "]"}]], "Input"], Cell[BoxData[ RowBox[{"D", "[", RowBox[{ RowBox[{"r", "[", "t", "]"}], ",", RowBox[{"{", RowBox[{"t", ",", "2"}], "}"}]}], "]"}]], "Input"], Cell["2-D Plots", "Subsubsection"], Cell[BoxData[ RowBox[{"?", "Plot"}]], "Input"], Cell[BoxData[ RowBox[{"Plot", "[", RowBox[{ RowBox[{"x", "^", "2"}], ",", RowBox[{"{", RowBox[{"x", ",", RowBox[{"-", "3"}], ",", "3"}], "}"}]}], "]"}]], "Input"], Cell["\<\ If we have a function defined, we can use it inside the Plot command!\ \>", "Text"], Cell[BoxData[ RowBox[{"Plot", "[", RowBox[{ RowBox[{"f", "[", "x", "]"}], ",", RowBox[{"{", RowBox[{"x", ",", "0", ",", "5"}], "}"}]}], "]"}]], "Input"], Cell[TextData[{ "If we want to change the range of the plot (the ", StyleBox["y", FontSlant->"Italic"], " values displayed), use the PlotRange option: PlotRange - > { y_min , y_max}" }], "Text", CellChangeTimes->{{3.454519142984375*^9, 3.454519158625*^9}}], Cell[BoxData[ RowBox[{"Plot", "[", RowBox[{ RowBox[{"x", "^", "2"}], ",", RowBox[{"{", RowBox[{"x", ",", RowBox[{"-", "3"}], ",", "3"}], "}"}], ",", RowBox[{"PlotRange", "->", RowBox[{"{", RowBox[{ RowBox[{"-", "4"}], ",", "4"}], "}"}]}]}], "]"}]], "Input"], Cell["\<\ To see all the y-values, and cut off unnecessary y-values, use: PlotRange - > \ All\ \>", "Text", CellChangeTimes->{{3.4545191676875*^9, 3.454519169984375*^9}}], Cell[BoxData[ RowBox[{"Plot", "[", RowBox[{ RowBox[{"x", "^", "2"}], ",", RowBox[{"{", RowBox[{"x", ",", RowBox[{"-", "3"}], ",", "3"}], "}"}], ",", RowBox[{"PlotRange", "\[Rule]", "All"}]}], "]"}]], "Input"], Cell[TextData[{ "We can change the color using the PlotStyle - > RBGColor option. RGBColor[ \ ", StyleBox["red, green, blue ", FontSlant->"Italic"], "] will display a plot in color. ", StyleBox["Red, Green, and Blue", FontSlant->"Italic"], " should all be numbers between 0 and 1." }], "Text"], Cell[BoxData[ RowBox[{"Plot", "[", RowBox[{ RowBox[{"x", "^", "2"}], ",", RowBox[{"{", RowBox[{"x", ",", RowBox[{"-", "3"}], ",", "3"}], "}"}], ",", RowBox[{"PlotStyle", "\[Rule]", RowBox[{"RGBColor", "[", RowBox[{"1", ",", "0", ",", "1"}], "]"}]}]}], "]"}]], "Input"], Cell[BoxData[ RowBox[{"Plot", "[", RowBox[{ RowBox[{"x", "^", "2"}], ",", RowBox[{"{", RowBox[{"x", ",", RowBox[{"-", "3"}], ",", "3"}], "}"}], ",", RowBox[{"PlotStyle", "\[Rule]", RowBox[{"RGBColor", "[", RowBox[{"0", ",", "0", ",", "1"}], "]"}]}]}], "]"}]], "Input"], Cell[TextData[{ "Another way of changing the color is the PlotStyle -> Hue option. Hue[ ", StyleBox["n", FontSlant->"Italic"], " ] set the color. ", StyleBox["n", FontSlant->"Italic"], " should be between 0 and 1. A hue of 0 corresponds to red, increasing from \ 0 to 1 goes through the colors of the rainbow!" }], "Text"], Cell[BoxData[ RowBox[{"Plot", "[", RowBox[{ RowBox[{"x", "^", "2"}], ",", RowBox[{"{", RowBox[{"x", ",", RowBox[{"-", "3"}], ",", "3"}], "}"}], ",", RowBox[{"PlotStyle", "\[Rule]", RowBox[{"Hue", "[", "0", "]"}]}]}], "]"}]], "Input"], Cell[TextData[{ "Label your axes with the AxesLabel - > { \" ", StyleBox["horizontal-axis-label", FontSlant->"Italic"], " \" , \" ", StyleBox["vertical-axis-label", FontSlant->"Italic"], " \" } option." }], "Text"], Cell[BoxData[ RowBox[{"Plot", "[", RowBox[{ RowBox[{"x", "^", "2"}], ",", RowBox[{"{", RowBox[{"x", ",", RowBox[{"-", "3"}], ",", "3"}], "}"}], ",", RowBox[{"AxesLabel", "\[Rule]", RowBox[{"{", RowBox[{"\"\\"", ",", "\"\\""}], "}"}]}]}], "]"}]], "Input"], Cell["All of these options can be used together!", "Text"], Cell[BoxData[ RowBox[{"Plot", "[", RowBox[{ RowBox[{"x", "^", "2"}], ",", RowBox[{"{", RowBox[{"x", ",", RowBox[{"-", "2"}], ",", "2"}], "}"}], ",", RowBox[{"PlotRange", "->", RowBox[{"{", RowBox[{ RowBox[{"-", "2"}], ",", "4"}], "}"}]}], ",", RowBox[{"PlotStyle", "\[Rule]", RowBox[{"RGBColor", "[", RowBox[{"0.1", ",", "0.6", ",", "0.7"}], "]"}]}], ",", RowBox[{"AxesLabel", "\[Rule]", RowBox[{"{", RowBox[{"\"\\"", ",", "\"\\""}], "}"}]}]}], "]"}]], "Input"], Cell[BoxData[ RowBox[{"Plot", "[", RowBox[{ RowBox[{"x", "^", "2"}], ",", RowBox[{"{", RowBox[{"x", ",", RowBox[{"-", "2"}], ",", "2"}], "}"}], ",", RowBox[{"PlotRange", "->", RowBox[{"{", RowBox[{ RowBox[{"-", "2"}], ",", "4"}], "}"}]}], ",", RowBox[{"PlotStyle", "\[Rule]", RowBox[{"RGBColor", "[", RowBox[{"0.1", ",", "0.6", ",", "0.7"}], "]"}]}], ",", RowBox[{"AxesLabel", "\[Rule]", RowBox[{"{", RowBox[{"\"\\"", ",", "\"\\""}], "}"}]}], ",", RowBox[{"Background", "\[Rule]", RowBox[{"RGBColor", "[", RowBox[{"0.1", ",", "0.9", ",", "0.9"}], "]"}]}]}], "]"}]], "Input"], Cell[TextData[{ "There are 2 ways to display more than one plot on a single graph. \nThe \ first is to enter several functions in curly brackets in the Plot command. \n\ The second is to store the different ", StyleBox["plots", FontSlant->"Italic"], " as variables, and then use the command Show[ ] to display them all. Both \ are demonstrated below." }], "Text"], Cell[BoxData[ RowBox[{ RowBox[{"f", "[", "x_", "]"}], "=", RowBox[{ RowBox[{"E", "^", RowBox[{"(", RowBox[{"-", "x"}], ")"}]}], "*", RowBox[{"Cos", "[", RowBox[{"8", "*", "x"}], "]"}]}]}]], "Input"], Cell[BoxData[ RowBox[{"p1", "=", RowBox[{"Plot", "[", RowBox[{ RowBox[{"f", "[", "x", "]"}], ",", RowBox[{"{", RowBox[{"x", ",", "0", ",", "6"}], "}"}], ",", RowBox[{"PlotRange", "\[Rule]", "All"}]}], "]"}]}]], "Input"], Cell[BoxData[ RowBox[{ RowBox[{"g", "[", "x_", "]"}], "=", RowBox[{"E", "^", RowBox[{"(", RowBox[{"-", "x"}], ")"}]}]}]], "Input"], Cell[BoxData[ RowBox[{"p2", "=", RowBox[{"Plot", "[", RowBox[{ RowBox[{"{", RowBox[{ RowBox[{"g", "[", "x", "]"}], ",", RowBox[{"-", RowBox[{"g", "[", "x", "]"}]}]}], "}"}], ",", RowBox[{"{", RowBox[{"x", ",", "0", ",", "6"}], "}"}], ",", RowBox[{"PlotStyle", "\[Rule]", RowBox[{"RGBColor", "[", RowBox[{"1", ",", "0", ",", "0"}], "]"}]}]}], "]"}]}]], "Input"], Cell[BoxData[ RowBox[{"Show", "[", RowBox[{"p1", ",", "p2"}], "]"}]], "Input"] }, WindowSize->{1272, 877}, WindowMargins->{{0, Automatic}, {Automatic, 0}}, ShowSelection->True, FrontEndVersion->"7.0 for Microsoft Windows (32-bit) (February 18, 2009)", StyleDefinitions->"DemoText.nb" ] (* End of Notebook Content *) (* Internal cache information *) (*CellTagsOutline CellTagsIndex->{} *) (*CellTagsIndex CellTagsIndex->{} *) (*NotebookFileOutline Notebook[{ Cell[545, 20, 50, 0, 56, "Title"], Cell[598, 22, 86, 1, 56, "Subsubtitle"], Cell[687, 25, 51, 0, 44, "Subsubsection"], Cell[741, 27, 209, 5, 25, "Text"], Cell[953, 34, 176, 6, 38, "Input"], Cell[1132, 42, 224, 8, 25, "Text"], Cell[1359, 52, 54, 1, 38, "Input"], Cell[1416, 55, 54, 1, 38, "Input"], Cell[1473, 58, 78, 2, 38, "Input"], Cell[1554, 62, 53, 0, 44, "Subsubsection"], Cell[1610, 64, 431, 19, 25, "Text"], Cell[2044, 85, 126, 4, 38, "Input"], Cell[2173, 91, 125, 4, 25, "Text"], Cell[2301, 97, 77, 2, 38, "Input"], Cell[2381, 101, 77, 2, 38, "Input"], Cell[2461, 105, 77, 2, 38, "Input"], Cell[2541, 109, 168, 3, 25, "Text"], Cell[2712, 114, 70, 0, 25, "Text"], Cell[2785, 116, 233, 7, 38, "Input"], Cell[3021, 125, 223, 10, 25, "Text"], Cell[3247, 137, 122, 3, 38, "Input"], Cell[3372, 142, 36, 0, 44, "Subsubsection"], Cell[3411, 144, 90, 2, 25, "Text"], Cell[3504, 148, 44, 1, 38, "Input"], Cell[3551, 151, 39, 0, 25, "Text"], Cell[3593, 153, 54, 1, 38, "Input"], Cell[3650, 156, 156, 5, 25, "Text"], Cell[3809, 163, 106, 3, 38, "Input"], Cell[3918, 168, 75, 0, 25, "Text"], Cell[3996, 170, 77, 2, 38, "Input"], Cell[4076, 174, 44, 0, 25, "Text"], Cell[4123, 176, 155, 5, 38, "Input"], Cell[4281, 183, 160, 5, 38, "Input"], Cell[4444, 190, 58, 0, 37, "Subtitle"], Cell[4505, 192, 236, 5, 55, "Text"], Cell[4744, 199, 160, 5, 38, "Input"], Cell[4907, 206, 211, 7, 38, "Input"], Cell[5121, 215, 78, 2, 38, "Input"], Cell[5202, 219, 78, 2, 38, "Input"], Cell[5283, 223, 50, 0, 25, "Text"], Cell[5336, 225, 106, 3, 38, "Input"], Cell[5445, 230, 155, 5, 38, "Input"], Cell[5603, 237, 34, 0, 44, "Subsubsection"], Cell[5640, 239, 47, 1, 38, "Input"], Cell[5690, 242, 184, 6, 38, "Input"], Cell[5877, 250, 93, 2, 25, "Text"], Cell[5973, 254, 168, 5, 38, "Input"], Cell[6144, 261, 263, 6, 25, "Text"], Cell[6410, 269, 300, 10, 38, "Input"], Cell[6713, 281, 171, 4, 25, "Text"], Cell[6887, 287, 234, 7, 38, "Input"], Cell[7124, 296, 304, 9, 25, "Text"], Cell[7431, 307, 305, 9, 38, "Input"], Cell[7739, 318, 305, 9, 38, "Input"], Cell[8047, 329, 334, 9, 25, "Text"], Cell[8384, 340, 264, 8, 38, "Input"], Cell[8651, 350, 223, 8, 25, "Text"], Cell[8877, 360, 303, 9, 38, "Input"], Cell[9183, 371, 58, 0, 25, "Text"], Cell[9244, 373, 546, 16, 38, "Input"], Cell[9793, 391, 674, 19, 38, "Input"], Cell[10470, 412, 370, 8, 85, "Text"], Cell[10843, 422, 227, 8, 38, "Input"], Cell[11073, 432, 247, 7, 38, "Input"], Cell[11323, 441, 145, 5, 38, "Input"], Cell[11471, 448, 428, 13, 38, "Input"], Cell[11902, 463, 82, 2, 38, "Input"] } ] *) (* End of internal cache information *)