1. Exercise 1 (```sinesum.py```) Approximating a function by a sum of sines (vie
ID: 3883108 • Letter: 1
Question
1. Exercise 1 (```sinesum.py```)
Approximating a function by a sum of sines
(view image for better formatting)
*Idea:* Any function can be approximated arbitrarily well by a sum of sines. (This is known as a Fourier series expansion of the original function.) Consider the following piecewise function defined in the interval $tin[-T/2,T/2]$:
$$f(t) = egin{cases}
1, & 0 < t < T/2 \
0, & t = T/2 \
-1, & -T/2 < t < 0
end{cases}$$
It can be shown that the following sum converges to $f(t)$ as $n oinfty$:
$$S_n(t) = rac{4}{pi}sum_{k=1}^n rac{1}{2k-1} sinleft(rac{2(2k-1)pi t}{T} ight)$$
We wish to show numerical evidence for this convergence.
(a) Create a function `s(t,n)` that computes the sum $S_n(t)$ defined above.
(b) Create a function `f(t)` that computes the function $f(t)$ defined above.
(c) In your Jupyter notebook `hw2.ipynb`, compute and show lists that illustrate how the error $epsilon_n(t) equiv f(t) S_n(t)$ varies with $n$ and $t$. Use the cases $n = 1, 3, 5, 10, 30, 100$ and $t = lpha T$, with $T = 2pi$ and $lpha = 0.01, 0.25, 0.49$. Use the computed lists to comment on how the quality of the approximation of $f$ by $S_n$ depends on $lpha$ and $n$.
Explanation / Answer
syms x f = exp(-2*x^2); %our function ezplot(f,[-2,2]) % plot of our function FT = fourier(f) % Fourier transform
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.