I am working on Fourier Analysis and need to implement Fourier Series in MATLAB. What I want is to do the following:
- Obtain the Fourier Coefficients as a function of n, $a(n)$, so that whenever I input say n=2, I get the numeric value of a(2). I need an analytical expression for $a(n)$ something like for example $a(n) = \frac{1}{1+n}, n \in \mathbb{N}$.
Let $f \in L^{2}[0,1], $ and we are working with the standard orthonormal basis $\{\sqrt2 sin (2k \pi x)\}_{n=1}^{\infty} \cup \{\sqrt2 cos (2k \pi x)\}_{n=1}^{\infty} \cup \{1\}$
The problem that I am facing with implementing the partial integration in the following step
$a(n) := \int_{0}^{1} f(x).e_{n}(x) dx$
where $e_{n}(x)$ is $\sqrt2 sin (2n \pi x), \sqrt2 cos (2n \pi x)$ or 1.
So for example we take $e_n(x) = \sqrt2 cos(2n\pi x)$. Let $g(n,x) = f(x).\sqrt2 cos(2n\pi x)$. How do I get the expression for $a(n)$ i.e.,
$a(n) = \int_{0}^{1} g(n,x) dx$ ?
I want to be able to give n as input to $a(n)$ and obtain the nth Fourier coefficient, $n \in \mathbb{N}$.
Now the things that I have tried are the following,
f = @(x)x;
g = @(n,x)(f(x).*cos(2n$\pi$x));
a_n = @(n)integral(@(x)g,0,1);
So then if I try to obtain a_n(2), I get the following error
Error using integralCalc/finalInputChecks (line 511) Input function must return 'double' or 'single' values. Found 'function_handle'.
Error in integralCalc/iterateScalarValued (line 315) finalInputChecks(x,fx);
Error in integralCalc/vadapt (line 133) [q,errbnd] = iterateScalarValued(u,tinterval,pathlen);
Error in integralCalc (line 76) [q,errbnd] = vadapt(@AtoBInvTransform,interval);
Error in integral (line 89) Q = integralCalc(fun,a,b,opstruct);
Error in @(n)integral(@(x)g,0,1)
Thanks for reading my question.
You may try something like this:
which produces $$\frac{1}{2n^2\pi^2} \enspace. $$