Beruflich Dokumente
Kultur Dokumente
u(x) v(x) dx
Compute the expansion coefficients
With the inner product defined, we can compute the Fourier coefficients for a function "func". Note the use of
deferred evaluation.
fourierCoefffunc, m : fourierIPfuncx, m, xfourierIPm, x, m, x
Show the general form of the Fourier coefficient:
fourierCoeff, m
cos(m x) (x) dx
sin(2 m)
2 m
+
Sum terms through order M
Here we define a function that computes the M-th partial sum of the Fourier series.
fourierSeriesM, func, x : SumfourierCoefffunc, mCosm x, m, 0, M
fourierSeriesM, , x
`
m=0
M
cos(m x)
1
cos(m x) (x) dx
sin(2 m)
2 m
+
At this point, were ready to go!
Example: Fourier series for a triangle wave
Define an expression for the function we want to expand in a Fourier series
Well approximate a triangle wave by a Fourier series. First we define an expression for one period of a triangle
wave.
triangleWavex Piecewise1 AbsxPi, Absx Pi
1
|x|
|x| s
Heres what the function looks like.
2 Fourier1.nb
PlottriangleWavex, x, 4Pi, 4Pi, PlotRange All
10 5 5 10
0.2
0.4
0.6
0.8
1.0
Well also want to see the periodic extension. The following function will replicate the triangle pulse over
several periods.
periodicExtensionfunc, nPeriods : Sumfuncx 2k Pi, k, nPeriods, nPeriods
Now we can plot a few periods of the triangle wave:
PlotperiodicExtensiontriangleWave, 4, x, 4Pi, 4Pi, PlotRange All
10 5 5 10
0.2
0.4
0.6
0.8
1.0
Compute the fourier series for the triangle wave
Lets first look at the Fourier coefficients.
fourierCoefftriangleWave, m
2 (cos(m) 1)
m
2
|
sin(2 m)
2 m
+ |
Next, compute the 2nd, 4th, and 16th partial sums:
fs2x fourierSeries2, triangleWave, x
4 cos(x)
2
+
1
2
Fourier1.nb 3
fs4x fourierSeries4, triangleWave, x
4 cos(x)
2
+
4 cos(3 x)
9
2
+
1
2
fs16x fourierSeries16, triangleWave, x
4 cos(x)
2
+
4 cos(3 x)
9
2
+
4 cos(5 x)
25
2
+
4 cos(7 x)
49
2
+
4 cos(9 x)
81
2
+
4 cos(11 x)
121
2
+
4 cos(13 x)
169
2
+
4 cos(15 x)
225
2
+
1
2
We can plot the partial sums against x.
Plotfs2x, fs4x, fs16x, x, Pi, Pi
3 2 1 1 2 3
0.2
0.4
0.6
0.8
1.0
To see how the accuracy improves with increasing number of terms, plot the difference between the series and
the exact triangle wave:
Plotfs2x triangleWavex,
fs4x triangleWavex, fs16x triangleWavex, x, Pi, Pi
3 2 1 1 2 3
0.04
0.02
0.02
0.04
Finally, plot the Fourier series over several periods, to show that it automatically "builds in" the periodic exten-
sion of the square wave.
4 Fourier1.nb
Plotfs2x, fs16x, x, 6Pi, 6Pi
15 10 5 5 10 15
0.2
0.4
0.6
0.8
1.0
Fourier1.nb 5