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



commit 3bf79d3b98c34f8ed9fcf25639d8dab8c88c8207
Author: Jiri (George) Lebl <jiri lebl gmail com>
Date:   Fri Sep 5 12:56:07 2014 -0500

    Fri Sep 05 12:56:05 2014  Jiri (George) Lebl <jirka 5z com>
    
        * tutors/*.gel: Add a few more tutorials (lorenz, finite difference
          method, standing waves)

 ChangeLog                 |    5 ++++
 tutors/Makefile.am        |    5 +++-
 tutors/laplace-fdm.gel    |   51 +++++++++++++++++++++++++++++++++++++++++++++
 tutors/lorenz.gel         |   37 ++++++++++++++++++++++++++++++++
 tutors/standing-waves.gel |   21 ++++++++++++++++++
 5 files changed, 118 insertions(+), 1 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 9a40d11..b53953d 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+Fri Sep 05 12:56:05 2014  Jiri (George) Lebl <jirka 5z com>
+
+       * tutors/*.gel: Add a few more tutorials (lorenz, finite difference
+         method, standing waves)
+
 Fri Sep 05 11:20:20 2014  Jiri (George) Lebl <jirka 5z com>
 
        * tutors/cantor.gel: Add Cantor's staircase tutorial
diff --git a/tutors/Makefile.am b/tutors/Makefile.am
index 916dc88..a63c321 100644
--- a/tutors/Makefile.am
+++ b/tutors/Makefile.am
@@ -2,6 +2,9 @@ tutordir = \
        $(datadir)/genius/tutors/
 tutor_DATA = \
        strange-attractor.gel \
-       cantor.gel
+       cantor.gel \
+       laplace-fdm.gel \
+       lorenz.gel \
+       standing-waves.gel
 EXTRA_DIST = \
        $(tutor_DATA)
diff --git a/tutors/laplace-fdm.gel b/tutors/laplace-fdm.gel
new file mode 100644
index 0000000..18d0f92
--- /dev/null
+++ b/tutors/laplace-fdm.gel
@@ -0,0 +1,51 @@
+# Category: Differential Equations
+# Name: Laplace equation solution using Finite Difference Method
+
+points = 25;
+
+# zero initial guess
+u = zeros(points+1,points+1);
+
+# how about random initial guess
+#u = 2*rand(points+1,points+1)-ones(points+1,points+1);
+
+# initial guess of -1s, that's actually somewhat slow to converge
+#u = -ones(points+1,points+1);
+
+# The side conditions
+for n=1 to points+1 do
+  u@(n,1) = -sin(pi*(n-1)/points);
+for n=1 to points+1 do
+  u@(n,points+1) = sin(2*pi*(n-1)/points);
+for n=1 to points+1 do
+  u@(1,n) = 0.5*sin(pi*(n-1)/points);
+for n=1 to points+1 do
+  u@(points+1,n) = 0;
+
+# don't draw the legend
+SurfacePlotDrawLegends = false;
+
+# plot the data
+SurfacePlotDataGrid(u,[0,pi,0,pi]);
+# If you want to export the animation to a sequence of .png
+# images uncomment here and below
+#ExportPlot ("animation" + 0 + ".png");
+
+for n = 1 to 300 do (
+  wait (0.1);
+
+  maxch = 0;
+  for i=2 to points do (
+    for j=2 to points do (
+      old = u@(i,j); 
+      u@(i,j) = (1/4)*(u@(i-1,j)+u@(i+1,j)+u@(i,j-1)+u@(i,j+1));
+      if |u@(i,j)-old| >  maxch then
+        maxch = |u@(i,j)-old|
+    )
+  );
+  print("Maximum change: " + maxch + " (iteration " + n + ")");
+
+  # plot the data
+  SurfacePlotDataGrid(u,[0,pi,0,pi]);
+  #ExportPlot ("animation" + n + ".png");
+);
diff --git a/tutors/lorenz.gel b/tutors/lorenz.gel
new file mode 100644
index 0000000..a536d68
--- /dev/null
+++ b/tutors/lorenz.gel
@@ -0,0 +1,37 @@
+# Category: Chaos
+# Name: Lorenz attractor
+#
+# We draw a trajectory of the Lorenz system to exhibit the chaotic behavior.
+# The trajectory will get close to the Lorenz attractor, so we can see how
+# it looks.
+
+
+# The Lorenz system (try playing around with the constants,
+# especially the 28)
+function lorenz(t,x) = [10*(x@(2)-x@(1)),
+                                         x@(1)*(28-x@(3))-x@(2),
+                                         x@(1)*x@(2)-(8/3)*x@(3)];
+
+# The [1,1,20] is an initial condition, try playing around with it,
+# the 15 is the time to follow a trajectory, 10000 is the number of
+# steps to do
+pt = RungeKuttaFull(lorenz,0,[1,1,20],15,10000);
+
+# Flatten the matrix so that rows are the [t,x@(1),x@(2),x@(3)]
+pt = ExpandMatrix (pt);
+
+SurfacePlotDrawLegends = false;
+# SurfacePlotDrawLine doesn't clear the 3D canvas, so we must do it
+# manually
+SurfacePlotClear ();
+# Note that we are picking out just the x coordinates
+SurfacePlotDrawLine (pt@(,2:4), "color", "blue", "window", "fit");
+
+
+#You could also draw perhaps the components of x against time in a line plot.
+# To do so, uncomment the following lines
+#LinePlotClear();
+#LinePlotWindow = [0,15,-25,50];
+#LinePlotDrawLine(pt@(,[1,2]),"color","blue","legend","x1");
+#LinePlotDrawLine(pt@(,[1,3]),"color","red","legend","x2");
+#LinePlotDrawLine(pt@(,[1,4]),"color","green","legend","x3");
diff --git a/tutors/standing-waves.gel b/tutors/standing-waves.gel
new file mode 100644
index 0000000..1b4b471
--- /dev/null
+++ b/tutors/standing-waves.gel
@@ -0,0 +1,21 @@
+# Category: Differential Equations
+# Name: Standing Waves
+
+the_answer = AskButtons("Number of dimensions?", "2D", "3D");
+
+if the_answer == 1 then (
+    LinePlotDrawLegends = false;
+
+    for t=1 to 100 by 0.1 do (
+        LinePlot(`(x)=cos(t)*sin(x),[-5,5,-2,2]);
+        wait (0.05)
+    )
+) else if the_answer == 2 then (
+    SurfacePlotDrawLegends = false;
+
+    for t=1 to 100 by 0.1 do (
+        SurfacePlot(`(x,y)=cos(t)*sin(x-y),[-5,5,-2,2,-1,1])
+    )
+)
+
+


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