[genius] Fri Sep 05 17:47:03 2014 Jiri (George) Lebl <jirka 5z com>
- From: George Lebl <jirka src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [genius] Fri Sep 05 17:47:03 2014 Jiri (George) Lebl <jirka 5z com>
- Date: Fri, 5 Sep 2014 22:47:16 +0000 (UTC)
commit 6eec49911f1115f9f36e639865429c2fb7ecb530
Author: Jiri (George) Lebl <jiri lebl gmail com>
Date: Fri Sep 5 17:47:06 2014 -0500
Fri Sep 05 17:47:03 2014 Jiri (George) Lebl <jirka 5z com>
* tutors/fourier*.gel: add some fourier series tutors
ChangeLog | 4 ++
tutors/Makefile.am | 4 ++-
tutors/fourier-series-animation.gel | 33 ++++++++++++++++++++
tutors/fourier-series-half-sawtooth.gel | 51 +++++++++++++++++++++++++++++++
4 files changed, 91 insertions(+), 1 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 6e67334..a86561e 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+Fri Sep 05 17:47:03 2014 Jiri (George) Lebl <jirka 5z com>
+
+ * tutors/fourier*.gel: add some fourier series tutors
+
Fri Sep 05 15:25:28 2014 Jiri (George) Lebl <jirka 5z com>
* tutors/*: Add whole bunch of tutorials from what I've been using
diff --git a/tutors/Makefile.am b/tutors/Makefile.am
index af95a06..bd5bb35 100644
--- a/tutors/Makefile.am
+++ b/tutors/Makefile.am
@@ -15,7 +15,9 @@ tutor_DATA = \
standing-waves.gel \
strange-attractor.gel \
taylor-exp.gel \
- taylor-sin.gel
+ taylor-sin.gel \
+ fourier-series-animation.gel \
+ fourier-series-half-sawtooth.gel
EXTRA_DIST = \
$(tutor_DATA)
diff --git a/tutors/fourier-series-animation.gel b/tutors/fourier-series-animation.gel
new file mode 100644
index 0000000..d48e84a
--- /dev/null
+++ b/tutors/fourier-series-animation.gel
@@ -0,0 +1,33 @@
+# Category: Differential Equations
+# Name: Fourier series animation
+
+# The computation is 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...");
+
+for k = 1 to 2 do (
+for n = 1 to elements(hvals) do (
+ h = hvals@(n);
+ LinePlot(F, fs@(n))
+)
+)
diff --git a/tutors/fourier-series-half-sawtooth.gel b/tutors/fourier-series-half-sawtooth.gel
new file mode 100644
index 0000000..5715bf4
--- /dev/null
+++ b/tutors/fourier-series-half-sawtooth.gel
@@ -0,0 +1,51 @@
+# Category: Differential Equations
+# Name: Fourier series for a half-sawtooth function
+
+#
+# The fourier series was precomputed by hand
+#
+
+# The Fourier series up to nth harmonic
+function ffsn(x,n) = (
+ (1/4) +
+ sum k=1 to n do (
+ (1/(k*pi)^2)*((-1)^k - 1) * cos(k*pi*x) + ((-1)^(k+1)/(k*pi)) * sin(k*pi*x)
+ )
+);
+
+LinePlotWindow=[-2,2,-0.5,1.5];
+LinePlotDrawLegends=false;
+
+LinePlotClear();
+
+# Draw the graph by hand to correctly draw the gap
+LinePlotDrawLine([-2,0;-1,1],"thickness",2,"color","darkblue");
+LinePlotDrawLine([-1,0;0,0;1,1],"thickness",2,"color","darkblue");
+LinePlotDrawLine([1,0;2,0],"thickness",2,"color","darkblue");
+
+# Wait for 1 second before starting with the Fourier series
+wait(1);
+
+# Do first 20 harmonics
+for n=1 to 20 do (
+ # compute values and put in a vector instead of using the built in function grapher
+ v=null;
+ for x=-2 to 2 by 0.003 do
+ v=[v,[x,ffsn(x,n)]];
+
+ # Freeze, Thaw makes the animation smoother
+ PlotCanvasFreeze ();
+
+ LinePlotClear ();
+
+ # Draw the graph by hand to correctly draw the gap
+ LinePlotDrawLine([-2,0;-1,1],"thickness",2,"color","darkblue");
+ LinePlotDrawLine([-1,0;0,0;1,1],"thickness",2,"color","darkblue");
+ LinePlotDrawLine([1,0;2,0],"thickness",2,"color","darkblue");
+
+ # Plot the fourier series up to nth harmonic
+ LinePlotDrawLine(v,"thickness",2,"color","darkgreen");
+
+ PlotCanvasThaw();
+);
+
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]