Fourier Series of "Split" Defined Function - Mathematica Stack Exchange most recent 30 from mathematica.stackexchange.com 2019-10-17T04:25:19Z https://mathematica.stackexchange.com/feeds/question/40147 https://creativecommons.org/licenses/by-sa/4.0/rdf https://mathematica.stackexchange.com/q/40147 3 Fourier Series of "Split" Defined Function Erik Vesterlund https://mathematica.stackexchange.com/users/8558 2014-01-10T04:28:42Z 2014-01-10T05:32:44Z <p>Not sure how to phrase this in a concise way, anyway it seems like the function FourierSeries assumes the interval for which to compute the Fourier coefficients of a given function is $[-\pi,\pi]$, which is all well and good. But if the function $f$ is defined as $g$ on, say, $[-\pi,a)$ and as $h$ on $[a,\pi]$, is there a way to define $f$ this way so that one can apply FourierSeries immediately on $f$?</p> <p>Also, is there a way to make Mathematica understand that $\cos{n\pi}=(-1)^n$ and $\sin{n\pi}=0$?</p> https://mathematica.stackexchange.com/questions/40147/-/40148#40148 3 Answer by Nasser for Fourier Series of "Split" Defined Function Nasser https://mathematica.stackexchange.com/users/70 2014-01-10T04:58:34Z 2014-01-10T05:32:44Z <p>You examples are easy, I was hoping for harder ones ;) This is from the definition.</p> <pre><code>f3[x_] := Piecewise[{{1 - x^2 , x &lt; 0}, {1 + x^2, x &gt; 0}}]; FourierSeries[f3[x], x, 3] </code></pre> <p><img src="https://i.stack.imgur.com/JPS7B.png" alt="Mathematica graphics"></p> <p>A quick Manipulate:</p> <p><img src="https://i.stack.imgur.com/GyGAr.gif" alt="enter image description here"></p> <pre><code>Manipulate[ r = FourierSeries[f[x], x, n]; Show[Plot[r, {x, -2 Pi, 2 Pi}, Frame -&gt; True], Plot[f[x], {x, -2 Pi, 2 Pi}, PlotStyle -&gt; {Thick, Red}]], Grid[{ {Control[{{n, 3, "how many terms?"}, 1, 20, 1}], Dynamic[n]} }], ContinuousAction -&gt; False, SynchronousUpdating -&gt; True, Initialization :&gt; ( f[x_] := Piecewise[{{1 - x^2 , x &lt; 0}, {1 + x^2, x &gt; 0}}] ) ] </code></pre> <p><img src="https://i.stack.imgur.com/rTu0p.png" alt="Mathematica graphics"></p> <p>And if you meant them to be different functions:</p> <pre><code>f1[x_] := Piecewise[{{1 - x^2 , x &lt; 0}, {0, True}}]; f2[x_] := Piecewise[{{1 + x^2 , x &gt; 0}, {0, True}}]; FourierSeries[f1[x], x, 3] </code></pre> <p><img src="https://i.stack.imgur.com/8FfCb.png" alt="Mathematica graphics"></p> <pre><code>FourierSeries[f2[x], x, 3] </code></pre> <p><img src="https://i.stack.imgur.com/wQM2d.png" alt="Mathematica graphics"></p> <p>You can use the definition of the $c_k$ also by using <code>FourierParameters</code> to make it match the textbook you are using. So make sure to look at <code>FourierParameters</code> and adjust it as needed else you'll get different looking result from the textbook if the textbook does not use the default setting used by Mathematica.</p>