[genius] Fri Sep 05 11:20:20 2014 Jiri (George) Lebl <jirka 5z com>



commit fb14d049080032e9a9368996eb2c0f469acb38df
Author: Jiri (George) Lebl <jiri lebl gmail com>
Date:   Fri Sep 5 11:20:37 2014 -0500

    Fri Sep 05 11:20:20 2014  Jiri (George) Lebl <jirka 5z com>
    
        * tutors/cantor.gel: Add Cantor's staircase tutorial

 ChangeLog         |    4 ++++
 tutors/cantor.gel |   31 +++++++++++++++++++++++++++++++
 2 files changed, 35 insertions(+), 0 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 3aea396..9a40d11 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+Fri Sep 05 11:20:20 2014  Jiri (George) Lebl <jirka 5z com>
+
+       * tutors/cantor.gel: Add Cantor's staircase tutorial
+
 Fri Sep 05 01:52:10 2014  Jiri (George) Lebl <jirka 5z com>
 
        * tutors/*: add a simple strange-attractor tutorial
diff --git a/tutors/cantor.gel b/tutors/cantor.gel
new file mode 100644
index 0000000..333ecdc
--- /dev/null
+++ b/tutors/cantor.gel
@@ -0,0 +1,31 @@
+# Category: Analysis
+# Name: Cantor's devil staircase function (approximation)
+
+function Ternary(x,n) = (
+    # only if x in [0,1)
+    out = null;
+    for k = 1 to n do (
+        x = x*3;
+        fx = floor (x);
+        x = FractionalPart (x);      
+        out = [out, fx]
+    )
+);
+
+# Cantor function, only really for x in [0,1]
+function Cantor(x) = (
+    if x >= 1 then return 1;
+    if x <= 0 then return 0;
+    # Number of steps, the higher the number the more precise the graph
+    n = 20;
+    t = Ternary(x,n);
+    N = n;
+    for k = 1 to n do (
+        if t@(k) == 1 then
+            (N = k; break)
+    );
+
+    1/(2^N) + sum k = 1 to (N-1) do (t@(k)/(2^(k+1)))
+);
+
+LinePlot(Cantor,[0,1]);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]