(*CacheID: 234*) (* Internal cache information: NotebookFileLineBreakTest NotebookFileLineBreakTest NotebookDataPosition[ 145, 0] NotebookDataLength[ 11772, 414] NotebookOptionsPosition[ 10229, 350] NotebookOutlinePosition[ 10605, 367] CellTagsIndexPosition[ 10562, 364] WindowFrame->Normal ContainsDynamic->False*) (* Beginning of Notebook Content *) Notebook[{ Cell[CellGroupData[{ Cell["Lesson 8 Answers - Functions", "Section", CellChangeTimes->{ 3.461093745181218*^9, {3.4612690405979643`*^9, 3.4612690487395773`*^9}, { 3.465130370741621*^9, 3.465130371658765*^9}}], Cell[TextData[{ "1) Define a function ", StyleBox["map[f_,L_]", "Input"], " that takes a list ", StyleBox["L", "Input"], " and makes a new list by applying the function ", StyleBox["f", "Input"], " to each entry in ", StyleBox["L", "Input"], ". For example, ", StyleBox["map[Sin,{a,b,c}]", "Input"], " should produce ", StyleBox["{Sin[a],Sin[b],Sin[c]}", "Input"], ". (There is a built-in function ", StyleBox["Map", "Input"], " that does this.)" }], "Text", CellChangeTimes->{{3.461180917728215*^9, 3.461180927417214*^9}, { 3.461181008295596*^9, 3.46118119603622*^9}}], Cell[BoxData[ RowBox[{ RowBox[{"map", "[", RowBox[{"f_", ",", "L_"}], "]"}], ":=", RowBox[{"Table", "[", RowBox[{ RowBox[{"f", "[", "i", "]"}], ",", RowBox[{"{", RowBox[{"i", ",", "L"}], "}"}]}], "]"}]}]], "Input", CellChangeTimes->{{3.46118120496436*^9, 3.461181237080117*^9}}, FontSlant->"Italic"], Cell[CellGroupData[{ Cell[BoxData[ RowBox[{"map", "[", RowBox[{"Sin", ",", RowBox[{"{", RowBox[{"a", ",", "b", ",", "c"}], "}"}]}], "]"}]], "Input", CellChangeTimes->{{3.461181296372096*^9, 3.461181305938138*^9}}, FontSlant->"Italic"], Cell[BoxData[ RowBox[{"{", RowBox[{ RowBox[{"Sin", "[", "a", "]"}], ",", RowBox[{"Sin", "[", "b", "]"}], ",", RowBox[{"Sin", "[", "c", "]"}]}], "}"}]], "Output", CellChangeTimes->{3.461181307263595*^9}, FontSlant->"Italic"] }, Open ]], Cell[CellGroupData[{ Cell[BoxData[ RowBox[{"map", "[", RowBox[{"g", ",", RowBox[{"Range", "[", "20", "]"}]}], "]"}]], "Input", CellChangeTimes->{{3.461181243712187*^9, 3.4611812907438707`*^9}}, FontSlant->"Italic"], Cell[BoxData[ RowBox[{"{", RowBox[{ RowBox[{"g", "[", "1", "]"}], ",", RowBox[{"g", "[", "2", "]"}], ",", RowBox[{"g", "[", "3", "]"}], ",", RowBox[{"g", "[", "4", "]"}], ",", RowBox[{"g", "[", "5", "]"}], ",", RowBox[{"g", "[", "6", "]"}], ",", RowBox[{"g", "[", "7", "]"}], ",", RowBox[{"g", "[", "8", "]"}], ",", RowBox[{"g", "[", "9", "]"}], ",", RowBox[{"g", "[", "10", "]"}], ",", RowBox[{"g", "[", "11", "]"}], ",", RowBox[{"g", "[", "12", "]"}], ",", RowBox[{"g", "[", "13", "]"}], ",", RowBox[{"g", "[", "14", "]"}], ",", RowBox[{"g", "[", "15", "]"}], ",", RowBox[{"g", "[", "16", "]"}], ",", RowBox[{"g", "[", "17", "]"}], ",", RowBox[{"g", "[", "18", "]"}], ",", RowBox[{"g", "[", "19", "]"}], ",", RowBox[{"g", "[", "20", "]"}]}], "}"}]], "Output", CellChangeTimes->{{3.461181253842043*^9, 3.46118129205886*^9}}, FontSlant->"Italic"] }, Open ]], Cell[TextData[{ "2) Define a function ", StyleBox["dot[u_,v_]", "Input"], " that takes two vectors ", StyleBox["u", "Input"], " and ", StyleBox["v", "Input"], " in ", Cell[BoxData[ FormBox[ SuperscriptBox["R", "n"], TraditionalForm]]], "(where ", StyleBox["n", FontSlant->"Italic"], " is unknown in advance) and calculates their dot product. For example, ", StyleBox["dot[{a,b},{3,4}]", "Input"], " produces ", StyleBox["3a+4b", "Input"], "; and ", StyleBox["dot[{1,2,3},{3,2,1}]", "Input"], " produces ", StyleBox["10", "Input"], ". " }], "Text", CellChangeTimes->{{3.461182697639451*^9, 3.461182699911315*^9}, { 3.461182855310939*^9, 3.461183020286942*^9}, {3.4611832503545847`*^9, 3.461183289932178*^9}, {3.461185199896802*^9, 3.461185214594425*^9}}], Cell[BoxData[ RowBox[{ RowBox[{"dot", "[", RowBox[{"u_", ",", "v_"}], "]"}], ":=", RowBox[{"Total", "[", RowBox[{"u", " ", "v"}], "]"}]}]], "Input", CellChangeTimes->{{3.461183054165452*^9, 3.461183082612615*^9}}, FontSlant->"Italic"], Cell[CellGroupData[{ Cell[BoxData[ StyleBox[ RowBox[{"dot", "[", RowBox[{ RowBox[{"{", RowBox[{"a", ",", "b"}], "}"}], ",", RowBox[{"{", RowBox[{"3", ",", "4"}], "}"}]}], "]"}], "Input"]], "Input", FontSlant->"Italic"], Cell[BoxData[ RowBox[{ RowBox[{"3", " ", "a"}], "+", RowBox[{"4", " ", "b"}]}]], "Output", CellChangeTimes->{3.461183097924926*^9}, FontSlant->"Italic"] }, Open ]], Cell[CellGroupData[{ Cell[BoxData[ StyleBox[ RowBox[{"dot", "[", RowBox[{ RowBox[{"{", RowBox[{"1", ",", "2", ",", "3"}], "}"}], ",", RowBox[{"{", RowBox[{"3", ",", "2", ",", "1"}], "}"}]}], "]"}], "Input"]], "Input", FontSlant->"Italic"], Cell[BoxData["10"], "Output", CellChangeTimes->{3.4611831216523848`*^9}, FontSlant->"Italic"] }, Open ]], Cell["Here's another, not so slick, definition.", "Text", CellChangeTimes->{{3.461183130002656*^9, 3.461183155222937*^9}}, FontSlant->"Italic"], Cell[BoxData[ RowBox[{ RowBox[{"dot", "[", RowBox[{"u_", ",", "v_"}], "]"}], ":=", RowBox[{"Sum", "[", RowBox[{ RowBox[{ RowBox[{"u", "[", RowBox[{"[", "i", "]"}], "]"}], "*", " ", RowBox[{"v", "[", RowBox[{"[", "i", "]"}], "]"}]}], ",", RowBox[{"{", RowBox[{"i", ",", RowBox[{"Length", "[", "u", "]"}]}], "}"}]}], "]"}]}]], "Input", CellChangeTimes->{{3.46118316917621*^9, 3.4611831955409193`*^9}}, FontSlant->"Italic"], Cell[TextData[{ "3) Define a function ", StyleBox["onesmatrix[n_]", "Input"], " that produces a ", StyleBox["n\[Cross]n", "Input"], " matrix whose entries are all ", StyleBox["1", "Input"], "." }], "Text", CellChangeTimes->{{3.461185638012127*^9, 3.461185735359503*^9}, 3.461185819672477*^9}], Cell[BoxData[ RowBox[{ RowBox[{"onesmatrix", "[", "n_", "]"}], ":=", RowBox[{"Table", "[", RowBox[{"1", ",", RowBox[{"{", "n", "}"}], ",", RowBox[{"{", "n", "}"}]}], "]"}]}]], "Input", CellChangeTimes->{{3.4611857413049927`*^9, 3.4611857704342117`*^9}}, FontSlant->"Italic"], Cell[CellGroupData[{ Cell[BoxData[ RowBox[{"onesmatrix", "[", "5", "]"}]], "Input", CellChangeTimes->{{3.461185773877771*^9, 3.4611857883258333`*^9}}, FontSlant->"Italic"], Cell[BoxData[ RowBox[{"{", RowBox[{ RowBox[{"{", RowBox[{"1", ",", "1", ",", "1", ",", "1", ",", "1"}], "}"}], ",", RowBox[{"{", RowBox[{"1", ",", "1", ",", "1", ",", "1", ",", "1"}], "}"}], ",", RowBox[{"{", RowBox[{"1", ",", "1", ",", "1", ",", "1", ",", "1"}], "}"}], ",", RowBox[{"{", RowBox[{"1", ",", "1", ",", "1", ",", "1", ",", "1"}], "}"}], ",", RowBox[{"{", RowBox[{"1", ",", "1", ",", "1", ",", "1", ",", "1"}], "}"}]}], "}"}]], "Output", CellChangeTimes->{{3.46118577911456*^9, 3.461185788844728*^9}}, FontSlant->"Italic"] }, Open ]], Cell[TextData[{ "4) Define a function ", StyleBox["trace[M_]", "Input"], " that calculates the trace of the square matrix ", StyleBox["M", "Input"], ". (The trace is the sum of the diagonal entries of a matrix. There is a \ built-in function that calculates the trace of matrices.)" }], "Text", CellChangeTimes->{{3.461255492201222*^9, 3.4612554935720243`*^9}, { 3.4612555687975807`*^9, 3.46125558991936*^9}, {3.4612558097909517`*^9, 3.461255867391037*^9}, {3.4612560072218933`*^9, 3.461256043214151*^9}}], Cell[BoxData[ RowBox[{ RowBox[{"trace", "[", "M_", "]"}], ":=", RowBox[{"Sum", "[", RowBox[{ RowBox[{"M", "[", RowBox[{"[", RowBox[{"i", ",", "i"}], "]"}], "]"}], ",", RowBox[{"{", RowBox[{"i", ",", RowBox[{"Length", "[", "M", "]"}]}], "}"}]}], "]"}]}]], "Input", CellChangeTimes->{{3.46125587071026*^9, 3.4612558976894503`*^9}}, FontSlant->"Italic"], Cell[CellGroupData[{ Cell[BoxData[ RowBox[{"trace", "[", RowBox[{"{", RowBox[{ RowBox[{"{", RowBox[{"a", ",", "b"}], "}"}], ",", RowBox[{"{", RowBox[{"c", ",", "d"}], "}"}]}], "}"}], "]"}]], "Input", CellChangeTimes->{{3.4612559073825502`*^9, 3.461255919798473*^9}}, FontSlant->"Italic"], Cell[BoxData[ RowBox[{"a", "+", "d"}]], "Output", CellChangeTimes->{3.4612559207224293`*^9}, FontSlant->"Italic"] }, Open ]], Cell[TextData[{ "5) Define a function ", StyleBox["extrema[f_]", "Input"], " that makes a list of the coordinates of the local extrema (maximum or \ minimum) of the polynomial ", StyleBox["f", "Input"], ". Decimal approximations suffice. Note that ", StyleBox["NSolve[f]", "Input"], " gives a list of replacement rules for the x-coordinates of these points, \ but ", StyleBox["extrema[f_]", "Input"], " should produce a list of the x- and y-coordinates of these points. Here's \ an example:" }], "Text", CellChangeTimes->{{3.4620323713294687`*^9, 3.462032571981763*^9}, { 3.462032689875082*^9, 3.46203272198337*^9}}], Cell[BoxData[ RowBox[{ RowBox[{"extrema", "[", "f_", "]"}], ":=", RowBox[{ RowBox[{"{", RowBox[{"x", ",", "f"}], "}"}], "/.", RowBox[{"NSolve", "[", RowBox[{ RowBox[{ RowBox[{"D", "[", RowBox[{"f", ",", "x"}], "]"}], "\[Equal]", "0"}], ",", "x"}], "]"}]}]}]], "Input", CellChangeTimes->{{3.462032584787505*^9, 3.462032613306377*^9}}, FontSlant->"Italic"], Cell[CellGroupData[{ Cell[BoxData[ RowBox[{"extrema", "[", RowBox[{ RowBox[{"x", "^", "3"}], "-", "x"}], "]"}]], "Input", CellChangeTimes->{{3.462032620134547*^9, 3.462032628496875*^9}}], Cell[BoxData[ RowBox[{"{", RowBox[{ RowBox[{"{", RowBox[{ RowBox[{"-", "0.5773502691896257`"}], ",", "0.3849001794597505`"}], "}"}], ",", RowBox[{"{", RowBox[{"0.5773502691896257`", ",", RowBox[{"-", "0.3849001794597505`"}]}], "}"}]}], "}"}]], "Output", CellChangeTimes->{3.462032629517004*^9}] }, Open ]] }, Open ]] }, WindowSize->{819, 716}, WindowMargins->{{85, Automatic}, {Automatic, 0}}, ShowSelection->True, Magnification->1., FrontEndVersion->"6.0 for Mac OS X x86 (32-bit) (April 20, 2007)", StyleDefinitions->"Default.nb" ] (* End of Notebook Content *) (* Internal cache information *) (*CellTagsOutline CellTagsIndex->{} *) (*CellTagsIndex CellTagsIndex->{} *) (*NotebookFileOutline Notebook[{ Cell[CellGroupData[{ Cell[590, 16, 193, 3, 67, "Section"], Cell[786, 21, 587, 18, 41, "Text"], Cell[1376, 41, 330, 10, 27, "Input"], Cell[CellGroupData[{ Cell[1731, 55, 228, 6, 27, "Input"], Cell[1962, 63, 240, 7, 27, "Output"] }, Open ]], Cell[CellGroupData[{ Cell[2239, 75, 203, 5, 27, "Input"], Cell[2445, 82, 931, 24, 43, "Output"] }, Open ]], Cell[3391, 109, 785, 26, 41, "Text"], Cell[4179, 137, 250, 7, 27, "Input"], Cell[CellGroupData[{ Cell[4454, 148, 226, 8, 27, "Input"], Cell[4683, 158, 160, 5, 27, "Output"] }, Open ]], Cell[CellGroupData[{ Cell[4880, 168, 246, 8, 27, "Input"], Cell[5129, 178, 95, 2, 27, "Output"] }, Open ]], Cell[5239, 183, 145, 2, 26, "Text"], Cell[5387, 187, 483, 15, 27, "Input"], Cell[5873, 204, 305, 10, 26, "Text"], Cell[6181, 216, 296, 8, 27, "Input"], Cell[CellGroupData[{ Cell[6502, 228, 153, 3, 27, "Input"], Cell[6658, 233, 588, 15, 27, "Output"] }, Open ]], Cell[7261, 251, 516, 10, 41, "Text"], Cell[7780, 263, 397, 12, 27, "Input"], Cell[CellGroupData[{ Cell[8202, 279, 297, 9, 27, "Input"], Cell[8502, 290, 116, 3, 27, "Output"] }, Open ]], Cell[8633, 296, 629, 15, 56, "Text"], Cell[9265, 313, 403, 13, 27, "Input"], Cell[CellGroupData[{ Cell[9693, 330, 173, 4, 27, "Input"], Cell[9869, 336, 332, 10, 27, "Output"] }, Open ]] }, Open ]] } ] *)