Matlab and Fourier Series (Due Mon 9/16)
The objectives of this lab include plotting partial sums of Fourier series, calculating how
many terms are needed to approximate a function within a desired accuracy, and examining
the Gibbs phenomenon.
We will use the trigonometric form of Fourier series in this lab, rather than the complex
exponential form. In particular we will focus on the sine series, which can be used to
represent odd functions (or odd extensions of a function on a given interval, with period
twice the length of the interval). Suppose we want to approximate a function f (t) on the
interval [0, π]. The idea is to extend f (t) by defining f (t) = −f (−t) on [−π, 0], and then
periodically extending this function on [−π, π] with period 2π to the entire real line. This
leads to the following formula for the nth coefficient of the corresponding sine series:
Z
2 π
f (t) sin(kt)dt,
(1)
bk =
π 0
where
f (t) ∼
∞
X
bk sin(kt).
k=1
The use of ∼ is to remind us that this is a representation of the function that agrees with
the function at each point of continuity, but not necessarily at points of discontinuity.
The nth partial sum Sn of the sine series is defined by
Sn (t) =
n
X
bk sin(kt).
k=1
Instructions: Submit the three requested figures as .fig or .tif files. You can save figures by
clicking on File in the figure window, then choosing Save As and naming the file after the
corresponding exercise, e.g., JonesLab1Exercise1.fig. When finished with all three exercises,
email the three figure files as attachments to tleise@amherst.edu.
Exercise 1 Find the sine series coefficients for f (t) = 1 on [0, π] by hand using equation (1),
and then plot the nth partial sums of the sine series for n = 10, 20, 50 (all three graphs on
the same set of axes). Use a legend to label the curves: legend(‘n=10’,‘n=20’,‘n=50’).
Determine the largest overshoot of Sn (t) on [0,1] to three decimal places for each n as well
as where it occurs (closest to t=0), and add this information to the legend, so labels look
something like ‘n=10, max overshoot 0.123 at t=0.123’.
Hint on coding Matlab: You can use for loops to generate the coefficients and the partial
sums. For example,
b=zeros(50,1);
for k=1:50
b(k)=fill in formula ;
end t=0:0.01:pi;
S50=zeros(1,length(t));
for k=1:50
S50=S50+b(k)*sin(k*t);
end
plot(t,S50)
Here is a more parsimonious (but less obvious) approach to computing the partial sum:
S50=sum(repmat(b(1:50),1,length(t)).*sin((1:50)’*t))
The max command may also be helpful: [m, k]=max(x) gives the maximum value m in the
vector x as well as the corresponding index k, so t(k) would be the time at which the
maximum value occurred.
Exercise 2 The sine series coefficients for f (t) = t(π − t) are
4(1 − (−1)k )
.
bk =
k3π
Plot the nth partial sum of the sine series for n = 1, 3, 5 on the same plot as the function
itself. To plot the function f (t), use plot(t,t.*(pi-t)). Use a legend to identify the curves.
Determine the smallest value of n such that |f (t) − Sn (t)| < 0.001 for 0 ≤ t ≤ π. State
this value of n in the title to the figure: title(‘n=# is required to achieve pointwise
error < 0.001’).
Exercise 3 To compare the decay rates of the Fourier coefficients of the discontinuous
function in Exercise 1 and the continuous function in Exercise 2, plot the odd-numbered
coefficients of each sine series divided by the first coefficient, with a legend. That is, plot
bk /b1 for k = 1, 3, 5, ..., 49. (Note that the even-numbered coefficients of these two sine series
happen to be zero, due to the symmetry of the functions.)
Matlab and Fourier Series (Due Mon 9 16)
of 2
Report
Tell us what’s wrong with it:
Thanks, got it!
We will moderate it soon!
Free up your schedule!
Our EduBirdie Experts Are Here for You 24/7! Just fill out a form and let us know how we can assist you.
Take 5 seconds to unlock
Enter your email below and get instant access to your document