(*********************************************************************** Mathematica-Compatible Notebook This notebook can be used on any computer system with Mathematica 4.0, MathReader 4.0, or any compatible application. The data for the notebook starts with the line containing stars above. To get the notebook into a Mathematica-compatible application, do one of the following: * Save the data starting with the line of stars above into a file with a name ending in .nb, then open the file inside the application; * Copy the data starting with the line of stars above to the clipboard, then use the Paste menu command inside the application. Data for notebooks contains only printable 7-bit ASCII and can be sent directly in email or through ftp in text mode. Newlines can be CR, LF or CRLF (Unix, Macintosh or MS-DOS style). NOTE: If you modify the data for this notebook not in a Mathematica- compatible application, you must delete the line below containing the word CacheID, otherwise Mathematica-compatible applications may try to use invalid cache data. For more information on notebooks and Mathematica-compatible applications, contact Wolfram Research: web: http://www.wolfram.com email: info@wolfram.com phone: +1-217-398-0700 (U.S.) Notebook reader applications are available free of charge from Wolfram Research. ***********************************************************************) (*CacheID: 232*) (*NotebookFileLineBreakTest NotebookFileLineBreakTest*) (*NotebookOptionsPosition[ 8182, 287]*) (*NotebookOutlinePosition[ 8962, 314]*) (* CellTagsIndexPosition[ 8918, 310]*) (*WindowFrame->Normal*) Notebook[{ Cell[CellGroupData[{ Cell["Building Up a Square Wave", "Title", TextAlignment->Center, TextJustification->0, FontSize->18], Cell[TextData[{ "In this notebook we'll build a square wave from normal modes and then \ calculate the coefficients. Then you get to try!\n\nSpecial feature: We use \ ", StyleBox["Mathematica", FontSlant->"Italic"], "'s Sum function to add a series of sine waves." }], "Text"], Cell[CellGroupData[{ Cell["Clear symbols", "Section", Evaluatable->False, AspectRatioFixed->True], Cell["\<\ In order to avoid interference from symbols defined in other \ notebooks, we first Clear and Remove all symbols. We assume that the \ relevant symbols are in the Global` context.\ \>", "Text", Evaluatable->False, AspectRatioFixed->True], Cell["Clear[\"Global`*\"]", "Input", AspectRatioFixed->True], Cell["Remove[\"Global`*\"]", "Input", AspectRatioFixed->True] }, Open ]], Cell[CellGroupData[{ Cell["First the Answer: Define the Sum", "Section", Evaluatable->False, AspectRatioFixed->True], Cell[TextData[{ "The function ", Cell[BoxData[ \(TraditionalForm\`\(\(\(f\_n\)(x)\)\(\ \)\)\)]], "is the sum of the first n sine waves with relative amplitude 1/i for the \ i'th term and wave number k*i, with k=2\[Pi]/L." }], "Text", Evaluatable->False, AspectRatioFixed->True], Cell[BoxData[ \(f[x_, n_]\ := \ 4\/\[Pi]\ \ Sum[1\/i\ Sin[i\ k\ x], {i, 1, 2*n - 1, 2}]\)], "Input"], Cell[BoxData[ \(\(k\ = \ \(2 \[Pi]\)\/L;\)\)], "Input"], Cell["We'll take L=1 for simplicity.", "Text", Evaluatable->False, AspectRatioFixed->True], Cell[BoxData[ \(\(L\ = \ 1\ ;\)\)], "Input"], Cell["Why are there just sine waves and not cosine waves?", "Text", Evaluatable->False, AspectRatioFixed->True] }, Open ]], Cell[CellGroupData[{ Cell["Make Some Plots", "Section", Evaluatable->False, AspectRatioFixed->True], Cell[BoxData[ \(\(\(p1\)\(\ \)\(=\)\(\ \)\(Plot[f[x, 1], {x, 0, 1}, PlotRange -> {\(-1.4\), 1.4}, \n\t\ \ \ \ \ \ \ \ \ \ \ \ \ \ PlotStyle -> RGBColor[1, 0, 0]]\)\(\ \)\)\)], "Input"], Cell[BoxData[ \(\(\(p2\)\(\ \)\(=\)\(\ \)\(Plot[f[x, 2], {x, 0, 1}, PlotRange -> {\(-1.4\), 1.4}, \n\t\ \ \ \ \ \ \ \ \ \ \ \ \ \ PlotStyle -> RGBColor[0, 1, 0]\ ]\)\(\ \)\)\)], "Input"], Cell[BoxData[ \(\(\(p3\)\(\ \)\(=\)\(\ \)\(Plot[f[x, 3], {x, 0, 1}, PlotRange -> {\(-1.4\), 1.4}, \n\t\ \ \ \ \ \ \ \ \ \ \ \ \ \ PlotStyle -> RGBColor[0, 0, 1]\ ]\)\(\ \)\)\)], "Input"], Cell[BoxData[ \(\(\(p30\)\(\ \)\(=\)\(\ \)\(Plot[f[x, 30], {x, 0, 1}, PlotRange -> {\(-1.4\), 1.4}, \n\t\ \ \ \ \ \ \ \ \ \ \ \ \ \ PlotStyle -> RGBColor[0, 1, 1]\ ]\)\(\ \)\)\)], "Input"], Cell["\<\ Try 100 terms! (What do you need to change in the p30 expression?)\ \ \>", "Text", Evaluatable->False, AspectRatioFixed->True], Cell[BoxData[ \(Show[p1, p2, p3, p30]\)], "Input"], Cell[BoxData[""], "Input"] }, Open ]], Cell[CellGroupData[{ Cell["Calculating the Coefficients", "Section", Evaluatable->False, AspectRatioFixed->True], Cell[TextData[ "Suppose we have a periodic function f[x] like the square wave, with one \ period from x=0 to x=1 and equal to zero at these points. The Fourier \ theorem says that we can represent it as a sum over an infinite number of \ sine waves with wave numbers equal to integer multiples\nof the wave number 2\ \[Pi]/L (= 2\[Pi] here): "], "Text", Evaluatable->False, AspectRatioFixed->True], Cell[BoxData[ \(\(f[x]\ = \ \[Sum]\+\(n = 1\)\%\[Infinity] c\_n\ Sin[n\ 2\ \[Pi]\ x]\ \)\)], "DisplayFormula"], Cell[TextData[{ "where the ", Cell[BoxData[ \(TraditionalForm\`c\_n\)]], "are constant coefficients. But how do we determine these coefficients?\n\ Answer: We can project them out! If m and n are integers, the integral:" }], "Text", Evaluatable->False, AspectRatioFixed->True], Cell[BoxData[ \(\[Integral]\_0\%1 Sin[m\ 2\ \[Pi]\ x]\ Sin[n\ 2\ \[Pi]\ x] \[DifferentialD]x = 0\)], "DisplayFormula"], Cell[TextData[{ "unless n=m, in which case it equals 1/2. This means that we can find ", Cell[BoxData[ \(TraditionalForm\`c\_m\)]], "by multiplying f(x) by sin(m\[Pi]x) and integrating from 0 to 1. Only the \ term with ", Cell[BoxData[ \(TraditionalForm\`c\_m\)]], "survives:" }], "Text", Evaluatable->False, AspectRatioFixed->True], Cell[BoxData[ \(\[Integral]\_0\%1 Sin[m\ 2\ \[Pi]\ x]\ f[x] \[DifferentialD]x = c\_m/2\)], "DisplayFormula"], Cell["\<\ For the square wave with amplitude 1, this means (understand \ this!):\ \>", "Text", Evaluatable->False, AspectRatioFixed->True], Cell[BoxData[ \(c\_m\ = \ Simplify[\ 2 \((\[Integral]\_0\%\(1/2\)Sin[ m\ 2\ \[Pi]\ x]*\((\(+1\))\)\ \[DifferentialD]x\ + \ \ \[Integral]\_\(1/2\)\%1 Sin[ m\ 2\ \[Pi]\ x]*\((\(-1\))\)\ \[DifferentialD]x)\)\ ]\)], \ "Input"], Cell[TextData[ "which is 0 if m is even (1-2+1=0), and 4/m\[Pi] if m is odd (1+2+1=4). This \ is the answer we used at the top! Why didn't we need any cosine waves? Why \ are the odd m sine wave coefficients zero?"], "Text", Evaluatable->False, AspectRatioFixed->True], Cell[TextData[{ "We can simplify the expression further by telling ", StyleBox["Mathematica", FontSlant->"Italic"], " that m is an integer:" }], "Text", Evaluatable->False, AspectRatioFixed->True], Cell[BoxData[ \(Simplify[c\_m, Element[m, Integers]]\)], "Input"], Cell["Equivalently:", "Text", Evaluatable->False, AspectRatioFixed->True], Cell[BoxData[ \(Simplify[c\_m, m \[Element] Integers]\)], "Input"] }, Open ]], Cell[CellGroupData[{ Cell["Now Try a Different Function!", "Section", Evaluatable->False, AspectRatioFixed->True], Cell[BoxData[ \(\(Clear[g];\)\)], "Input"], Cell[BoxData[ \(g[x_]\ := \ 2 x\ /; \ 0 < x < 1/4\)], "Input"], Cell[BoxData[ \(g[x_]\ := \ 1 - 2 x\ /; \ 1/4\ < \ x\ < \ 3/4\)], "Input"], Cell[BoxData[ \(g[x_]\ := \ 2 x\ - 2\ /; \ 3/4\ < \ x\ < \ 1\)], "Input"], Cell[BoxData[ \(Plot[g[x], {x, 0, 1}, PlotRange -> {\(- .7\), .7}]\)], "Input"], Cell["\<\ Challenge: Find the coefficients and plot the result for the first \ few terms!\ \>", "Text", Evaluatable->False, AspectRatioFixed->True] }, Open ]] }, Open ]] }, FrontEndVersion->"4.0 for X", ScreenRectangle->{{0, 1280}, {0, 1024}}, WindowSize->{640, 867}, WindowMargins->{{Automatic, 281}, {46, Automatic}}, PrintingPageRange->{Automatic, Automatic}, PrintingOptions->{"PaperSize"->{612, 792}, "PaperOrientation"->"Portrait", "Magnification"->1} ] (*********************************************************************** Cached data follows. If you edit this Notebook file directly, not using Mathematica, you must remove the line containing CacheID at the top of the file. The cache data will then be recreated when you save this file from within Mathematica. ***********************************************************************) (*CellTagsOutline CellTagsIndex->{} *) (*CellTagsIndex CellTagsIndex->{} *) (*NotebookFileOutline Notebook[{ Cell[CellGroupData[{ Cell[1739, 51, 107, 3, 93, "Title"], Cell[1849, 56, 288, 7, 86, "Text"], Cell[CellGroupData[{ Cell[2162, 67, 80, 2, 60, "Section", Evaluatable->False], Cell[2245, 71, 251, 6, 50, "Text", Evaluatable->False], Cell[2499, 79, 62, 1, 27, "Input"], Cell[2564, 82, 63, 1, 27, "Input"] }, Open ]], Cell[CellGroupData[{ Cell[2664, 88, 99, 2, 60, "Section", Evaluatable->False], Cell[2766, 92, 293, 8, 50, "Text", Evaluatable->False], Cell[3062, 102, 112, 2, 44, "Input"], Cell[3177, 106, 61, 1, 44, "Input"], Cell[3241, 109, 94, 2, 32, "Text", Evaluatable->False], Cell[3338, 113, 49, 1, 27, "Input"], Cell[3390, 116, 115, 2, 32, "Text", Evaluatable->False] }, Open ]], Cell[CellGroupData[{ Cell[3542, 123, 82, 2, 60, "Section", Evaluatable->False], Cell[3627, 127, 221, 4, 43, "Input"], Cell[3851, 133, 223, 4, 43, "Input"], Cell[4077, 139, 223, 4, 43, "Input"], Cell[4303, 145, 225, 4, 43, "Input"], Cell[4531, 151, 141, 5, 32, "Text", Evaluatable->False], Cell[4675, 158, 54, 1, 27, "Input"], Cell[4732, 161, 26, 0, 27, "Input"] }, Open ]], Cell[CellGroupData[{ Cell[4795, 166, 95, 2, 60, "Section", Evaluatable->False], Cell[4893, 170, 402, 7, 86, "Text", Evaluatable->False], Cell[5298, 179, 120, 2, 46, "DisplayFormula"], Cell[5421, 183, 296, 8, 50, "Text", Evaluatable->False], Cell[5720, 193, 133, 2, 39, "DisplayFormula"], Cell[5856, 197, 360, 11, 50, "Text", Evaluatable->False], Cell[6219, 210, 119, 2, 39, "DisplayFormula"], Cell[6341, 214, 142, 5, 32, "Text", Evaluatable->False], Cell[6486, 221, 284, 7, 44, "Input"], Cell[6773, 230, 275, 5, 50, "Text", Evaluatable->False], Cell[7051, 237, 210, 7, 32, "Text", Evaluatable->False], Cell[7264, 246, 69, 1, 27, "Input"], Cell[7336, 249, 77, 2, 32, "Text", Evaluatable->False], Cell[7416, 253, 70, 1, 27, "Input"] }, Open ]], Cell[CellGroupData[{ Cell[7523, 259, 96, 2, 60, "Section", Evaluatable->False], Cell[7622, 263, 46, 1, 27, "Input"], Cell[7671, 266, 69, 1, 27, "Input"], Cell[7743, 269, 83, 1, 27, "Input"], Cell[7829, 272, 83, 1, 27, "Input"], Cell[7915, 275, 84, 1, 27, "Input"], Cell[8002, 278, 152, 5, 32, "Text", Evaluatable->False] }, Open ]] }, Open ]] } ] *) (*********************************************************************** End of Mathematica Notebook file. ***********************************************************************)