(* 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[ 10181, 368] NotebookOptionsPosition[ 8948, 324] NotebookOutlinePosition[ 9337, 341] CellTagsIndexPosition[ 9294, 338] WindowFrame->Normal ContainsDynamic->False*) (* Beginning of Notebook Content *) Notebook[{ Cell[CellGroupData[{ Cell["Exercises (9)", "Title"], Cell["\<\ Assigned: March 26 (Extra Credit Only!) Due: April 2\ \>", "Subsubtitle", CellChangeTimes->{{3.447062071861902*^9, 3.4470620878015833`*^9}}], Cell[CellGroupData[{ Cell["Accuracy versus Mode Count", "Section"], Cell["Consider two functions,", "Text"], Cell[BoxData[{ RowBox[{ RowBox[{ RowBox[{"f1", "[", RowBox[{"x_", "/;", RowBox[{"0", "\[LessEqual]", "x", "\[LessEqual]", "1"}]}], "]"}], ":=", RowBox[{"1.5`", " ", "x", " ", RowBox[{"Sin", "[", RowBox[{"\[Pi]", " ", "x"}], "]"}]}]}], ";"}], "\n", RowBox[{ RowBox[{ RowBox[{"f2", "[", RowBox[{"x_", "/;", RowBox[{"0", "\[LessEqual]", "x", "\[LessEqual]", "1"}]}], "]"}], ":=", RowBox[{"If", "[", RowBox[{ RowBox[{"x", "<", "0.5`"}], ",", "1.`", ",", "0.`"}], "]"}]}], ";"}], "\n", RowBox[{"Plot", "[", RowBox[{ RowBox[{"{", RowBox[{ RowBox[{"f1", "[", "x", "]"}], ",", RowBox[{"f2", "[", "x", "]"}]}], "}"}], ",", RowBox[{"{", RowBox[{"x", ",", "0", ",", "1"}], "}"}]}], "]"}]}], "Input"], Cell[TextData[{ "Determine the accuracy of a Fourier expansion of these two functions as the \ number of terms in the series increases. A convenient measure of the \ \"accuracy\" is the integral of the mean-square-difference between the exact \ function and the Fourier series. Use ", StyleBox["NIntegrate[\[Ellipsis]]", FontWeight->"Bold"], " to find this integral." }], "Text"], Cell[TextData[{ "For these functions, use ", StyleBox["both", FontSlant->"Italic"], " Sine and Cosine functions. However, you will find most of the Cosine \ coefficients will equal zero. For example, write:\n\tf[x] \[TildeTilde] ", Cell[BoxData[ FormBox[ RowBox[{ UnderoverscriptBox["\[Sum]", RowBox[{"n", "=", "0"}], "N"], RowBox[{ SubscriptBox["a", "n"], " ", RowBox[{"Cos", "[", RowBox[{"2", " ", "\[Pi]", " ", "n", " ", "x"}], "]"}]}]}], TraditionalForm]]], " + ", Cell[BoxData[ FormBox[ RowBox[{ UnderoverscriptBox["\[Sum]", RowBox[{"n", "=", "1"}], "N"], RowBox[{ SubscriptBox["b", "n"], " ", RowBox[{"Sin", "[", RowBox[{"2", "\[Pi]", " ", "n", " ", "x"}], "]"}]}]}], TraditionalForm]]], "\nYou will want to examine values of ", StyleBox["N", FontSlant->"Italic"], " at least as large as 15. With this definition, y", "our problem to solve is to compare the approximte expansion to the actual \ function. Create a ", StyleBox["ListPlot[\[Ellipsis]]", FontWeight->"Bold"], " of mean-square difference as ", StyleBox["N", FontSlant->"Italic"], " increases." }], "Text"], Cell[CellGroupData[{ Cell["Hint", "Subsubsection"], Cell[TextData[{ "Define functions called ", StyleBox["getCosMode[f][n]", FontWeight->"Bold"], " and ", StyleBox["getSinMode[f][n]", FontWeight->"Bold"], ". These were defined in class." }], "Text"], Cell[BoxData[ RowBox[{ RowBox[{ RowBox[{"getCosMode", "[", "f_", "]"}], "[", "n_Integer", "]"}], " ", ":=", " ", RowBox[{ RowBox[{"If", "[", RowBox[{ RowBox[{"n", " ", ">", " ", "0"}], ",", " ", "2", ",", " ", "1"}], "]"}], RowBox[{"Integrate", "[", RowBox[{ RowBox[{ RowBox[{"f", "[", "x", "]"}], " ", RowBox[{"Cos", "[", RowBox[{"2", " ", "\[Pi]", " ", "x", " ", "n"}], "]"}]}], ",", " ", RowBox[{"{", RowBox[{"x", ",", " ", "0", ",", " ", "1"}], "}"}]}], "]"}], " "}]}]], "Input"], Cell[BoxData[ RowBox[{ RowBox[{ RowBox[{"getSinMode", "[", "f_", "]"}], "[", "n_Integer", "]"}], " ", ":=", " ", RowBox[{"2", " ", RowBox[{"Integrate", "[", RowBox[{ RowBox[{ RowBox[{"f", "[", "x", "]"}], " ", RowBox[{"Sin", "[", RowBox[{"2", " ", "\[Pi]", " ", "x", " ", "n"}], "]"}]}], ",", " ", RowBox[{"{", RowBox[{"x", ",", " ", "0", ",", " ", "1"}], "}"}]}], "]"}], " "}]}]], "Input"], Cell["\<\ Then, use these functions to define your approximate function (as done in \ class\[Ellipsis]).\ \>", "Text"] }, Closed]] }, Closed]], Cell[CellGroupData[{ Cell["ChebyshevT", "Section"], Cell["\<\ The Chebyshev polynomial of the first kind is another orthogonal function \ that can be used to expand a function.\ \>", "Text"], Cell[TextData[{ "Chebyshev functions are normalized by integrating from ", StyleBox["x", FontSlant->"Italic"], " = -1", StyleBox[" ", FontSlant->"Italic"], "to ", StyleBox["x", FontSlant->"Italic"], " = +1 and by dividing by Sqrt[1 - ", Cell[BoxData[ FormBox[ SuperscriptBox["x", "2"], TraditionalForm]]], "]. For example," }], "Text"], Cell[BoxData[ RowBox[{"{", RowBox[{ RowBox[{"ChebyshevT", "[", RowBox[{"0", ",", "x"}], "]"}], ",", RowBox[{"ChebyshevT", "[", RowBox[{"2", ",", "x"}], "]"}], ",", " ", RowBox[{"ChebyshevT", "[", RowBox[{"5", ",", "x"}], "]"}]}], "}"}]], "Input"], Cell[BoxData[ RowBox[{"Plot", "[", RowBox[{ RowBox[{"Evaluate", "[", RowBox[{"Table", "[", RowBox[{ RowBox[{"ChebyshevT", "[", RowBox[{"n", ",", "x"}], "]"}], ",", RowBox[{"{", RowBox[{"n", ",", "0", ",", "5"}], "}"}]}], "]"}], "]"}], ",", RowBox[{"{", RowBox[{"x", ",", RowBox[{"-", "1"}], ",", "1"}], "}"}], ",", RowBox[{"PlotStyle", "\[Rule]", RowBox[{"Table", "[", RowBox[{ RowBox[{"{", RowBox[{"Hue", "[", FractionBox["i", "5"], "]"}], "}"}], ",", RowBox[{"{", RowBox[{"i", ",", "0", ",", "5"}], "}"}]}], "]"}]}]}], "]"}]], "Input"], Cell["They are orthogonal\[Ellipsis]", "Text"], Cell[BoxData[ RowBox[{"Integrate", "[", RowBox[{ RowBox[{ RowBox[{"ChebyshevT", "[", RowBox[{"2", ",", "x"}], "]"}], " ", RowBox[{ RowBox[{"ChebyshevT", "[", RowBox[{"5", ",", "x"}], "]"}], " ", "/", RowBox[{"Sqrt", "[", RowBox[{"1", " ", "-", " ", SuperscriptBox["x", "2"]}], "]"}]}]}], ",", " ", RowBox[{"{", RowBox[{"x", ",", " ", RowBox[{"-", "1"}], ",", " ", "1"}], "}"}]}], "]"}]], "Input"], Cell[BoxData[ RowBox[{"Table", "[", RowBox[{ RowBox[{"Integrate", "[", RowBox[{ RowBox[{ RowBox[{"ChebyshevT", "[", RowBox[{"n", ",", "x"}], "]"}], " ", RowBox[{ RowBox[{"ChebyshevT", "[", RowBox[{"n", ",", "x"}], "]"}], " ", "/", RowBox[{"Sqrt", "[", RowBox[{"1", " ", "-", " ", SuperscriptBox["x", "2"]}], "]"}]}]}], ",", " ", RowBox[{"{", RowBox[{"x", ",", " ", RowBox[{"-", "1"}], ",", " ", "1"}], "}"}]}], "]"}], ",", " ", RowBox[{"{", RowBox[{"n", ",", " ", "0", ",", " ", "5"}], "}"}]}], "]"}]], "Input"], Cell[TextData[{ "In this problem, examine the accuracy of representing the following \ functions by a series of Chebyshev functions. (", StyleBox["Hint: ", FontSlant->"Italic"], "follow a similar procedure as used in the previous problem. Please note, \ however, that you may have to use ", StyleBox["NIntegrate[\[Ellipsis]]", FontWeight->"Bold"], " instead of ", StyleBox["Integrate[\[Ellipsis]] ", FontWeight->"Bold"], "since ", StyleBox["Mathematica", FontSlant->"Italic"], " may not be able to integrate your functions in closed form.)" }], "Text"], Cell[BoxData[{ RowBox[{ RowBox[{ RowBox[{"fc1", "[", RowBox[{"x_", "/;", RowBox[{ RowBox[{"-", "1"}], "\[LessEqual]", "x", "\[LessEqual]", "x"}]}], "]"}], ":=", RowBox[{"0.2`", "\[InvisibleSpace]", "+", RowBox[{"1.5`", " ", "x", " ", SuperscriptBox[ RowBox[{"Cos", "[", RowBox[{"5", " ", "x"}], "]"}], "2"]}]}]}], ";"}], "\n", RowBox[{ RowBox[{ RowBox[{"fc2", "[", RowBox[{"x_", "/;", RowBox[{ RowBox[{"-", "1"}], "\[LessEqual]", "x", "\[LessEqual]", "x"}]}], "]"}], ":=", RowBox[{"If", "[", RowBox[{ RowBox[{ RowBox[{"Abs", "[", "x", "]"}], "\[LessEqual]", "0.5`"}], ",", "1.`", ",", "x"}], "]"}]}], ";"}], "\n", RowBox[{"Plot", "[", RowBox[{ RowBox[{"{", RowBox[{ RowBox[{"fc1", "[", "x", "]"}], ",", RowBox[{"fc2", "[", "x", "]"}]}], "}"}], ",", RowBox[{"{", RowBox[{"x", ",", RowBox[{"-", "1"}], ",", "1"}], "}"}], ",", RowBox[{"PlotRange", "\[Rule]", "All"}]}], "]"}]}], "Input"] }, Closed]] }, Open ]] }, WindowSize->{652, 775}, WindowMargins->{{120, Automatic}, {Automatic, 0}}, PrintingCopies->1, PrintingPageRange->{1, Automatic}, FrontEndVersion->"6.0 for Mac OS X x86 (32-bit) (May 21, 2008)", StyleDefinitions->"Default.nb" ] (* End of Notebook Content *) (* Internal cache information *) (*CellTagsOutline CellTagsIndex->{} *) (*CellTagsIndex CellTagsIndex->{} *) (*NotebookFileOutline Notebook[{ Cell[CellGroupData[{ Cell[590, 23, 30, 0, 73, "Title"], Cell[623, 25, 151, 4, 45, "Subsubtitle"], Cell[CellGroupData[{ Cell[799, 33, 45, 0, 69, "Section"], Cell[847, 35, 39, 0, 27, "Text"], Cell[889, 37, 788, 25, 63, "Input"], Cell[1680, 64, 384, 8, 59, "Text"], Cell[2067, 74, 1179, 39, 114, "Text"], Cell[CellGroupData[{ Cell[3271, 117, 29, 0, 24, "Subsubsection"], Cell[3303, 119, 206, 8, 27, "Text"], Cell[3512, 129, 564, 18, 46, "Input"], Cell[4079, 149, 454, 14, 28, "Input"], Cell[4536, 165, 118, 3, 27, "Text"] }, Closed]] }, Closed]], Cell[CellGroupData[{ Cell[4703, 174, 29, 0, 39, "Section"], Cell[4735, 176, 138, 3, 43, "Text"], Cell[4876, 181, 355, 15, 46, "Text"], Cell[5234, 198, 276, 8, 28, "Input"], Cell[5513, 208, 652, 20, 71, "Input"], Cell[6168, 230, 46, 0, 27, "Text"], Cell[6217, 232, 466, 14, 33, "Input"], Cell[6686, 248, 622, 18, 53, "Input"], Cell[7311, 268, 569, 16, 75, "Text"], Cell[7883, 286, 1037, 34, 65, "Input"] }, Closed]] }, Open ]] } ] *) (* End of internal cache information *)