I have to define the function f
:
- π for x ∈ (-1,1)
- 0 for all the others.
How do I find the n-th coefficient of this function in the Fourier series expansion for (-3π, 3π)?
Define the function,
f[x_] := If[x < 1 && x > -1, \[Pi], 0]
or
f[x_] := Piecewise[{{\[Pi], x > -1 && x < 1}}, 0]
Do the series expansion, b=1/3
for the required region $(-3\pi,3\pi)$ (check documentation of FourierSeries and FourierParameters) for details, here choosing a=0
, and up to the 30th order
fx = FourierSeries[f[x], x, 30, FourierParameters -> {0, 1/3}];
You may plot it to see the approximation
Plot[fx, {x, -3 \[Pi], 3 \[Pi]}, PlotRange -> All]
and to collect the terms by order, use
fxc = Collect[fx, E^((I x)/3) ]
1/3 + E^(-((I x)/3)) Sin[1/3] + E^((I x)/3) Sin[1/3] + 1/2 E^(-((2 I x)/3)) Sin[2/3] + 1/2 E^((2 I x)/3) Sin[2/3] + 1/3 E^(-I x) Sin1 + 1/3 E^(I x) Sin1+... (truncated)
where you may then access each one by array index e.g. fxc[[3]]
(notice the grouping of negative and positive n)
Plot[fxc[[3]] // ReIm // Evaluate, {x, -3 \[Pi], 3 \[Pi]}]
$\endgroup$
Commented
Jan 23, 2019 at 19:44
FourierSeries
gives the whole series expansion, FourierCoefficient
outputs the coefficient before the $n$-th order $e^{int}$, so there's actually no difference. notice for the whole expansion, the n
in FourierCoefficient
goes from negative "cut" $-n_c$ to the positive $n_c$
$\endgroup$
Commented
Jan 24, 2019 at 15:20
This can be done as follows.
f[x_] := Piecewise[{{\[Pi], x > -1 && x < 1}}, 0];
FourierCoefficient[f[x], x, n, FourierParameters -> {1, 1/3}] // TeXForm
$$ \begin{cases} \frac{1}{3} & n=0 \\ \frac{\sin \left(\frac{n}{3}\right)}{n} & \text{True} \end{cases} $$
See Mathematica help to FourierCoefficient
for more info.
Piecewise
andIntegrate
in the documentation for proper syntax for defining piecewise-defined function and how to integrate functions. If not, perhaps you meant to ask this on Mathematics. $\endgroup$