(* Content-type: application/mathematica *) (*** Wolfram Notebook File ***) (* http://www.wolfram.com/nb *) (* CreatedBy='Mathematica 7.0' *) (*CacheID: 234*) (* Internal cache information: NotebookFileLineBreakTest NotebookFileLineBreakTest NotebookDataPosition[ 145, 7] NotebookDataLength[ 10533, 305] NotebookOptionsPosition[ 9936, 283] NotebookOutlinePosition[ 10280, 298] CellTagsIndexPosition[ 10237, 295] WindowFrame->Normal*) (* Beginning of Notebook Content *) Notebook[{ Cell[TextData[{ "\t\t\t\t\t\t\t\t\t", StyleBox["Legendre Polynomial Series\n\n", FontSize->36, FontWeight->"Bold"], StyleBox["In this worksheet, you will use the Legendre Polynomials to \ approximate a function in the same way you use sines and cosines or \ exponentials to approximate a function in Fourier series. \n\nWe want to \ approximate a function f(z) with Legendre Polynomials ", FontSize->20], Cell[BoxData[ FormBox[ SubscriptBox["P", "l"], TraditionalForm]], FontSize->22], StyleBox["(z), ", FontSize->22], StyleBox["analogously to doing Fourier series, i.e.\n\n\t\t\t\t\t\t\t", FontSize->20], StyleBox["f(z) = ", FontSize->36], Cell[BoxData[ FormBox[ RowBox[{ UnderoverscriptBox["\[Sum]", RowBox[{" ", RowBox[{"l", " ", "=", "0"}]}], "\[Infinity]"], SubscriptBox["c", "l"]}], TraditionalForm]], FontSize->36, FontWeight->"Plain"], Cell[BoxData[ FormBox[ RowBox[{ SubscriptBox["P", "l"], "(", "z", ")"}], TraditionalForm]], FontSize->36, FontWeight->"Plain"], "\n\n", StyleBox["Let's start with the epsilon function f(z) = \[Epsilon](z), where \ \[Epsilon](z) is the integral of the Heaviside function \[Theta](z).\n\n", FontSize->20], "\t\t\t\t\t\t" }], "Text", CellChangeTimes->{{3.5206010024399242`*^9, 3.5206014572916346`*^9}, { 3.520601500555044*^9, 3.520601608596387*^9}}], Cell[BoxData[ StyleBox[ RowBox[{"f", "=", " ", RowBox[{"Piecewise", "[", RowBox[{"{", RowBox[{ RowBox[{"{", RowBox[{"0", ",", RowBox[{"z", "<", "0"}]}], "}"}], ",", RowBox[{"{", RowBox[{"z", ",", RowBox[{"z", ">", "0"}]}], "}"}]}], "}"}], "]"}]}], FontSize->18]], "Input", CellChangeTimes->{{3.5206016212051163`*^9, 3.520601637407412*^9}, { 3.5206016687964296`*^9, 3.5206017291214657`*^9}}], Cell[BoxData[ StyleBox[ RowBox[{"Plot", "[", RowBox[{"f", ",", RowBox[{"{", RowBox[{"z", ",", RowBox[{"-", "2"}], ",", "2"}], "}"}]}], "]"}], FontSize->18]], "Input", CellChangeTimes->{{3.5206017932900553`*^9, 3.5206018294600782`*^9}}], Cell[TextData[{ "\n", StyleBox["First let's check how much each Legendre polynomial look like \ \[Epsilon](z).", FontSize->20] }], "Text", CellChangeTimes->{{3.520601858802326*^9, 3.5206019099403324`*^9}}], Cell[BoxData[{ StyleBox[ RowBox[{"l", ":=", "0"}], FontSize->18], "\[IndentingNewLine]", StyleBox[ RowBox[{"Plot", "[", RowBox[{ RowBox[{"{", RowBox[{"f", ",", RowBox[{"LegendreP", "[", RowBox[{"l", ",", "z"}], "]"}]}], "}"}], ",", RowBox[{"{", RowBox[{"z", ",", RowBox[{"-", "2"}], ",", "2"}], "}"}]}], "]"}], FontSize->18]}], "Input", CellChangeTimes->{{3.520601912877682*^9, 3.5206020124038363`*^9}, 3.520627517426322*^9, 3.520687646758815*^9, {3.520687677788476*^9, 3.5206876821945*^9}, 3.520687798876026*^9}], Cell[TextData[{ "\n", StyleBox["Now change the value of l to check some other Legendre \ polynomials.\n\nNow let's calculate the coefficients of the Legendre \ polynomial expansion.\n\n\n\t\t\t\t\t\t", FontSize->20], Cell[BoxData[ FormBox[ SubscriptBox["c", "l"], TraditionalForm]], FontSize->36], StyleBox[" = ", FontSize->36], Cell[BoxData[ FormBox[ RowBox[{ SubsuperscriptBox["\[Integral]", RowBox[{"-", "1"}], "1"], RowBox[{ FractionBox[ RowBox[{ RowBox[{"f", "(", RowBox[{ RowBox[{"2", "l"}], "+", "1"}], ")"}], RowBox[{"P", "(", RowBox[{"l", ",", "z"}], ")"}]}], "2"], "dz"}]}], TraditionalForm]], FontSize->36], "\n\t\t\t\t\t\t\n\n", StyleBox["(Compare this expression to the expression for the coefficients in \ a Fourier series.)\n\nWhy is the factor ", FontSize->20], Cell[BoxData[ FormBox[ StyleBox[ FractionBox[ RowBox[{ RowBox[{"2", "l"}], "+", "1"}], "2"], FontSize->36], TraditionalForm]]], " ", StyleBox["in the equation?", FontSize->20] }], "Text", CellChangeTimes->{{3.5206020243719735`*^9, 3.5206021629742517`*^9}, { 3.520602196581906*^9, 3.5206023893220367`*^9}}], Cell[BoxData[{ StyleBox[ RowBox[{"lmax", ":=", "3"}], FontSize->18], "\[IndentingNewLine]", StyleBox[ RowBox[{"Table", "[", RowBox[{ RowBox[{"Integrate", "[", RowBox[{ RowBox[{ RowBox[{"(", RowBox[{ RowBox[{"(", RowBox[{ RowBox[{"2", "*", "m"}], "+", "1"}], ")"}], "/", "2"}], ")"}], "*", "f", "*", RowBox[{"LegendreP", "[", RowBox[{"m", ",", "z"}], "]"}]}], ",", RowBox[{"{", RowBox[{"z", ",", RowBox[{"-", "1"}], ",", "1"}], "}"}]}], "]"}], ",", RowBox[{"{", RowBox[{"m", ",", "0", ",", "lmax"}], "}"}]}], "]"}], FontSize->18], "\[IndentingNewLine]", RowBox[{ StyleBox[ RowBox[{"Do", "[", RowBox[{ RowBox[{ RowBox[{"c", "[", "m", "]"}], "=", RowBox[{"Integrate", "[", RowBox[{ RowBox[{ RowBox[{"(", RowBox[{ RowBox[{"(", RowBox[{ RowBox[{"2", "*", "m"}], "+", "1"}], ")"}], "/", "2"}], ")"}], "*", "f", "*", RowBox[{"LegendreP", "[", RowBox[{"m", ",", "z"}], "]"}]}], ",", RowBox[{"{", RowBox[{"z", ",", RowBox[{"-", "1"}], ",", "1"}], "}"}]}], "]"}]}], ",", RowBox[{"{", RowBox[{"m", ",", "0", ",", "lmax"}], "}"}]}], "]"}], FontSize->20], "\[IndentingNewLine]"}], "\[IndentingNewLine]"}], "Input", CellChangeTimes->{{3.52060239268124*^9, 3.5206025033318243`*^9}, { 3.5206027224143567`*^9, 3.5206027728024015`*^9}, {3.5206028089568005`*^9, 3.52060281014424*^9}, {3.5206028677819138`*^9, 3.5206028681568947`*^9}, { 3.5206030193210297`*^9, 3.5206030207897043`*^9}, 3.520603130752824*^9, { 3.5206031668447256`*^9, 3.5206032985411077`*^9}, {3.520603434581017*^9, 3.5206035172017865`*^9}, {3.520604015723136*^9, 3.5206040160356197`*^9}, { 3.5206040738607845`*^9, 3.520604122311428*^9}, {3.5206042093538465`*^9, 3.520604252835995*^9}, {3.520604291818374*^9, 3.5206043809700594`*^9}, { 3.520604429701939*^9, 3.520604538727607*^9}, {3.5206047528885164`*^9, 3.520604790433469*^9}, {3.5206049293638554`*^9, 3.520604945738017*^9}, { 3.520605072669018*^9, 3.520605148165152*^9}, {3.520605234332615*^9, 3.520605252316069*^9}, {3.52060528706429*^9, 3.5206052885017166`*^9}, { 3.5206053882309847`*^9, 3.5206054061519423`*^9}, 3.520605452149587*^9, 3.52060548500728*^9, {3.520605628234321*^9, 3.5206057116206765`*^9}, { 3.520605767414695*^9, 3.520605786882448*^9}, {3.5206058211306944`*^9, 3.520605893736352*^9}, {3.5206059355935836`*^9, 3.5206059497959814`*^9}, { 3.5206065087829847`*^9, 3.520606585200947*^9}, {3.520619867880499*^9, 3.520619924643217*^9}, {3.520619963359985*^9, 3.520619984312037*^9}, { 3.5206200948845005`*^9, 3.520620119383246*^9}, {3.520627562111534*^9, 3.5206275682362204`*^9}, {3.5206277753818636`*^9, 3.5206278102082057`*^9}, {3.520627895781949*^9, 3.520627920608803*^9}, { 3.5206854710733404`*^9, 3.5206855585844846`*^9}, {3.520685628674646*^9, 3.5206856459706354`*^9}, {3.52068589820772*^9, 3.5206859297529798`*^9}, { 3.5206860479969254`*^9, 3.520686055871522*^9}, {3.5206861212275505`*^9, 3.5206861244617605`*^9}, {3.520686168787616*^9, 3.520686171256239*^9}, { 3.520686207785619*^9, 3.520686217097642*^9}, {3.520686262157835*^9, 3.520686277485175*^9}, {3.520686309108556*^9, 3.5206863586060214`*^9}, { 3.5206864212590637`*^9, 3.5206864256963363`*^9}, {3.520686984730212*^9, 3.520686985480174*^9}, 3.5206871022398205`*^9, {3.5206875130469112`*^9, 3.520687521952705*^9}, {3.520687604448481*^9, 3.5206876229162855`*^9}, { 3.520687971445315*^9, 3.520687971554684*^9}, {3.520688179981512*^9, 3.520688179997136*^9}}], Cell[TextData[StyleBox["Let's look at the graph of the truncated series, and \ compare it to the graph of f(z).\n", FontSize->20]], "Text", CellChangeTimes->{{3.520603540528717*^9, 3.5206035973383083`*^9}}], Cell[BoxData[{ StyleBox[ RowBox[{"r", "=", RowBox[{"Sum", "[", RowBox[{ RowBox[{ RowBox[{"c", "[", "m", "]"}], "*", RowBox[{"LegendreP", "[", RowBox[{"m", ",", "z"}], "]"}]}], ",", RowBox[{"{", RowBox[{"m", ",", "0", ",", "lmax"}], "}"}]}], "]"}]}], FontSize->18], "\[IndentingNewLine]", StyleBox[ RowBox[{"Plot", "[", RowBox[{ RowBox[{"{", RowBox[{"r", ",", "f"}], "}"}], ",", RowBox[{"{", RowBox[{"z", ",", RowBox[{"-", "2"}], ",", "2"}], "}"}]}], "]"}], FontSize->18]}], "Input", CellChangeTimes->{{3.5206036054472685`*^9, 3.5206037049109254`*^9}, { 3.520603812296052*^9, 3.520603824326686*^9}, {3.5206279412014985`*^9, 3.5206279426857977`*^9}, {3.520686366464994*^9, 3.520686385526518*^9}, { 3.520686447460847*^9, 3.5206864653349314`*^9}, {3.520687006979073*^9, 3.520687011275728*^9}, {3.520688182153276*^9, 3.5206881822313967`*^9}}], Cell[TextData[{ "\n", StyleBox["How good a job did the Legendre polynomials do? Try adding more \ terms. How many terms does it take to get decent convergence? What happens \ outside the range -1..1? Why? Compare to the Fourier series approximation to \ the function.", FontSize->20] }], "Text", CellChangeTimes->{{3.520687173767408*^9, 3.520687309479209*^9}}] }, WindowSize->{1272, 922}, WindowMargins->{{0, Automatic}, {Automatic, 0}}, FrontEndVersion->"7.0 for Microsoft Windows (32-bit) (February 18, 2009)", StyleDefinitions->"Default.nb" ] (* End of Notebook Content *) (* Internal cache information *) (*CellTagsOutline CellTagsIndex->{} *) (*CellTagsIndex CellTagsIndex->{} *) (*NotebookFileOutline Notebook[{ Cell[545, 20, 1370, 42, 359, "Text"], Cell[1918, 64, 460, 14, 36, "Input"], Cell[2381, 80, 263, 8, 36, "Input"], Cell[2647, 90, 210, 6, 54, "Text"], Cell[2860, 98, 580, 17, 52, "Input"], Cell[3443, 117, 1210, 42, 346, "Text"], Cell[4656, 161, 3754, 78, 115, "Input"], Cell[8413, 241, 208, 3, 61, "Text"], Cell[8624, 246, 939, 25, 52, "Input"], Cell[9566, 273, 366, 8, 79, "Text"] } ] *) (* End of internal cache information *)