File: fourier-series-animation.gel

package info (click to toggle)
genius 1.0.24-2
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 27,952 kB
  • sloc: ansic: 105,597; xml: 67,672; sh: 4,537; makefile: 2,089; lex: 499; yacc: 298; perl: 54; python: 22
file content (39 lines) | stat: -rw-r--r-- 984 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# Category: Differential Equations
# Name: Fourier series animation (Gibbs phenomenon)
#
# Animation where a discontinuity appears and disappears to exhibit
# Gibbs phenomenon
#

# The computation can be slow, so be patient when running...

# The function (h is a parameter)
function F(x) = (
    while x < -pi do increment x by 2*pi;
    while x > pi do increment x by -2*pi;
  
    if x < 0 then 2*h*(x+pi/2)/pi else 2-h
);
  
  
LinePlotWindow=[-pi*1.1,pi*1.1,-3,3];
LinePlotDrawLegends=false;

# For faster animation, precompute,
print("Precomputing Fourier Series...");
hvals = [0.0:0.1:2.0,2.0:-0.1:0.0];
for n=1 to elements(hvals) do (
    h = hvals@(n);
    printn (n + "/" + elements(hvals) + "...");
    fs@(n) = NumericalFourierSeriesFunction (F, pi, 10);
);
print("Done... Starting animation...");

PlotWindowPresent(); # Make sure the window is raised

for k = 1 to 10 do (
    for n = 1 to elements(hvals) do (
        h = hvals@(n);
        LinePlot(F, fs@(n))
    )
)