(* 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[ 27966, 962] NotebookOptionsPosition[ 25232, 878] NotebookOutlinePosition[ 25621, 895] CellTagsIndexPosition[ 25578, 892] WindowFrame->Normal ContainsDynamic->False*) (* Beginning of Notebook Content *) Notebook[{ Cell[CellGroupData[{ Cell["Solutions (9)", "Title"], Cell["\<\ Assigned: March 26 (Extra Credit Only!) Due: April 2\ \>", "Subsubtitle", CellChangeTimes->{{3.447062071861902*^9, 3.4470620878015833`*^9}}], Cell[TextData[{ "Below, I turn off some warnings. These can signal errors in ", StyleBox["Mathematica", FontSlant->"Italic"], "'s computations, but, for our purposes, they are not significant in this \ assignment." }], "Text"], Cell[BoxData[ RowBox[{ RowBox[{ RowBox[{ RowBox[{"Off", "[", RowBox[{"General", "::", "\"\\""}], "]"}], ";"}], " ", RowBox[{"(*", " ", RowBox[{"Avoid", " ", "spelling", " ", "warnings"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"Off", "[", RowBox[{"NIntegrate", "::", "\"\\""}], "]"}], ";"}], " ", RowBox[{"(*", " ", RowBox[{ "Avoid", " ", "loss", " ", "of", " ", "accuracy", " ", "warnings"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"Off", "[", RowBox[{"NIntegrate", "::", "\"\\""}], "]"}], ";"}]}], " ", RowBox[{"(*", " ", RowBox[{ "Avoid", " ", "failed", " ", "to", " ", "converge", " ", "warnings"}], " ", "*)"}]}]], "Input"], 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]], Cell[CellGroupData[{ Cell["Solution", "Subsubsection"], Cell[BoxData[ RowBox[{ RowBox[{"nModes", " ", "=", " ", "25"}], ";"}]], "Input"], Cell[TextData[StyleBox["Function 1\[Ellipsis]", FontWeight->"Bold"]], "Text", FontColor->RGBColor[0, 1, 0]], Cell[BoxData[ RowBox[{ RowBox[{"Do", "[", RowBox[{ RowBox[{ RowBox[{"f1a", "[", "n", "]"}], " ", "=", " ", RowBox[{"N", "[", RowBox[{ RowBox[{"getCosMode", "[", "f1", "]"}], "[", "n", "]"}], "]"}]}], ",", " ", RowBox[{"{", RowBox[{"n", ",", " ", "0", ",", " ", "nModes"}], "}"}]}], "]"}], ";"}]], "Input"], Cell[BoxData[ RowBox[{ RowBox[{"Do", "[", RowBox[{ RowBox[{ RowBox[{"f1b", "[", "n", "]"}], " ", "=", " ", RowBox[{"N", "[", RowBox[{ RowBox[{"getSinMode", "[", "f1", "]"}], "[", "n", "]"}], "]"}]}], ",", " ", RowBox[{"{", RowBox[{"n", ",", " ", "1", ",", " ", "nModes"}], "}"}]}], "]"}], ";"}]], "Input"], Cell[BoxData[ RowBox[{ RowBox[{ RowBox[{"f1Fourier", "[", "n_Integer", "]"}], "[", "x_", "]"}], " ", ":=", " ", RowBox[{ RowBox[{"Sum", "[", RowBox[{ RowBox[{ RowBox[{"f1a", "[", "i", "]"}], " ", RowBox[{"Cos", "[", RowBox[{"2", " ", "\[Pi]", " ", "i", " ", "x"}], "]"}]}], ",", " ", RowBox[{"{", RowBox[{"i", ",", " ", "0", ",", " ", "n"}], "}"}]}], "]"}], " ", "+", " ", RowBox[{"Sum", "[", RowBox[{ RowBox[{ RowBox[{"f1b", "[", "i", "]"}], " ", RowBox[{"Sin", "[", RowBox[{"2", " ", "\[Pi]", " ", "i", " ", "x"}], "]"}]}], ",", " ", RowBox[{"{", RowBox[{"i", ",", " ", "1", ",", " ", "n"}], "}"}]}], "]"}]}]}]], "Input"], Cell[BoxData[ RowBox[{"Plot", "[", RowBox[{ RowBox[{"{", RowBox[{ RowBox[{"f1", "[", "x", "]"}], ",", RowBox[{ RowBox[{"f1Fourier", "[", "3", "]"}], "[", "x", "]"}], ",", RowBox[{ RowBox[{"f1Fourier", "[", "5", "]"}], "[", "x", "]"}], ",", RowBox[{ RowBox[{"f1Fourier", "[", "nModes", "]"}], "[", "x", "]"}]}], "}"}], ",", RowBox[{"{", RowBox[{"x", ",", "0", ",", "1"}], "}"}], ",", RowBox[{"PlotStyle", "\[Rule]", RowBox[{"{", RowBox[{ RowBox[{"{", RowBox[{"Thickness", "[", "0.01`", "]"}], "}"}], ",", RowBox[{"{", RowBox[{"Hue", "[", FractionBox["1", "5"], "]"}], "}"}], ",", RowBox[{"{", RowBox[{"Hue", "[", FractionBox["2", "5"], "]"}], "}"}], ",", RowBox[{"{", RowBox[{"Hue", "[", FractionBox["3", "5"], "]"}], "}"}], ",", RowBox[{"{", RowBox[{"Hue", "[", FractionBox["4", "5"], "]"}], "}"}]}], "}"}]}], ",", RowBox[{"PlotLabel", "\[Rule]", "\"\\""}]}], "]"}]], "Input"], Cell[TextData[StyleBox["Function 2\[Ellipsis]", FontWeight->"Bold"]], "Text", FontColor->RGBColor[0, 1, 0]], Cell[BoxData[ RowBox[{ RowBox[{"Do", "[", RowBox[{ RowBox[{ RowBox[{"f2a", "[", "n", "]"}], " ", "=", " ", RowBox[{"N", "[", RowBox[{ RowBox[{"getCosMode", "[", "f2", "]"}], "[", "n", "]"}], "]"}]}], ",", " ", RowBox[{"{", RowBox[{"n", ",", " ", "0", ",", " ", "nModes"}], "}"}]}], "]"}], ";"}]], "Input"], Cell[BoxData[ RowBox[{ RowBox[{"Do", "[", RowBox[{ RowBox[{ RowBox[{"f2b", "[", "n", "]"}], " ", "=", " ", RowBox[{"N", "[", RowBox[{ RowBox[{"getSinMode", "[", "f2", "]"}], "[", "n", "]"}], "]"}]}], ",", " ", RowBox[{"{", RowBox[{"n", ",", " ", "1", ",", " ", "nModes"}], "}"}]}], "]"}], ";"}]], "Input"], Cell[BoxData[ RowBox[{ RowBox[{ RowBox[{"f2Fourier", "[", "n_Integer", "]"}], "[", "x_", "]"}], " ", ":=", " ", RowBox[{ RowBox[{"Sum", "[", RowBox[{ RowBox[{ RowBox[{"f2a", "[", "i", "]"}], " ", RowBox[{"Cos", "[", RowBox[{"2", " ", "\[Pi]", " ", "i", " ", "x"}], "]"}]}], ",", " ", RowBox[{"{", RowBox[{"i", ",", " ", "0", ",", " ", "n"}], "}"}]}], "]"}], " ", "+", " ", RowBox[{"Sum", "[", RowBox[{ RowBox[{ RowBox[{"f2b", "[", "i", "]"}], " ", RowBox[{"Sin", "[", RowBox[{"2", " ", "\[Pi]", " ", "i", " ", "x"}], "]"}]}], ",", " ", RowBox[{"{", RowBox[{"i", ",", " ", "1", ",", " ", "n"}], "}"}]}], "]"}]}]}]], "Input"], Cell[BoxData[ RowBox[{"Plot", "[", RowBox[{ RowBox[{"{", RowBox[{ RowBox[{"f2", "[", "x", "]"}], ",", RowBox[{ RowBox[{"f2Fourier", "[", "3", "]"}], "[", "x", "]"}], ",", RowBox[{ RowBox[{"f2Fourier", "[", "5", "]"}], "[", "x", "]"}], ",", RowBox[{ RowBox[{"f2Fourier", "[", "nModes", "]"}], "[", "x", "]"}]}], "}"}], ",", RowBox[{"{", RowBox[{"x", ",", "0", ",", "1"}], "}"}], ",", RowBox[{"PlotStyle", "\[Rule]", RowBox[{"{", RowBox[{ RowBox[{"{", RowBox[{"Thickness", "[", "0.01`", "]"}], "}"}], ",", RowBox[{"{", RowBox[{"Hue", "[", FractionBox["1", "5"], "]"}], "}"}], ",", RowBox[{"{", RowBox[{"Hue", "[", FractionBox["2", "5"], "]"}], "}"}], ",", RowBox[{"{", RowBox[{"Hue", "[", FractionBox["3", "5"], "]"}], "}"}], ",", RowBox[{"{", RowBox[{"Hue", "[", FractionBox["4", "5"], "]"}], "}"}]}], "}"}]}], ",", RowBox[{"PlotLabel", "\[Rule]", "\"\\""}]}], "]"}]], "Input"], Cell["\<\ Finding the mean square difference\[Ellipsis]\ \>", "Text", FontWeight->"Bold", FontColor->RGBColor[0, 1, 0]], Cell[BoxData[ RowBox[{ RowBox[{"meanError1", "[", "n_Integer", "]"}], " ", ":=", " ", RowBox[{"NIntegrate", "[", RowBox[{ RowBox[{ RowBox[{"(", RowBox[{ RowBox[{"f1", "[", "x", "]"}], " ", "-", " ", RowBox[{ RowBox[{"f1Fourier", "[", "n", "]"}], "[", "x", "]"}]}], ")"}], "^", "2"}], ",", " ", RowBox[{"{", RowBox[{"x", ",", " ", "0", ",", " ", "1"}], "}"}]}], "]"}]}]], "Input"], Cell[BoxData[ RowBox[{ RowBox[{"f1Error", " ", "=", " ", RowBox[{"Table", "[", RowBox[{ RowBox[{"meanError1", "[", "n", "]"}], ",", " ", RowBox[{"{", RowBox[{"n", ",", " ", "1", ",", " ", "nModes"}], "}"}]}], "]"}]}], ";"}]], "Input"], Cell[BoxData[ RowBox[{"ListPlot", "[", RowBox[{"f1Error", ",", RowBox[{"PlotRange", "\[Rule]", RowBox[{"{", RowBox[{"0.`", ",", "0.003`"}], "}"}]}], ",", RowBox[{"PlotStyle", "\[Rule]", RowBox[{"PointSize", "[", "0.02`", "]"}]}], ",", RowBox[{"PlotLabel", "\[Rule]", "\"\\""}]}], "]"}]], "Input"], Cell[BoxData[ RowBox[{ RowBox[{"meanError2", "[", "n_Integer", "]"}], " ", ":=", " ", RowBox[{"NIntegrate", "[", RowBox[{ RowBox[{ RowBox[{"(", RowBox[{ RowBox[{"f2", "[", "x", "]"}], " ", "-", " ", RowBox[{ RowBox[{"f2Fourier", "[", "n", "]"}], "[", "x", "]"}]}], ")"}], "^", "2"}], ",", " ", RowBox[{"{", RowBox[{"x", ",", " ", "0", ",", " ", "1"}], "}"}]}], "]"}]}]], "Input"], Cell[BoxData[ RowBox[{ RowBox[{"f2Error", " ", "=", " ", RowBox[{"Table", "[", RowBox[{ RowBox[{"meanError2", "[", "n", "]"}], ",", " ", RowBox[{"{", RowBox[{"n", ",", " ", "1", ",", " ", "nModes"}], "}"}]}], "]"}]}], ";"}]], "Input"], Cell[BoxData[ RowBox[{"ListPlot", "[", RowBox[{"f2Error", ",", RowBox[{"PlotRange", "\[Rule]", RowBox[{"{", RowBox[{"0.`", ",", "0.05`"}], "}"}]}], ",", RowBox[{"PlotStyle", "\[Rule]", RowBox[{"PointSize", "[", "0.02`", "]"}]}], ",", RowBox[{"PlotLabel", "\[Rule]", "\"\\""}]}], "]"}]], "Input"], Cell["\<\ Notice that it takes many terms in order to represent functions with sharp, \ discontinuous steps.\ \>", "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"], Cell[CellGroupData[{ Cell["Solution", "Subsubsection"], Cell[BoxData[ RowBox[{ RowBox[{ RowBox[{"getChebyshevMode", "[", "f_", "]"}], "[", "n_Integer", "]"}], " ", ":=", " ", RowBox[{ RowBox[{"If", "[", RowBox[{ RowBox[{"n", " ", ">", " ", "0"}], ",", " ", RowBox[{"2", "/", "\[Pi]"}], ",", " ", RowBox[{"1", "/", "\[Pi]"}]}], "]"}], RowBox[{"NIntegrate", "[", RowBox[{ RowBox[{ RowBox[{"f", "[", "x", "]"}], " ", RowBox[{ RowBox[{"ChebyshevT", "[", RowBox[{"n", ",", "x"}], "]"}], "/", RowBox[{"Sqrt", "[", RowBox[{"1", " ", "-", " ", SuperscriptBox["x", "2"]}], "]"}]}]}], ",", " ", RowBox[{"{", RowBox[{"x", ",", " ", RowBox[{"-", "1"}], ",", " ", "1"}], "}"}]}], "]"}], " "}]}]], "Input"], Cell[BoxData[ RowBox[{ RowBox[{"nModes", " ", "=", " ", "25"}], ";"}]], "Input"], Cell[BoxData[ RowBox[{ RowBox[{"Do", "[", RowBox[{ RowBox[{ RowBox[{"fc1", "[", "n", "]"}], " ", "=", " ", RowBox[{"N", "[", RowBox[{ RowBox[{"getChebyshevMode", "[", "fc1", "]"}], "[", "n", "]"}], "]"}]}], ",", " ", RowBox[{"{", RowBox[{"n", ",", " ", "0", ",", " ", "nModes"}], "}"}]}], "]"}], ";"}]], "Input"], Cell[BoxData[ RowBox[{ RowBox[{"Do", "[", RowBox[{ RowBox[{ RowBox[{"fc2", "[", "n", "]"}], " ", "=", " ", RowBox[{"N", "[", RowBox[{ RowBox[{"getChebyshevMode", "[", "fc2", "]"}], "[", "n", "]"}], "]"}]}], ",", " ", RowBox[{"{", RowBox[{"n", ",", " ", "0", ",", " ", "nModes"}], "}"}]}], "]"}], ";"}]], "Input"], Cell[BoxData[{ RowBox[{ RowBox[{ RowBox[{ RowBox[{"fc1Chebyshev", "[", "n_Integer", "]"}], "[", "x_", "]"}], " ", ":=", " ", RowBox[{"Sum", "[", RowBox[{ RowBox[{ RowBox[{"fc1", "[", "i", "]"}], " ", RowBox[{"ChebyshevT", "[", RowBox[{"i", ",", "x"}], "]"}]}], ",", " ", RowBox[{"{", RowBox[{"i", ",", " ", "0", ",", " ", "n"}], "}"}]}], "]"}]}], ";"}], "\[IndentingNewLine]", RowBox[{ RowBox[{ RowBox[{ RowBox[{"fc2Chebyshev", "[", "n_Integer", "]"}], "[", "x_", "]"}], " ", ":=", " ", RowBox[{"Sum", "[", RowBox[{ RowBox[{ RowBox[{"fc2", "[", "i", "]"}], " ", RowBox[{"ChebyshevT", "[", RowBox[{"i", ",", "x"}], "]"}]}], ",", " ", RowBox[{"{", RowBox[{"i", ",", " ", "0", ",", " ", "n"}], "}"}]}], "]"}]}], ";"}]}], "Input"], Cell[BoxData[ RowBox[{"Plot", "[", RowBox[{ RowBox[{"{", RowBox[{ RowBox[{"fc1", "[", "x", "]"}], ",", RowBox[{ RowBox[{"fc1Chebyshev", "[", "3", "]"}], "[", "x", "]"}], ",", RowBox[{ RowBox[{"fc1Chebyshev", "[", "5", "]"}], "[", "x", "]"}], ",", RowBox[{ RowBox[{"fc1Chebyshev", "[", "10", "]"}], "[", "x", "]"}], ",", RowBox[{ RowBox[{"fc1Chebyshev", "[", "15", "]"}], "[", "x", "]"}]}], "}"}], ",", RowBox[{"{", RowBox[{"x", ",", RowBox[{"-", "1"}], ",", "1"}], "}"}], ",", RowBox[{"PlotRange", "\[Rule]", "All"}], ",", RowBox[{"PlotStyle", "\[Rule]", RowBox[{"{", RowBox[{ RowBox[{"{", RowBox[{"Thickness", "[", "0.01`", "]"}], "}"}], ",", RowBox[{"{", RowBox[{"Hue", "[", FractionBox["1", "5"], "]"}], "}"}], ",", RowBox[{"{", RowBox[{"Hue", "[", FractionBox["2", "5"], "]"}], "}"}], ",", RowBox[{"{", RowBox[{"Hue", "[", FractionBox["3", "5"], "]"}], "}"}], ",", RowBox[{"{", RowBox[{"Hue", "[", FractionBox["4", "5"], "]"}], "}"}]}], "}"}]}], ",", RowBox[{"PlotLabel", "\[Rule]", "\"\\""}]}], "]"}]], "Input"], Cell[BoxData[ RowBox[{"Plot", "[", RowBox[{ RowBox[{"{", RowBox[{ RowBox[{"fc2", "[", "x", "]"}], ",", RowBox[{ RowBox[{"fc2Chebyshev", "[", "3", "]"}], "[", "x", "]"}], ",", RowBox[{ RowBox[{"fc2Chebyshev", "[", "5", "]"}], "[", "x", "]"}], ",", RowBox[{ RowBox[{"fc2Chebyshev", "[", "10", "]"}], "[", "x", "]"}], ",", RowBox[{ RowBox[{"fc2Chebyshev", "[", "15", "]"}], "[", "x", "]"}]}], "}"}], ",", RowBox[{"{", RowBox[{"x", ",", RowBox[{"-", "1"}], ",", "1"}], "}"}], ",", RowBox[{"PlotRange", "\[Rule]", "All"}], ",", RowBox[{"PlotStyle", "\[Rule]", RowBox[{"{", RowBox[{ RowBox[{"{", RowBox[{"Thickness", "[", "0.01`", "]"}], "}"}], ",", RowBox[{"{", RowBox[{"Hue", "[", FractionBox["1", "5"], "]"}], "}"}], ",", RowBox[{"{", RowBox[{"Hue", "[", FractionBox["2", "5"], "]"}], "}"}], ",", RowBox[{"{", RowBox[{"Hue", "[", FractionBox["3", "5"], "]"}], "}"}], ",", RowBox[{"{", RowBox[{"Hue", "[", FractionBox["4", "5"], "]"}], "}"}]}], "}"}]}], ",", RowBox[{"PlotLabel", "\[Rule]", "\"\\""}]}], "]"}]], "Input"], Cell[BoxData[{ RowBox[{ RowBox[{ RowBox[{"meanErrorC1", "[", "n_Integer", "]"}], " ", ":=", " ", RowBox[{"NIntegrate", "[", RowBox[{ RowBox[{ RowBox[{"(", RowBox[{ RowBox[{"fc1", "[", "x", "]"}], " ", "-", " ", RowBox[{ RowBox[{"fc1Chebyshev", "[", "n", "]"}], "[", "x", "]"}]}], ")"}], "^", "2"}], ",", " ", RowBox[{"{", RowBox[{"x", ",", " ", RowBox[{"-", "1"}], ",", " ", "1"}], "}"}]}], "]"}]}], ";"}], "\[IndentingNewLine]", RowBox[{ RowBox[{ RowBox[{"meanErrorC2", "[", "n_Integer", "]"}], " ", ":=", " ", RowBox[{"NIntegrate", "[", RowBox[{ RowBox[{ RowBox[{"(", RowBox[{ RowBox[{"fc2", "[", "x", "]"}], " ", "-", " ", RowBox[{ RowBox[{"fc2Chebyshev", "[", "n", "]"}], "[", "x", "]"}]}], ")"}], "^", "2"}], ",", " ", RowBox[{"{", RowBox[{"x", ",", " ", RowBox[{"-", "1"}], ",", " ", "1"}], "}"}]}], "]"}]}], ";"}]}], "Input"], Cell[BoxData[ RowBox[{ RowBox[{"fc1Error", " ", "=", " ", RowBox[{"Table", "[", RowBox[{ RowBox[{"meanErrorC1", "[", "n", "]"}], ",", " ", RowBox[{"{", RowBox[{"n", ",", " ", "1", ",", " ", "nModes"}], "}"}]}], "]"}]}], ";"}]], "Input"], Cell[BoxData[ RowBox[{"ListPlot", "[", RowBox[{"fc1Error", ",", RowBox[{"PlotRange", "\[Rule]", RowBox[{"{", RowBox[{"0.`", ",", "0.12`"}], "}"}]}], ",", RowBox[{"PlotStyle", "\[Rule]", RowBox[{"PointSize", "[", "0.02`", "]"}]}], ",", RowBox[{"PlotLabel", "\[Rule]", "\"\\""}]}], "]"}]], "Input"], Cell[BoxData[ RowBox[{ RowBox[{"fc2Error", " ", "=", " ", RowBox[{"Table", "[", RowBox[{ RowBox[{"meanErrorC2", "[", "n", "]"}], ",", " ", RowBox[{"{", RowBox[{"n", ",", " ", "1", ",", " ", "nModes"}], "}"}]}], "]"}]}], ";"}]], "Input"], Cell[BoxData[ RowBox[{"ListPlot", "[", RowBox[{"fc2Error", ",", RowBox[{"PlotRange", "\[Rule]", RowBox[{"{", RowBox[{"0.`", ",", "0.7`"}], "}"}]}], ",", RowBox[{"PlotStyle", "\[Rule]", RowBox[{"PointSize", "[", "0.02`", "]"}]}], ",", RowBox[{"PlotLabel", "\[Rule]", "\"\\""}]}], "]"}]], "Input"], Cell["\<\ Once again, the accuracy improves for short sums when the function is smooth \ and continuous.\ \>", "Text"] }, Closed]] }, Closed]] }, Open ]] }, WindowSize->{652, 889}, WindowMargins->{{42, Automatic}, {Automatic, 10}}, 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[777, 31, 231, 6, 43, "Text"], Cell[1011, 39, 769, 22, 80, "Input"], Cell[CellGroupData[{ Cell[1805, 65, 45, 0, 69, "Section"], Cell[1853, 67, 39, 0, 27, "Text"], Cell[1895, 69, 788, 25, 63, "Input"], Cell[2686, 96, 384, 8, 59, "Text"], Cell[3073, 106, 1179, 39, 114, "Text"], Cell[CellGroupData[{ Cell[4277, 149, 29, 0, 24, "Subsubsection"], Cell[4309, 151, 206, 8, 27, "Text"], Cell[4518, 161, 564, 18, 46, "Input"], Cell[5085, 181, 454, 14, 28, "Input"], Cell[5542, 197, 118, 3, 27, "Text"] }, Closed]], Cell[CellGroupData[{ Cell[5697, 205, 33, 0, 24, "Subsubsection"], Cell[5733, 207, 83, 2, 28, "Input"], Cell[5819, 211, 109, 2, 27, "Text"], Cell[5931, 215, 360, 12, 28, "Input"], Cell[6294, 229, 360, 12, 28, "Input"], Cell[6657, 243, 739, 23, 46, "Input"], Cell[7399, 268, 1079, 32, 123, "Input"], Cell[8481, 302, 109, 2, 27, "Text"], Cell[8593, 306, 360, 12, 28, "Input"], Cell[8956, 320, 360, 12, 28, "Input"], Cell[9319, 334, 739, 23, 46, "Input"], Cell[10061, 359, 1079, 32, 123, "Input"], Cell[11143, 393, 121, 4, 27, "Text"], Cell[11267, 399, 445, 13, 46, "Input"], Cell[11715, 414, 267, 8, 28, "Input"], Cell[11985, 424, 351, 9, 42, "Input"], Cell[12339, 435, 445, 13, 46, "Input"], Cell[12787, 450, 267, 8, 28, "Input"], Cell[13057, 460, 350, 9, 42, "Input"], Cell[13410, 471, 122, 3, 27, "Text"] }, Closed]] }, Closed]], Cell[CellGroupData[{ Cell[13581, 480, 29, 0, 39, "Section"], Cell[13613, 482, 138, 3, 43, "Text"], Cell[13754, 487, 355, 15, 46, "Text"], Cell[14112, 504, 276, 8, 28, "Input"], Cell[14391, 514, 652, 20, 67, "Input"], Cell[15046, 536, 46, 0, 27, "Text"], Cell[15095, 538, 466, 14, 33, "Input"], Cell[15564, 554, 622, 18, 53, "Input"], Cell[16189, 574, 569, 16, 75, "Text"], Cell[16761, 592, 1037, 34, 65, "Input"], Cell[CellGroupData[{ Cell[17823, 630, 33, 0, 24, "Subsubsection"], Cell[17859, 632, 764, 23, 69, "Input"], Cell[18626, 657, 83, 2, 28, "Input"], Cell[18712, 661, 369, 12, 28, "Input"], Cell[19084, 675, 369, 12, 28, "Input"], Cell[19456, 689, 857, 28, 46, "Input"], Cell[20316, 719, 1242, 36, 140, "Input"], Cell[21561, 757, 1242, 36, 140, "Input"], Cell[22806, 795, 1012, 31, 80, "Input"], Cell[23821, 828, 269, 8, 28, "Input"], Cell[24093, 838, 352, 9, 46, "Input"], Cell[24448, 849, 269, 8, 28, "Input"], Cell[24720, 859, 351, 9, 46, "Input"], Cell[25074, 870, 118, 3, 27, "Text"] }, Closed]] }, Closed]] }, Open ]] } ] *) (* End of internal cache information *)