Grundvereinbarungen

schwarz = GrayLevel[0];
dick = Thickness[0.008];
$DefaultFont = {"Arial", 12};

Definition der Rechteckfunktion

Clear[f, a, T, ord]
a = 1;
T = 4 a;
ord = 11;
A = 1;

f[t_] := f[t + T] /; t ≤ -a
f[t_] := A /; t > -a && t ≤ a
f[t_] := 0 /; t > a && t ≤ 3 a
f[t_] := f[t - T] /; t > T - a

\(\(Plot[
        f[t] // Evaluate, {t, \(-a\)\ 1.1, 
          3  a\ 1.1}, \ 
PlotPoints -> 
          500, 
Ticks -> {\ 
            Table[{k\ a, ToString[k] <> "a"}, {k, \(-1\), 
                3}], {0, {A, "A"}}}, 
PlotStyle -> {dick, schwarz}, 
PlotRange -> {\(\(-2\)\/π\) 1.1, 
            1.25  A}, 
PlotLabel -> \ "Rechteckfunktion"];\)\)

Berechnung der Fourier-Koeffizienten

gleichAnteil = (( 2 a A)/T)

komplexKoeff = (1/T) (∫_(-a)^a) 
              A Exp[- I  Range[
                    ord] ((2  π)/T) t] \[DifferentialD]t // 
        ComplexExpand

summandenListe = 
        2 Re[komplexKoeff*
                Exp[I Range[
                      Length[komplexKoeff]] ((2 π)/T) t]] // 
          ComplexExpand;
PrependTo[summandenListe, gleichAnteil]

poly = Apply[Plus, Take[summandenListe, ord]]

Zeichnung der Animation

ordList = {0, 1, 3, 5, 7, 9} + 1;
\(\(bilderAnimation = 
        Table[Show[
            GraphicsArray[{

Plot[{Take[
                        summandenListe, 
                        n = ordList[[
                            l]]], f[t]} // 
                    Evaluate, {t, \(-a\)\ 1.1, 
                    3  a\ 1.1}, \ 
PlotPoints -> 
                    100, 
Ticks -> {\ 
                      Table[{k\ a, ToString[k] <> "a"}, {k, \(-1\), 
                          3}], {0, {A, "A"}}}, 
PlotStyle -> 
                    Join[Table[{dick, Hue[\(k - 1\)\/ord, 1, 1/2]}, {k, 
                          n}], {{dick, 
                          schwarz}}], 
PlotRange -> {\(\(-2\)\/π\) 1.1, 
                      1.25  A}, 
PlotLabel -> "Einzelne Summanden  bis zur Ordnung " <> ToString[n - 1], 
                  DisplayFunction -> 
                    Identity], 

Plot[{Apply[Plus, 
                        Take[summandenListe, 
                          n = ordList[[
                              l]]]], f[t]} // 
                    Evaluate, {t, \(-a\)\ 1.1, 
                    3  a\ 1.1}, \ 
PlotPoints -> 
                    50, 
Ticks -> {\ 
                      Table[{k\ a, ToString[k] <> "a"}, {k, \(-1\), 
                          3}], {0, {A, "A"}}}, 
PlotStyle -> {{dick, 
                        Hue[\(n - 1\)\/ord, 1, 1/2]}, {dick, 
                        schwarz}}, 
PlotRange -> {\(\(-2\)\/π\) 1.1, 
                      1.25  A}, 
PlotLabel -> "Überlagerung", 
                  DisplayFunction -> 
                    Identity]

}]], 
{l, 1, Length[ordList]}];\)\)

Zeichnung der Einzelbilder

bilder = 
        Show[GraphicsArray[
            Partition[Drop[Drop[bilderAnimation, {1}], {-1}], 
              1]]];

Fourier-Polynom der Ordnung 99

\(\(f99 = 
        Plot[{gleichAnteil + \(4\/T\) \(∑\+\(k = 1\)\%99\(\(\(\ \)\(Sin[\(k\ π\)\/2]\)\)\/\(k\ π\)\) 2 
                       Re[Exp[I\ k\ \(\(2\ π\)\/T\) t]]\), 
              f[t]} // Evaluate, {t, \(-a\)\ 1.1, 
            3  a\ 1.1}, \ 
PlotPoints -> 
            500, 
Ticks -> {\ 
              Table[{k\ a, ToString[k] <> "a"}, {k, \(-1\), 
                  3}], {0, {A, "A"}}}, 
PlotStyle -> {{Hue[0, 1, 
                  1/2]}, {schwarz}}, 
PlotRange -> {\(\(-2\)\/π\) 1.1, 
              1.25  A}, 
PlotLabel -> \ "Ordnung  n = 99"];\)\)

Speicherung der Grafiken als Gif-Dateien

Setzt das Standard-Verzeichnis in das Verzeichnis, in dem das Notebook gespeichert ist:

\(NotebookPath\  := \ 
      Module[{tmp}, 
		tmp = "FileName" /. 
            NotebookInformation[SelectedNotebook[]]; 
		Switch[tmp, 
          FrontEnd`FileName[__], ToFileName[First[tmp]], _, 
          Directory[]]]\)
SetDirectory[NotebookPath]

ratio = 
        FullOptions[bilderAnimation[[1]], 
          AspectRatio];
size = 700;
Export["fourier-ani.gif", bilderAnimation, "GIF", 
      ImageSize -> {size, size*ratio}, 
      ConversionOptions -> {"AnimationDisplayTime" -> 
            2, "Loop" -> True}]

ratio = FullOptions[bilder, AspectRatio];
size = 700;
Export["fourier.gif", bilder, "GIF", 
      ImageSize -> {size, size*ratio}]

ratio = FullOptions[f99, AspectRatio];
size = 500;
Export["f99.gif", f99, "GIF", 
      ImageSize -> {size, size*ratio}]