(*^ ::[ Information = "This is a Mathematica Notebook file. It contains ASCII text, and can be transferred by email, ftp, or other text-file transfer utility. It should be read or edited using a copy of Mathematica or MathReader. If you received this as email, use your mail application or copy/paste to save everything from the line containing (*^ down to the line containing ^*) into a plain text file. On some systems you may have to give the file a name ending with ".ma" to allow Mathematica to recognize it as a Notebook. The line below identifies what version of Mathematica created this file, but it can be opened using any other version as well."; FrontEndVersion = "Macintosh Mathematica Notebook Front End Version 2.2"; MacintoshStandardFontEncoding; fontset = title, inactive, noPageBreakBelow, nohscroll, preserveAspect, groupLikeTitle, center, M7, bold, L3, e8, 24, "New York"; fontset = subtitle, inactive, noPageBreakBelow, nohscroll, preserveAspect, groupLikeTitle, center, M7, bold, L2, e6, 18, "New York"; fontset = subsubtitle, inactive, noPageBreakBelow, nohscroll, preserveAspect, groupLikeTitle, center, M7, bold, L2, e6, 14, "New York"; fontset = section, inactive, noPageBreakBelow, nohscroll, preserveAspect, groupLikeSection, grayBox, M22, bold, L2, a20, 14, "New York"; fontset = subsection, inactive, noPageBreakBelow, nohscroll, preserveAspect, groupLikeSection, blackBox, M19, bold, L2, a15, 12, "New York"; fontset = subsubsection, inactive, noPageBreakBelow, nohscroll, preserveAspect, groupLikeSection, whiteBox, M18, bold, L2, a12, 10, "New York"; fontset = text, inactive, nohscroll, noKeepOnOnePage, preserveAspect, M7, L2, 12, "New York"; fontset = smalltext, inactive, nohscroll, noKeepOnOnePage, preserveAspect, M7, L2, 10, "New York"; fontset = input, noPageBreakInGroup, nowordwrap, preserveAspect, groupLikeInput, M42, N23, bold, L2, 12, "Courier"; fontset = output, output, inactive, noPageBreakInGroup, nowordwrap, preserveAspect, groupLikeOutput, M42, N23, L2, 12, "Courier"; fontset = message, inactive, noPageBreakInGroup, nowordwrap, preserveAspect, groupLikeOutput, M42, N23, R32768, L2, 12, "Courier"; fontset = print, inactive, noPageBreakInGroup, nowordwrap, preserveAspect, groupLikeOutput, M42, N23, L2, 12, "Courier"; fontset = info, inactive, noPageBreakInGroup, nowordwrap, preserveAspect, groupLikeOutput, M42, N23, L2, 12, "Courier"; fontset = postscript, PostScript, formatAsPostScript, output, inactive, noPageBreakInGroup, nowordwrap, preserveAspect, groupLikeGraphics, M7, l34, w282, h287, L2, 12, "Courier"; fontset = name, inactive, nowordwrap, nohscroll, noKeepOnOnePage, preserveAspect, M7, italic, B32768, L2, 10, "Geneva"; fontset = header, inactive, noKeepOnOnePage, preserveAspect, M7, L2, 10, "Times"; fontset = leftheader, inactive, L2, 10, "Times"; fontset = footer, inactive, noKeepOnOnePage, preserveAspect, center, M7, L2, 12, "Times"; fontset = leftfooter, inactive, center, L2, 12, "Times"; fontset = help, inactive, nohscroll, noKeepOnOnePage, preserveAspect, M7, L2, 10, "Geneva"; fontset = clipboard, inactive, noKeepOnOnePage, preserveAspect, M7, L2, 12, "New York"; fontset = completions, inactive, nowordwrap, noKeepOnOnePage, preserveAspect, M7, L2, 12, "New York"; fontset = special1, inactive, nowordwrap, noKeepOnOnePage, preserveAspect, M7, L2, 12, "New York"; fontset = special2, inactive, nowordwrap, noKeepOnOnePage, preserveAspect, center, M7, L2, 12, "New York"; fontset = special3, inactive, nowordwrap, noKeepOnOnePage, preserveAspect, right, M7, L2, 12, "New York"; fontset = special4, inactive, nowordwrap, noKeepOnOnePage, preserveAspect, M7, L2, 12, "New York"; fontset = special5, inactive, nowordwrap, noKeepOnOnePage, preserveAspect, M7, L2, 12, "New York"; paletteColors = 128; currentKernel; ] :[font = title; inactive; preserveAspect] Linear Methods of Applied Mathematics Calculations of some Fourier Series ;[s] 3:0,0;38,1;39,0;75,-1; 2:2,26,17,Times,1,23,0,0,0;1,14,8,Times,1,11,0,0,0; :[font = text; inactive; preserveAspect; plain; bold; fontName = "Times"] (c) Copyright 1994-1997 by Evans M. Harrell II and James V. Herod. All rights reserved. :[font = text; inactive; Cclosed; preserveAspect; plain; bold; startGroup] Notes for the instructor. ;[s] 2:0,1;25,0;26,-1; 2:1,17,12,New York,1,12,0,0,0;1,14,10,New York,1,9,0,0,0; :[font = text; inactive; preserveAspect; endGroup] This contains calculations and examples which correlate with chapter 4 of the WWW text by Harrell and Herod. Students can be encouraged to cut and paste from this notebook to do homework. :[font = subsubsection; inactive; Cclosed; preserveAspect; startGroup] Instructions :[font = text; inactive; preserveAspect; endGroup] This notebook uses Mathematica to perform calculations for Harrell and Herod's hypertext book, Linear Methods of Applied Mathematics. The student needs only a basic knowledge of Mathematica to use the notebook, which is designed both to show how to work problems in the text and to provide a template for using Mathematica to work other problems of the student's own design. Calculations will be performed when the reader presses enter in a given calculation cell (bold print). It is best to activate the cells in order, so that Mathematica will be able to call on operators and functions defined in earlier cells. Red color coding is used to warn the reader when a given calculation relies on an earlier one. ;[s] 13:0,0;19,1;30,0;96,1;133,0;181,1;192,0;315,1;326,0;538,1;549,0;626,2;642,0;721,-1; 3:7,17,12,New York,0,12,0,0,0;5,17,12,New York,2,12,0,0,0;1,17,12,New York,0,12,65535,0,0; :[font = text; inactive; preserveAspect; fontSize = 14; fontName = "Times"] A useful substitution, which we shall often make, is: :[font = input; preserveAspect] TrigId = {Cos[Pi n_] -> (-1)^n, Sin[Pi n_] -> 0}; :[font = section; inactive; Cclosed; preserveAspect; fontSize = 18; fontName = "Times"; startGroup] Some illustrative examples :[font = subsection; inactive; Cclosed; preserveAspect; fontSize = 14; fontName = "Times"; startGroup] A square pulse :[font = text; inactive; dontPreserveAspect; fontSize = 14; fontName = "Times"] Let's evaluate the Fourier series for the functions: f(x) = 1 for 0 <= x <= L/2, but 0 for L/2 <= x <= L. and g(x) = x, 0 <= x <= L. We want to represent these functions in the form a[0] + Sum[a[m] Cos[2 Pi m x/L, {m,1,N}] + Sum[b[n] Sin[2 Pi n x/L, {n,1,N}]. By the way, there is a procedure in Mathematica called Fourier, but it computes the discrete Fourier transform, which is a related but different operation. The formulae for these coefficients are: a[0] := (1/L) Integrate[f[x], {x,0,L}] (the average of f) a[m] := (2/L) Integrate[f[x] Cos[2 Pi m x/L], {x,0,L}], m = 1, 2, ... b[n] := (2/L) Integrate[f[x] Cos[2 Pi n x/L], {x,0,L}], n = 1, 2, ... We simplify matters by setting L = 1. ;[s] 3:0,0;307,1;320,0;730,-1; 2:2,17,12,Times,0,14,0,0,0;1,17,12,Times,2,14,0,0,0; :[font = input; dontPreserveAspect] f[x_] := 1 /; 0 <= x <= 1/2 f[x_] := 0 /; 1/2 < x <= 1 :[font = input; preserveAspect] Plot[f[x], {x, 0, 1}] ;[s] 3:0,0;5,1;6,0;22,-1; 2:2,14,10,Courier,1,12,0,0,0;1,14,10,Courier,1,12,65535,0,0; :[font = input; dontPreserveAspect] a[0] := Integrate[f[x], {x,0,1}] ;[s] 3:0,0;18,1;19,0;33,-1; 2:2,14,10,Courier,1,12,0,0,0;1,14,10,Courier,1,12,65535,0,0; :[font = input; Cclosed; dontPreserveAspect; startGroup] a[0] ;[s] 2:0,1;1,0;5,-1; 2:1,14,10,Courier,1,12,0,0,0;1,14,10,Courier,1,12,65535,0,0; :[font = output; output; inactive; dontPreserveAspect; endGroup] 1/2 ;[o] 1 - 2 :[font = input; dontPreserveAspect] a[m_] := 2 Integrate[Cos[2 m Pi x], {x,0,1/2}] :[font = input; Cclosed; dontPreserveAspect; startGroup] a[m] /. TrigId ;[s] 4:0,1;1,0;8,1;14,0;15,-1; 2:2,14,10,Courier,1,12,0,0,0;2,14,10,Courier,1,12,65535,0,0; :[font = output; output; inactive; preserveAspect; endGroup] 0 ;[o] 0 :[font = text; inactive; dontPreserveAspect; fontSize = 14; fontName = "Times"] These coefficients are all zero. Why? :[font = input; dontPreserveAspect] b[n_] := 2 Integrate[Sin[2 n Pi x], {x,0,1/2}] :[font = input; Cclosed; dontPreserveAspect; startGroup] b[n] /. TrigId ;[s] 2:0,0;8,1;15,-1; 2:1,14,10,Courier,1,12,0,0,0;1,14,10,Courier,1,12,65535,0,0; :[font = output; output; inactive; dontPreserveAspect; endGroup] 2*(1/(2*n*Pi) - (-1)^n/(2*n*Pi)) ;[o] n 1 (-1) 2 (------ - ------) 2 n Pi 2 n Pi :[font = input; Cclosed; dontPreserveAspect; startGroup] Simplify[%] ;[s] 3:0,0;9,1;10,0;12,-1; 2:2,14,10,Courier,1,12,0,0,0;1,14,10,Courier,1,12,65535,0,0; :[font = output; output; inactive; dontPreserveAspect; endGroup] (1 - (-1)^n)/(n*Pi) ;[o] n 1 - (-1) --------- n Pi :[font = text; inactive; dontPreserveAspect; fontSize = 14; fontName = "Times"] If n is even, b[2 k] = 0. Thus only odd terms survive, in which case b[2 k + 1] = 2/(Pi (2 k + 1)). We can write the full series: :[font = input; dontPreserveAspect] Clear[FullSeries] :[font = input; dontPreserveAspect] FullSeries[x_,N_] := 1/2 + \ Sum[2 Sin[2 Pi n x]/ (Pi n),{n,1,N,2}] ;[s] 4:0,0;28,1;35,0;39,1;75,-1; 2:2,14,10,Courier,1,12,0,0,0;2,17,12,New York,1,12,0,0,0; :[font = text; inactive; preserveAspect; fontSize = 14; fontName = "Times"] Explanation: The list {n,1,N,2} tells Mathematica to increment n by 2 until it reaches N. This takes care of the two forms of b[n] in an efficient way. ;[s] 3:0,0;39,1;50,0;154,-1; 2:2,17,12,Times,0,14,0,0,0;1,17,12,Times,2,14,0,0,0; :[font = input; dontPreserveAspect] Plot[{FullSeries[x,1], f[x]}, {x,0,1}] ;[s] 3:0,0;6,1;16,0;39,-1; 2:2,14,10,Courier,1,12,0,0,0;1,14,10,Courier,1,12,65535,0,0; :[font = input; dontPreserveAspect] Plot[{FullSeries[x,3], f[x]}, {x,0,1}] ;[s] 3:0,0;6,1;16,0;39,-1; 2:2,14,10,Courier,1,12,0,0,0;1,14,10,Courier,1,12,65535,0,0; :[font = input; dontPreserveAspect; endGroup] Plot[{FullSeries[x,7], f[x]}, {x,0,1}] ;[s] 3:0,0;6,1;16,0;39,-1; 2:2,14,10,Courier,1,12,0,0,0;1,14,10,Courier,1,12,65535,0,0; :[font = subsection; inactive; Cclosed; preserveAspect; startGroup] On the excitation of mechanical resonances :[font = text; inactive; dontPreserveAspect; fontSize = 14; fontName = "Times"] Suppose that experiments by K. Battle at the Wiener Staatsoper in Austria show that a crystal goblet will shatter if the intensity of the tone at frequency 1760 Hz (high A) exceeds .01. (We use physical units in which the proportionality between the power and the square of the amplitude is 1, i.e., we define the intensity simply by a[k]^2 + b[k]^2.) At Georgia Tech, not a particularly musical spot, we can generate a square pulse with amplitude A for 1/704 sec., then amplitude 0 for the same length of time, then A, etc., periodically with period 1/352. What amplitude A will cause the glass to shatter in our laboratory? The mapping from functions to their Fourier coefficients is linear. Hence the coefficients can be obtained from the ones we just calculated. Step 1. Scale the independent variable by replacing x with t and L with 1/330. Step 2. Multiply all the coefficients by A. The harmonic with frequency 1760 is the one with n=5, so the Fourier coefficients corresponding to this frequency are a[5] = 0, and b[5] = 2A/(5 Pi) The intensity is 4 A^2/(25 Pi^2). The intensity above which the glass will shatter is :[font = input; Cclosed; dontPreserveAspect; startGroup] A = Sqrt[25 Pi^2 / 400] :[font = output; output; inactive; dontPreserveAspect; endGroup] Pi/4 ;[o] Pi -- 4 :[font = input; Cclosed; dontPreserveAspect; startGroup] N[%] :[font = output; output; inactive; dontPreserveAspect; endGroup; endGroup] 0.7853981633974483095 ;[o] 0.785398 :[font = subsection; inactive; Cclosed; preserveAspect; fontSize = 14; fontName = "Times"; startGroup] A sawtooth function :[font = text; inactive; dontPreserveAspect; fontSize = 14; fontName = "Times"] For comparison, let us find another Fourier series, namely the one for the periodic extension of f(x) = x, 0 <= x <= L, sometmes designated x mod L. Thus for x between L and 2L, the function is (x-L), for x between 2L and 3L it is (x-2L), etc. Again, for simplicity we set L = 1. The graph has a sawtooth shape: :[font = input; dontPreserveAspect; fontSize = 14; fontName = "Times"] Plot[Mod[x,1], {x,-2,3}] :[font = input; dontPreserveAspect] a[0] := Integrate[x, {x,0,1}] :[font = input; Cclosed; dontPreserveAspect; startGroup] a[0] ;[s] 2:0,1;4,0;5,-1; 2:1,14,10,Courier,1,12,0,0,0;1,14,10,Courier,1,12,65535,0,0; :[font = output; output; inactive; preserveAspect; endGroup] 1/2 ;[o] 1 - 2 :[font = input; dontPreserveAspect] Clear[a] :[font = input; dontPreserveAspect] a[m_] := 2 Integrate[x Cos[2 m Pi x], {x,0,1}] :[font = input; Cclosed; dontPreserveAspect; startGroup] a[m] /. TrigId ;[s] 4:0,1;1,0;8,1;14,0;15,-1; 2:2,14,10,Courier,1,12,0,0,0;2,14,10,Courier,1,12,65535,0,0; :[font = output; output; inactive; dontPreserveAspect; endGroup] (-m^(-2) + (-1)^(2*m)/m^2)/Pi ;[o] 2 m -2 (-1) -m + ------- 2 m -------------- Pi :[font = input; Cclosed; preserveAspect; startGroup] % /. (-1)^(2 m) -> 1 :[font = output; output; inactive; preserveAspect; endGroup] 0 ;[o] 0 :[font = text; inactive; dontPreserveAspect; fontSize = 14; fontName = "Times"] These coefficients are all zero, again. Why? :[font = input; dontPreserveAspect] b[n_] := 2 Integrate[x Sin[2 n Pi x], \ {x,0,1}] /. TrigId /. (-1)^(2 n) -> 1 :[font = input; Cclosed; dontPreserveAspect; startGroup] b[n] :[font = output; output; inactive; preserveAspect; endGroup] -(1/(n*Pi)) ;[o] 1 -(----) n Pi :[font = input; dontPreserveAspect] Clear[FullSeries] :[font = input; dontPreserveAspect] FullSeries[x_,N_] := 1/2 + \ Sum[- (1/(n Pi)) Sin[2 Pi n x] ,{n,1,N}] ;[s] 4:0,0;28,1;35,0;39,1;77,-1; 2:2,14,10,Courier,1,12,0,0,0;2,17,12,New York,1,12,0,0,0; :[font = text; inactive; preserveAspect] Let us see how the series converges: :[font = input; preserveAspect] Plot[{FullSeries[x,2], x}, {x,0,1}] ;[s] 3:0,0;6,1;16,0;36,-1; 2:2,14,10,Courier,1,12,0,0,0;1,14,10,Courier,1,12,65535,0,0; :[font = input; dontPreserveAspect] Plot[{FullSeries[x,6], x}, {x,0,1}] ;[s] 3:0,0;6,1;16,0;36,-1; 2:2,14,10,Courier,1,12,0,0,0;1,14,10,Courier,1,12,65535,0,0; :[font = text; inactive; preserveAspect] Here is how it looks when we plot on a longer interval: :[font = input; dontPreserveAspect] Plot[{FullSeries[x,4], Mod[x,1]}, {x,- 2,2}] ;[s] 3:0,0;6,1;16,0;45,-1; 2:2,14,10,Courier,1,12,0,0,0;1,14,10,Courier,1,12,65535,0,0; :[font = text; inactive; dontPreserveAspect; fontSize = 14; fontName = "Times"; endGroup] The Fourier series is converging nicely to the function except at the end-points of the interval, which are places where the full periodic saw-tooth function has jumps, and we saw something similar with the square pulse. In both cases we see numerical evidence for the theorem that the Fourier series converges to f(x) where f(x) is continuous, and where it has a jump, the Fourier series converges to the average of the upper and the lower value at the jump. :[font = subsection; inactive; Cclosed; preserveAspect; startGroup] A complicated function :[font = text; inactive; dontPreserveAspect; fontSize = 14; fontName = "Times"] Let's try out a different sort of example, where we need to integrate numerically: the function sin(Pi/x) :[font = input; dontPreserveAspect] Clear[b] :[font = input; dontPreserveAspect] b[n_] := NIntegrate[Sin[Pi/x] Sin[n Pi x], {x,-1,1}] :[font = input; Cclosed; dontPreserveAspect; startGroup] {b[1],b[2],b[3],b[4],b[5],b[6]} ;[s] 13:0,0;1,1;2,0;6,1;7,0;11,1;12,0;16,1;17,0;21,1;22,0;26,1;27,0;32,-1; 2:7,14,10,Courier,1,12,0,0,0;6,14,10,Courier,1,12,65535,0,0; :[font = output; output; inactive; dontPreserveAspect; endGroup] {-0.3071329778789654123, 0.5062509679699521912, -0.271449220623610834, -0.2561291634161970945, 0.1947511859947028479, 0.2192911372159977088} ;[o] {-0.307133, 0.506251, -0.271449, -0.256129, 0.194751, 0.219291} :[font = text; inactive; dontPreserveAspect; fontSize = 14; fontName = "Times"] We are clearly having convergence problems. Let us put the series in by hand and look at it: :[font = input; dontPreserveAspect] NewSeries[x_] := - 0.307133 Sin[Pi x] + \ 0.506251 Sin[2 Pi x] - 0.271449 Sin[3 Pi x]\ - 0.256129 Sin[4 Pi x] + 0.194751 Sin[5 Pi x] + \ 0.219291 Sin[6 Pi x] :[font = input; dontPreserveAspect; endGroup] Plot[NewSeries[x], {x, -1, 1}] Plot[Sin[Pi/x], {x, -1, 1}] ;[s] 3:0,0;5,1;14,0;59,-1; 2:2,14,10,Courier,1,12,0,0,0;1,14,10,Courier,1,12,65535,0,0; :[font = subsection; inactive; Cclosed; preserveAspect; fontSize = 14; fontName = "Times"; startGroup] A singular function :[font = text; inactive; dontPreserveAspect; fontSize = 14; fontName = "Times"] Here is another example, which is square-integrable but has an infinite jump. :[font = input; dontPreserveAspect] Clear[b] Clear[NewSeries] :[font = input; dontPreserveAspect] b[n_] := NIntegrate[x^(-1/3) Sin[n Pi x], {x,-1,1}] :[font = input; Cclosed; dontPreserveAspect; startGroup] {b[1],b[2],b[3],b[4],b[5],b[6]} ;[s] 13:0,0;1,1;2,0;6,1;7,0;11,1;12,0;16,1;17,0;21,1;22,0;26,1;27,0;32,-1; 2:7,14,10,Courier,1,12,0,0,0;6,14,10,Courier,1,12,65535,0,0; :[font = message; inactive; dontPreserveAspect] NIntegrate::conv: Numerical integral failed to reach specified accuracy after 7 recursive subdivisions near -0.0164299 for variable number 1. :[font = message; inactive; dontPreserveAspect] NIntegrate::conv: Numerical integral failed to reach specified accuracy after 7 recursive subdivisions near 0.0148201 for variable number 1. :[font = message; inactive; dontPreserveAspect] NIntegrate::conv: Numerical integral failed to reach specified accuracy after 7 recursive subdivisions near -0.0164299 for variable number 1. :[font = message; inactive; dontPreserveAspect] General::stop: Further output of NIntegrate::conv will be suppressed during this calculation. :[font = output; output; inactive; dontPreserveAspect; endGroup] {1.710689953277251171, 0.3736036030974259086, 0.7368949814369842807, 0.2752161613201822172, 0.5010701734296802681, 0.2252029789384463762} ;[o] {1.71069, 0.373604, 0.736895, 0.275216, 0.50107, 0.225203} :[font = input; dontPreserveAspect] NewSeries[x_] := 1.71069 Sin[Pi x] + \ 0.373604 Sin[2 Pi x] + 0.736895 Sin[3 Pi x]\ + 0.275216 Sin[4 Pi x] + 0.50107 Sin[5 Pi x] + \ 0.225203 Sin[6 Pi x] :[font = input; dontPreserveAspect; endGroup; endGroup] Plot[NewSeries[x], {x, -1, 1}] ;[s] 3:0,0;5,1;14,0;31,-1; 2:2,14,10,Courier,1,12,0,0,0;1,14,10,Courier,1,12,65535,0,0; :[font = section; inactive; Cclosed; preserveAspect; fontSize = 18; fontName = "Times"; startGroup] Automating the Fourier series :[font = text; inactive; preserveAspect; fontSize = 14; fontName = "Times"] Here we set up some Mathematica commands to compute the Fourier for a general function defined on an interval a < x < b. Warning! We do not recommend running these commands on a computer with a slow processor, since there are several nested definitions and integrations. If you find yoursefl limited by the capabilities of your machine, it is recommended that you calculate the coefficients first, and then insert them into the series with a separate definition, as in the examples above. We first give the formulae in case the integrals can be done in closed form: ;[s] 3:0,0;20,1;31,0;571,-1; 2:2,17,12,Times,0,14,0,0,0;1,17,12,Times,2,14,0,0,0; :[font = input; dontPreserveAspect] Ave[f_, {a_,b_}] := (1/(b-a)) Integrate[(f /. x -> intvar1), \ {intvar1, a, b}] A[f_,m_, {a_,b_}] := (2/(b-a)) Integrate[ \ (Cos[2 m Pi intvar2/(b-a)] f /. x -> intvar2), \ {intvar2, a, b}] /. TrigId B[f_,n_, {a_,b_}] := (2/(b-a)) Integrate[ \ (Sin[2 n Pi intvar3/(b-a)] f /. x -> intvar3), \ {intvar3, a, b}] /. TrigId :[font = input; preserveAspect] FullSeries[f_, infinity_, {x_,a_,b_}] := Ave[f,{a,b}] + \ Sum[A[f,m,{a,b}] Cos[2 m Pi x/(b-a)], {m, 1, infinity}] + \ Sum[B[f,n,{a,b}] Sin[2 n Pi x/(b-a)], {n, 1, infinity}] ;[s] 7:0,0;41,1;44,0;68,1;69,0;134,1;135,0;186,-1; 2:4,14,10,Courier,1,12,0,0,0;3,14,10,Courier,1,12,65535,0,0; :[font = text; inactive; preserveAspect; fontSize = 14; fontName = "Times"] An example: :[font = input; Cclosed; preserveAspect; startGroup] FullSeries[x, 3, {x,0,1}] :[font = output; output; inactive; preserveAspect; endGroup] 1/2 - Sin[2*Pi*x]/Pi - Sin[4*Pi*x]/(2*Pi) - Sin[6*Pi*x]/(3*Pi) ;[o] 1 Sin[2 Pi x] Sin[4 Pi x] Sin[6 Pi x] - - ----------- - ----------- - ----------- 2 Pi 2 Pi 3 Pi :[font = text; inactive; preserveAspect; fontSize = 14; fontName = "Times"] Of course, it may be necessary to compute integrals numerically. In that case, we use the commands: :[font = input; dontPreserveAspect] NAve[f_, {a_,b_}] := (1/(b-a)) NIntegrate[(f /. x -> intvar1), \ {intvar1, a, b}] NA[f_,m_, {a_,b_}] := (2/(b-a)) NIntegrate[ \ (Cos[2 m Pi intvar2/(b-a)] f /. x -> intvar2), \ {intvar2, a, b}] NB[f_,n_, {a_,b_}] := (2/(b-a)) NIntegrate[ \ (Sin[2 n Pi intvar3/(b-a)] f /. x -> intvar3), \ {intvar3, a, b}] :[font = input; preserveAspect] NFullSeries[f_, infinity_, {x_,a_,b_}] := NAve[f,{a,b}] + \ Sum[NA[f,m,{a,b}] Cos[2 m Pi x/(b-a)], {m, 1, infinity}] + \ Sum[NB[f,n,{a,b}] Sin[2 n Pi x/(b-a)], {n, 1, infinity}] ;[s] 7:0,0;42,1;46,0;70,1;72,0;137,1;139,0;190,-1; 2:4,14,10,Courier,1,12,0,0,0;3,14,10,Courier,1,12,65535,0,0; :[font = text; inactive; preserveAspect; fontSize = 14; fontName = "Times"] An example: :[font = input; Cclosed; preserveAspect; startGroup] NFullSeries[x^(2/3), 3, {x,0,1}] ;[s] 2:0,1;11,0;33,-1; 2:1,14,10,Courier,1,12,0,0,0;1,14,10,Courier,1,12,65535,0,0; :[font = output; output; inactive; preserveAspect; endGroup; endGroup] 0.6000000002354127 - 0.03963941745547517*Cos[2*Pi*x] - 0.01459951482347818*Cos[4*Pi*x] - 0.007963770053469162*Cos[6*Pi*x] - 0.2777963201578738*Sin[2*Pi*x] - 0.1460841097837243*Sin[4*Pi*x] - 0.0994072810056653*Sin[6*Pi*x] ;[o] 0.6 - 0.0396394 Cos[2 Pi x] - 0.0145995 Cos[4 Pi x] - 0.00796377 Cos[6 Pi x] - 0.277796 Sin[2 Pi x] - 0.146084 Sin[4 Pi x] - 0.0994073 Sin[6 Pi x] :[font = section; inactive; Cclosed; preserveAspect; fontSize = 18; fontName = "Times"; startGroup] Complex Fourier series :[font = text; inactive; preserveAspect; fontSize = 14; fontName = "Times"] As in the previous sections, it will be convenient to program in some common trigonometric substitutions, but now we should include their exponential form: :[font = input; preserveAspect] ExpId = {E^(I Pi k) -> (-1)^k,E^(-I Pi k) -> (-1)^k} :[font = text; inactive; preserveAspect; fontSize = 14; fontName = "Times"] In the last part of this notebook we will use the complex form of the Fourier series. As you recall, the complex series is completely equivalent to the full real series, with both sines and cosines. You may find it instructive to set the calculations up with the real functions for comparison, using the notebook for chapter 4 as a template. The complex Fourier coefficients for a function f on an interval (a,b) are given by the formula: :[font = input; preserveAspect] FourierC[f_,k_, {a_,b_}] := (1/(b-a)) Integrate[ \ (Exp[- 2 k Pi I intvar2/(b-a)] f /. x -> intvar2), \ {intvar2, a, b}] /. TrigId /. ExpId :[font = subsection; inactive; Cclosed; preserveAspect; fontSize = 14; fontName = "Times"; startGroup] A simple example: The constant function 1 for 0 < x < pi. :[font = input; Cclosed; preserveAspect; startGroup] FourierC[1,k, {0,Pi}] ;[s] 2:0,1;8,0;22,-1; 2:1,14,10,Courier,1,12,0,0,0;1,14,10,Courier,1,12,65535,0,0; :[font = output; output; inactive; preserveAspect; endGroup] (-I/2/k + (I/2*E^(-2*I*k*Pi))/k)/Pi ;[o] -I I -2 I k Pi -- - E 2 2 -- + ------------ k k ----------------- Pi :[font = input; Cclosed; dontPreserveAspect; startGroup] % /. k -> 2 ;[s] 2:0,1;1,0;12,-1; 2:1,14,10,Courier,1,12,0,0,0;1,14,10,Courier,1,12,65535,0,0; :[font = output; output; inactive; dontPreserveAspect; endGroup] 0 ;[o] 0 :[font = input; Cclosed; dontPreserveAspect; startGroup] %% /. k -> 3 ;[s] 2:0,1;2,0;13,-1; 2:1,14,10,Courier,1,12,0,0,0;1,14,10,Courier,1,12,65535,0,0; :[font = output; output; inactive; dontPreserveAspect; endGroup] 0 ;[o] 0 :[font = input; Cclosed; dontPreserveAspect; startGroup] FourierC[1,0, {0,Pi}] ;[s] 2:0,1;8,0;22,-1; 2:1,14,10,Courier,1,12,0,0,0;1,14,10,Courier,1,12,65535,0,0; :[font = output; output; inactive; dontPreserveAspect; endGroup] 1 ;[o] 1 :[font = subsubsection; inactive; Cclosed; preserveAspect; fontName = "Times"; startGroup] Explanation of syntax :[font = text; inactive; preserveAspect; fontName = "Times"; endGroup] Recall that % refers to the previous calculation, %% to the one before that, etc. The phrase /. k -> 3 tells Mathematica to evaluate the expression with the additional rule that k = 3. ;[s] 3:0,0;110,1;121,0;189,-1; 2:2,14,9,Times,0,12,0,0,0;1,14,9,Times,2,12,0,0,0; :[font = text; inactive; preserveAspect; fontSize = 14; fontName = "Times"; endGroup] So, we appear to be up and running; the only nonzero coefficient is the one for k=0, corresponding to the constant function. This function is its own Fourier series. A question to ponder: What would have happened if I had written %%% /. k -> 0 in the line above? :[font = subsection; inactive; Cclosed; preserveAspect; fontSize = 14; fontName = "Times"; startGroup] Example: The function x - x3 for -1 < x < 1. ;[s] 3:0,0;28,1;29,0;46,-1; 2:2,17,12,Times,1,14,0,0,0;1,25,16,Times,33,14,0,0,0; :[font = input; Cclosed; preserveAspect; startGroup] FourierC[x - x^3,k, {-1,1}] ;[s] 2:0,1;8,0;28,-1; 2:1,14,10,Courier,1,12,0,0,0;1,14,10,Courier,1,12,65535,0,0; :[font = output; output; inactive; preserveAspect; endGroup] (-(((-1)^k*(6 - 6*I*k*Pi - 2*k^2*Pi^2))/(k^4*Pi^4)) + ((-1)^k*(6 + 6*I*k*Pi - 2*k^2*Pi^2))/(k^4*Pi^4))/2 ;[o] k 2 2 (-1) (6 - 6 I k Pi - 2 k Pi ) (-(-------------------------------) + 4 4 k Pi k 2 2 (-1) (6 + 6 I k Pi - 2 k Pi ) -------------------------------) / 2 4 4 k Pi :[font = input; Cclosed; dontPreserveAspect; startGroup] Simplify[%] ;[s] 3:0,0;9,1;10,0;12,-1; 2:2,14,10,Courier,1,12,0,0,0;1,14,10,Courier,1,12,65535,0,0; :[font = output; output; inactive; dontPreserveAspect; endGroup] (6*I*(-1)^k)/(k^3*Pi^3) ;[o] k 6 I (-1) --------- 3 3 k Pi :[font = text; inactive; dontPreserveAspect; fontSize = 14; fontName = "Times"; endGroup; endGroup] If we want a plot, it will be best to avoid complex numbers, and use the - completely equivalent - full Fourier series. :[font = section; inactive; Cclosed; preserveAspect; fontSize = 18; fontName = "Times"; startGroup] Fourier cosine series :[font = text; inactive; preserveAspect; fontSize = 14; fontName = "Times"] Here we set up some Mathematica commands to compute the Fourier cosine series. ;[s] 3:0,0;20,1;31,0;82,-1; 2:2,17,12,Times,0,14,0,0,0;1,17,12,Times,2,14,0,0,0; :[font = input; dontPreserveAspect] Ave[f_, {a_,b_}] := (1/(b-a)) Integrate[(f /. x -> intvar1), \ {intvar1, a, b}] AC[f_,m_, {a_,b_}] := (2/(b-a)) Integrate[ \ (Cos[m Pi intvar2/(b-a)] f /. x -> intvar2), \ {intvar2, a, b}] /. TrigId :[font = input; preserveAspect] CosSeries[f_, NN_, {x_,a_,b_}] := Ave[f,{a,b}] + \ Sum[AC[f,m,{a,b}] Cos[m Pi x/(b-a)], {m, 1, NN}] :[font = subsection; inactive; Cclosed; preserveAspect; fontSize = 14; fontName = "Times"; startGroup] Examples: :[font = input; Cclosed; preserveAspect; startGroup] CosSeries[Sin[Pi x], 5, {x,0,1}] :[font = output; output; inactive; preserveAspect; endGroup] 2/Pi - (4*Cos[2*Pi*x])/(3*Pi) - (4*Cos[4*Pi*x])/(15*Pi) ;[o] 2 4 Cos[2 Pi x] 4 Cos[4 Pi x] -- - ------------- - ------------- Pi 3 Pi 15 Pi :[font = input; Cclosed; preserveAspect; startGroup] CosSeries[(x-1/2)^2, 5, {x,0,1}] :[font = output; output; inactive; preserveAspect; endGroup; endGroup; endGroup] 1/12 + Cos[2*Pi*x]/Pi^2 + Cos[4*Pi*x]/(4*Pi^2) ;[o] 1 Cos[2 Pi x] Cos[4 Pi x] -- + ----------- + ----------- 12 2 2 Pi 4 Pi :[font = section; inactive; Cclosed; preserveAspect; fontSize = 18; fontName = "Times"; startGroup] Fourier sine series :[font = text; inactive; preserveAspect; fontSize = 14; fontName = "Times"] Here we set up some Mathematica commands to compute the Fourier sine series. ;[s] 3:0,0;20,1;31,0;80,-1; 2:2,17,12,Times,0,14,0,0,0;1,17,12,Times,2,14,0,0,0; :[font = input; dontPreserveAspect] BS[f_,n_, {a_,b_}] := (2/(b-a)) Integrate[ \ (Sin[n Pi intvar3/(b-a)] f /. x -> intvar3), \ {intvar3, a, b}] /. TrigId :[font = input; preserveAspect] SinSeries[f_, NN_, {x_,a_,b_}] := \ Sum[BS[f,n,{a,b}] Sin[n Pi x/(b-a)], {n, 1, NN}] :[font = subsection; inactive; preserveAspect; fontSize = 14; fontName = "Times"] Examples: :[font = input; Cclosed; preserveAspect; startGroup] SinSeries[Sin[Pi x], 5, {x,0,1}] :[font = output; output; inactive; preserveAspect; endGroup] Sin[Pi*x] ;[o] Sin[Pi x] :[font = input; Cclosed; preserveAspect; startGroup] SinSeries[(x-1/2)^2, 5, {x,0,1}] :[font = output; output; inactive; preserveAspect; endGroup] 2*(-(8 - Pi^2)/(4*Pi^3) + (-8 + Pi^2)/(4*Pi^3))*Sin[Pi*x] + 2*(-(8 - 9*Pi^2)/(108*Pi^3) + (-8 + 9*Pi^2)/(108*Pi^3))* Sin[3*Pi*x] + 2*(-(8 - 25*Pi^2)/(500*Pi^3) + (-8 + 25*Pi^2)/(500*Pi^3))*Sin[5*Pi*x] ;[o] 2 2 -(8 - Pi ) -8 + Pi 2 (---------- + --------) Sin[Pi x] + 3 3 4 Pi 4 Pi 2 2 -(8 - 9 Pi ) -8 + 9 Pi 2 (------------ + ----------) Sin[3 Pi x] + 3 3 108 Pi 108 Pi 2 2 -(8 - 25 Pi ) -8 + 25 Pi 2 (------------- + -----------) Sin[5 Pi x] 3 3 500 Pi 500 Pi :[font = input; Cclosed; preserveAspect; startGroup] Simplify[%] :[font = output; output; inactive; preserveAspect; endGroup; endGroup] ((-8 + Pi^2)*Sin[Pi*x])/Pi^3 + ((-8 + 9*Pi^2)*Sin[3*Pi*x])/(27*Pi^3) + ((-8 + 25*Pi^2)*Sin[5*Pi*x])/(125*Pi^3) ;[o] 2 2 (-8 + Pi ) Sin[Pi x] (-8 + 9 Pi ) Sin[3 Pi x] -------------------- + ------------------------ + 3 3 Pi 27 Pi 2 (-8 + 25 Pi ) Sin[5 Pi x] ------------------------- 3 125 Pi ^*)