EGM 3344
Summer 2025
Introduction to Numerical Methods of Engineering Analysis
University of Florida
Mechanical and Aerospace Engineering
Homework 8: Size Matters Not; Look at My Code; Judge It by Its Size Do You?
Hmm? Hmm. And Well You Should Not, for My Ally is MATLAB, and a Powerful
Ally It is
Due: Tuesday, August 5, 2025, 11:59pm.
Instructions:
1. Submit your solutions as a PDF document on Canvas.
2. Include any and all plots in the PDF.
3. Also submit your individual .m files.
4. Do not submit a zipped file.
5. Make sure to add axis labels and legends to all plots.
6. You may use MATLAB’s fft function for problems 5-8.
7. Remember to use a superfluous amount of comments!
Problem 1: Compute by hand the continuous Fourier coefficients for the triangle wave described by
the following equation and shown in Figure 1. That is, derive the formula for a0 , ak ,
and bk for:
A − 4At
0 ≤ t < T2
T ,
.
f (t) =
4At
T
A+ T , −2 ≤ t < 0
Hint: Integration by parts(!).
Note: In the formulas for a0 , ak , and bk from class, we wrote the integral from 0 to T .
Because the function is periodic, we can take the integral anywhere we want, as long
as it has a total length of T . E.g., from −T to 0, from πT to (π + 1)T , or even . . . from
− T2 to T2 .
Solution to Problem 11 : First, we have
"Z
#
Z T 0 2
1
4At
4At
a0 =
A+
dt +
A−
dt
T
T
T
0
− T2
1
−AT
AT
AT
AT
=
0+0−
−
+
−
−0+0
T
2
2
2
2
= 0.
1
Note to self: do not forget to remove this from the PDF before releasing it to the students.
Jonathan Brooks
1
EGM 3344
Summer 2025
+A
t
-T
T
2
0
T
2
T
-A
Figure 1: Triangle wave for problem 1
Next, we have
Z
Z T 2
2 0
4At
4At
2
ak =
A−
A+
cos(kω0 t)dt +
cos(kω0 t)dt
T −T
T
T 0
T
2
Z 0 Z T 2A 2
4t
2A
4t
cos(kω0 t)dt +
1−
cos(kω0 t)dt
=
1+
T −T
T
T 0
T
"Z 2 #
Z T 0
2
2A
4t
4t
=
cos(kω0 t) − cos(kω0 t) dt
cos(kω0 t) + cos(kω0 t) dt +
T
T
T
− T2
0
"Z T
#
Z T
Z 0
2
2 4t
4t
2A
cos(kω0 t)dt −
cos(kω0 t)dt
=
cos(kω0 t)dt +
T
T
− T2
− T2 T
0
"
#
Z 0
Z T
2
8A
= 2 0+
t cos(kω0 t)dt .
t cos(kω0 t)dt −
T
−T
0
2
Using integration by parts, we have
Z b
b
1
a
1
t cos(kω0 t)dt =
sin(kω0 b) + 2 2 cos(kω0 b) −
sin(kω0 a) − 2 2 cos(kω0 a).
kω0
kω0
k ω0
k ω0
a
Substituting this into our equation, we get
8A
0
1
T
kω0 T
1
kω0 T
sin(0) + 2 2 cos(0) +
sin −
− 2 2 cos −
ak = 2
T
kω0
2kω0
2
2
k ω
k ω0
0 T
kω0 T
1
kω0 T
0
1
−
sin
+ 2 2 cos
−
sin(0) − 2 2 cos(0)
2kω0
2
2
kω0
k ω0
k ω0
8A
T
kω0 T
1
kω0 T
1
= 2
+
sin −
− 2 2 cos −
2
2
T
2kω0
2
2
k ω0
k ω0
T
kω0 T
1
kω0 T
1
−
sin
+ 2 2 cos
− 2 2
.
2kω0
2
2
k ω0
k ω0
Jonathan Brooks
2
EGM 3344
Summer 2025
Now from T = 2π/ω0 , we have that T ω0 = 2π, so
1
T
1
8A
+
sin(−kπ) − 2 2 cos(−kπ)
ak = 2
T
k 2 ω02 2kω0
k ω0
T
1
1
−
sin(kπ) + 2 2 cos(kpi) − 2 2
2kω0
k ω0
k ω0
1
1
8A
= 2 2 2 + 0 − 2 2 cos(−kπ)
T k ω0
k ω0
1
1
− 0 − 2 2 cos(kpi) + 2 2
k ω0
k ω0
2
2
8A
= 2 2 2 − 2 2 cos(−kπ)
T k ω0
k ω0
16A
= 2 2 2 [1 − cos(kπ)]
T k ω0
4A
= 2 2 [1 − cos(kπ)] .
k π
Finally, we may observe that this simplifies to
8A
, k odd
k2 π 2
ak =
0,
k even
Similarly, for bk , we have
Z 0 Z T 2
4At
4At
2
A−
A+
sin(kω0 t)dt +
sin(kω0 t)dt
T
T 0
T
− T2
Z
Z T 4t
2A 2
4t
2A 0
1+
sin(kω0 t)dt +
1−
sin(kω0 t)dt
=
T −T
T
T 0
T
"Z 2 #
Z T 0
2
2A
4t
4t
=
sin(kω0 t) + sin(kω0 t) dt +
sin(kω0 t) − sin(kω0 t) dt
T
T
T
− T2
0
"Z T
#
Z 0
Z T
2
2 4t
2A
4t
=
sin(kω0 t)dt +
sin(kω0 t)dt −
sin(kω0 t)dt
T
T
− T2
− T2 T
0
"
#
Z 0
Z T
2
8A
= 2 0+
t sin(kω0 t)dt −
t sin(kω0 t)dt .
T
−T
0
2
bk =
T
2
Using integration by parts, we have
Z b
t sin(kω0 t)dt = −
a
Jonathan Brooks
b
1
a
1
cos(kω0 b) + 2 2 sin(kω0 b) +
cos(kω0 a) − 2 2 sin(kω0 a).
kω0
kω0
k ω0
k ω0
3
EGM 3344
Summer 2025
Substituting this into our equation, we get
0
1
−T
kω0 T
1
kω0 T
8A
−
cos(0) + 2 2 sin(0) +
cos −
− 2 2 sin −
bk = 2
T
kω0
2kω0
2
2
k ω
k ω0
0 kω0 T
1
0
1
kω0 T
T
cos
+ 2 2 sin
+
cos(0) − 2 2 sin(0)
− −
2kω0
2
2
kω0
k ω0
k ω0
8A
T
kω0 T
1
kω0 T
= 2
−
cos
+ 2 2 sin
T
2kω0
2
2
k ω
0
kω0 T
1
T
kω0 T
cos
+ 2 2 sin
− −
2kω0
2
2
k ω0
= 0.
Problem 2: Write a MATLAB function called tri_fourier.m to compute the Fourier-series approximation for the triangle wave in problem 1 (using your answer from problem 12 ).
The number of sinusoidal frequencies used in the Fourier series (m), the fundamental
frequency (ωo ), and time (t) should be the inputs to the function, and the approximated
triangle-wave values should be the output.
Use your function to plot the approximate triangle wave for 1 frequency, 3 frequencies,
10 frequencies, and 1,000 frequencies (make sure your step size is small enough); use
ωo = 1, A = 1, and t ∈ [−10, 10]. (You do not need to submit code for the plotting
part, but be sure to include your figure in your PDF, and remember axis labels and
legend.)
Discuss your results—what is the trend as the number of included frequencies increases?
5 bonus points: Do not use any loops or if statements in your function. (Hint: create
a vector for your ak values, then create a matrix of cosine values by which to multiply
it.)
Hint for the bonus: Look up “outer products.”
Problem 3: Show (by hand) that the only nonzero Fourier coefficient of f (t) = C sin(ωt) is b1 = C.
Show your work—do not simply plug a troublesome integral into your calculator. You
may invoke trigonometric identities.
Hint: For each of ak and bk , consider the case k = 1 and k ̸= 1 separately. When
k ̸= 1, the integration
is not bad. When k = 1, note that we get cos (1 − 1)ωt and/or
sin (1−1)ωt , which will result in a division by 0.
Rather than attempting to integrate
in that form, consider the fact that cos (1−1)ωt = cos(0) and sin (1−1)ωt = sin(0),
and you are integrating that from 0 to T .
Extra Hint: Remember that ωo = 2π
T or alternatively ωo T = 2π.
Problem 4: Plot the following three curves in the same plot using MATLAB3 , from t = 0 to t = 8π
(in seconds):
2
That is, you are not having MATLAB do integrals. You already did the integrals yourself. Now you are putting the
result of that work into MATLAB.
3
You do not need to submit a .m file for this problem.
Jonathan Brooks
4
EGM 3344
Summer 2025
a) y1 (t) = 0.1 sin (0.25t),
b) y2 (t) = 0.01 sin (5t),
c) y3 (t) = y1 (t) + y2 (t).
Note: Yes, it is as easy as it sounds.
Problem 5: Note: Before actually completing this problem, first think about what you expect the
plots to look like4 .
Using the fft function, write a MATLAB script called hw8_p5.m to compute the DFT
for y3 (t) from problem 4 and use MATLAB’s stem function to plot the magnitude of
the DFT as a function of regular frequency (i.e., frequency in Hz). Use 4 different
samplings of y3 (t):
a) t = 0 : 0.01 : 8π,
b) t = 0 : 0.01 : 12π,
c) t = 0 : 0.01 : 16π,
d) t = 0 : 0.01 : 60π.
Discuss your results: What do the plots have in common, and why does this make
sense?
Note: There are differences between the plots, and the reasons for those differences
are very interesting, but you are only required to explain the similarities.
Suggestion: Use xlim to zoom in on the frequency axis to get a better view of the
frequencies close to 0.
Problem 6: Let us return once again to our coronavirus data. Because of the way that reporting
works over the weekend, there is a cyclical nature of the reported cases with a period
of one week.
Use fft to compute the DFT of the daily reported coronavirus cases from the data file
hw8_p6.mat, and use MATLAB’s stem function to plot the magnitude of the DFT as
a function of regular frequency. (You do not need to submit code for this problem.)
Recommendation: Plot the frequency axis in units of cycles per week, i.e., 1/weeks.
Discuss your results: Is there notable frequency content with weekly periods? What
does the first initial spike in the DFT denote?
Problem 7: Our rover is equipped with a radio telescope to search for extraterrestrial life in the
cosmos. The microwave background radiation is a constant radio “buzz” across a
wide range of frequencies that can be measured in all directions. This background
radiation means that no matter where the points its telescope, there will always be
some background noise in its radio measurements, and that noise will have content
in nearly all frequencies. A sign of extraterrestrial communication would be a radio
4
Think about the GIF from class, and think about problem 3.
Jonathan Brooks
5
EGM 3344
Summer 2025
signal with significantly higher content at a particular frequency (e.g., 30 times higher
than the content in other frequencies). At one point, the rover’s telescope was directed
at the constellation Sagittarius, when it collected the data contained in hw8_p7.mat,
where time is measured in seconds.
Use fft to compute the DFT of the signal measured by the telescope, and use MATLAB’s stem function to plot the magnitude of the DFT as a function of regular frequency. (You do not need to submit code for this problem.)
Discuss your results: Is there any evidence of extraterrestrial life in the data sample?
Problem 8: Shai-Hulud are large worms indigenous to the desert planet, Arrakis5 . They live underground, sensing prey through rhythmic vibrations in the sand caused by prey walking
on the surface. Human-sized and human-shaped humanoids tend to walk with a step
frequency of approximately 2 Hz. Thus, the sandworms lurk underground listening
for strong vibrations with a frequency of 2 Hz. The Fremen—the native people of
Dune—have learned to mask their movements by walking without rhythm, i.e., they
walk in a way that spreads their movements across all frequencies, whereas an untrained
non-Fremen person would walk at 2 Hz.
The data files, hw8_p8a.mat and hw8_p8b.mat, contain vibration measurements from
the dunes of Arrakis6 . Use fft to compute the DFT of each measured signal, and use
MATLAB’s stem function to plot the magnitude of the DFT as a function of regular
frequency. (You do not need to submit code for this problem.)
Discuss your results: Which data were measured near a Fremen sietch and which
data were measured near the Outworlder capital of Arrakeen.
5
6
Also known as Dune.
Time is measured in seconds.
Jonathan Brooks
6