Commit bd06c860 authored by Felipe Sateler's avatar Felipe Sateler

Imported Upstream version 1.0.19

parents 316f08cb 89819169
Tue Sep 23 12:10:49 2014 Jiri (George) Lebl <jirka@5z.com>
* Release 1.0.19
Mon Sep 22 14:41:46 2014 Jiri (George) Lebl <jirka@5z.com>
* lib/number_theory/primes.gel: I was misunderstanding the GIMPS
output on doublechecked exponents, leading to an incredibly
miniscule chance of reporting the wrong result on the least
non-double-checked exponent (in case the double check would prove
the initial LL wrong)
Mon Sep 22 13:17:18 2014 Jiri (George) Lebl <jirka@5z.com>
* src/examples.c, gtkextra/*.c: fix compiler warnings. Also fix an
overuse of strlen, won't really improve performance, but I find
using "strlen(s) == 0" just annoying enough to make me change it
anyhow
Thu Sep 18 17:52:37 2014 Jiri (George) Lebl <jirka@5z.com>
* src/gnome-genius.c: Fix tab reordering, and add the close button
code that was commented out (i.e. make it work)
Wed Sep 17 00:08:16 2014 Jiri (George) Lebl <jirka@5z.com>
* src/graphing.c: fix some typos, thanks to Wolfgang Stoeggl
Tue Sep 16 16:30:42 2014 Jiri (George) Lebl <jirka@5z.com>
* src/graphing.c: Fitting dependent axis doesn't work if no
function is selected, so just ignore fitting when size is negative
rather than doing undefined things. The whole thing is a mess,
we should allow fitting the lines that we draw and such I guess
not just functions.
Mon Sep 15 13:29:27 2014 Jiri (George) Lebl <jirka@5z.com>
* src/compil.c: new string decoding routine interacted with a stupid
optimization hence eating string constants from compiled files
starting with 'E'
* src/gnome-genius.c, src/plugin.c: move the examples reading and
plugin reading to happen later so that things display seemingly
quicker. plus some other very minor optimizations for startup
Fri Sep 12 11:14:14 2014 Jiri (George) Lebl <jirka@5z.com>
* examples/peano.gel: Add peano example in polar
Tue Sep 09 10:08:38 2014 Jiri (George) Lebl <jirka@5z.com>
* src/graphing.c: fixes in help/error texts. Thanks to Marek
Černocký
Sat Sep 06 10:24:33 2014 Jiri (George) Lebl <jirka@5z.com>
* src/gnome-genius.gel: fix New Program crash
* examples/easy-matrix-examples.gel, examples/rsa.gel: Add
code for creating nice classroom examples for easily hand
computable RREF and eigenvalues, and add an example of computing
an RSA key and encryption/decryption with it
Fri Sep 05 21:20:02 2014 Jiri (George) Lebl <jirka@5z.com>
* src/graphing.c: Add PlotWindowPresent
* examples/*.gel: use the PlotWindowPresent function
* help/C/genius.xml: document the function
Fri Sep 05 20:46:23 2014 Jiri (George) Lebl <jirka@5z.com>
* src/gnome-genius.c, src/examples.[ch]: rename tutorials to examples
I really like that wording bettter
* tutors -> examples: move all the files
* configure.in, Makefile.am: move to examples
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
in classes (those that weren't a mess)
Fri Sep 05 13:01:51 2014 Jiri (George) Lebl <jirka@5z.com>
* src/tutors.c: sort the tutors by category and then name.
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
Fri Sep 05 01:52:10 2014 Jiri (George) Lebl <jirka@5z.com>
* tutors/*: add a simple strange-attractor tutorial
* src/tutors.[ch], src/gnome-genius.c: add a tutorials menu
to load same programs, Right now really simple, eventually should
have submenus, and have to figure out translation
Tue Sep 02 10:12:42 2014 Jiri (George) Lebl <jirka@5z.com>
* help/C/genius.xml: minor fixes
Tue Sep 02 00:58:58 2014 Jiri (George) Lebl <jirka@5z.com>
* src/graphing.c: Add SurfacePlotDrawLine, SurfacePlotDrawPoints, and
SurfacePlotClear
* help/C/genius.xml: Add documentation for the above functions
* src/graphing.c: Add rotate animation
Sat Aug 30 17:10:23 2014 Jiri (George) Lebl <jirka@5z.com>
* help/C/genius.xml: fix spelling, update grant info
Sat Aug 30 15:40:00 2014 Jiri (George) Lebl <jirka@5z.com>
* gtkextra/gtkplotflux.c: fix almost zero arrows causing NaNs causing
postscript errors.
Fri Aug 29 10:41:36 2014 Jiri (George) Lebl <jirka@5z.com>
* src/gnome-genius.c: fix compilation on my old ubuntu 10.04 laptop
Tue Aug 26 11:56:12 2014 Jiri (George) Lebl <jirka@5z.com>
* Release 1.0.18
......
SUBDIRS = ve gtkextra src pixmaps lib po help
SUBDIRS = ve gtkextra src pixmaps examples lib po help
mimeinfodir = $(datadir)/mime-info
mimeinfo_DATA = genius.keys genius.mime
......
......@@ -406,7 +406,7 @@ target_alias = @target_alias@
top_build_prefix = @top_build_prefix@
top_builddir = @top_builddir@
top_srcdir = @top_srcdir@
SUBDIRS = ve gtkextra src pixmaps lib po help
SUBDIRS = ve gtkextra src pixmaps examples lib po help
mimeinfodir = $(datadir)/mime-info
mimeinfo_DATA = genius.keys genius.mime
appregdir = $(datadir)/application-registry
......
Changes to 1.0.19
* New menu: Examples. These are annotated programs that show some
mathematical concept. Generally taken from the classes I have been teaching.
They are installed under prefix/share/genius/examples/ and are mostly using
graphics so only work in the graphical GNOME/GTK version
* New plotting functions: SurfacePlotDrawLine, SurfacePlotDrawPoints,
SurfacePlotClear, PlotWindowPresent
* New rotation animation in the surface plot window
* Fix string constants from compiled library starting with 'E' (funky bug)
* A few fixes
* Translation updates (Miguel Rodríguez Núñez, Daniel Mustieles,
Wolfgang Stöggl, Marek Černocký)
* During making of these changes the author (Jiri) was partially supported by
NSF grant DMS 1362337 and the Oklahoma State University
Changes to 1.0.18
* New general functions: KroneckerProduct (alias TensorProduct), NewtonsMethod,
......@@ -6,7 +23,7 @@ Changes to 1.0.18
* New plotting functions: PlotCanvasFreeze/PlotCanvasThaw to improve flicker
if doing animations with genius, and LinePlotDrawPoints function to draw just
points without the line
* While plotting errors are no longer forced into a dialog, and presence
* While plotting, errors are no longer forced into a dialog, and presence
of errors is indicated in the graph window below the graph
* Allow setting color in LinePlotDrawLine with RGB vector.
* When the vector building notation is done with floats and the final
......@@ -24,6 +41,9 @@ Changes to 1.0.18
Wolfgang Stöggl, Miguel Rodriguez Nuñez, Piotr Drąg, Wylmer Wang,
Dimitris Spingos, Enrico Nicoletto, Matej Urbančič)
* During making of these changes the author (Jiri) was partially supported by
NSF grant DMS 1362337 and the Oklahoma State University
Changes to 1.0.17
* Better precision for graphs especially when zoomed it a lot, and make font
......
#! /bin/sh
# Guess values for system-dependent variables and create Makefiles.
# Generated by GNU Autoconf 2.69 for genius 1.0.18.
# Generated by GNU Autoconf 2.69 for genius 1.0.19.
#
#
# Copyright (C) 1992-1996, 1998-2012 Free Software Foundation, Inc.
......@@ -587,8 +587,8 @@ MAKEFLAGS=
# Identity of this package.
PACKAGE_NAME='genius'
PACKAGE_TARNAME='genius'
PACKAGE_VERSION='1.0.18'
PACKAGE_STRING='genius 1.0.18'
PACKAGE_VERSION='1.0.19'
PACKAGE_STRING='genius 1.0.19'
PACKAGE_BUGREPORT=''
PACKAGE_URL=''
......@@ -1432,7 +1432,7 @@ if test "$ac_init_help" = "long"; then
# Omit some internal or obsolete options to make the list less imposing.
# This message is too long to be a string in the A/UX 3.1 sh.
cat <<_ACEOF
\`configure' configures genius 1.0.18 to adapt to many kinds of systems.
\`configure' configures genius 1.0.19 to adapt to many kinds of systems.
Usage: $0 [OPTION]... [VAR=VALUE]...
......@@ -1502,7 +1502,7 @@ fi
if test -n "$ac_init_help"; then
case $ac_init_help in
short | recursive ) echo "Configuration of genius 1.0.18:";;
short | recursive ) echo "Configuration of genius 1.0.19:";;
esac
cat <<\_ACEOF
......@@ -1655,7 +1655,7 @@ fi
test -n "$ac_init_help" && exit $ac_status
if $ac_init_version; then
cat <<\_ACEOF
genius configure 1.0.18
genius configure 1.0.19
generated by GNU Autoconf 2.69
Copyright (C) 2012 Free Software Foundation, Inc.
......@@ -2020,7 +2020,7 @@ cat >config.log <<_ACEOF
This file contains any messages produced by compilers while
running configure, to aid debugging if configure makes a mistake.
It was created by genius $as_me 1.0.18, which was
It was created by genius $as_me 1.0.19, which was
generated by GNU Autoconf 2.69. Invocation command line was
$ $0 $@
......@@ -2884,7 +2884,7 @@ fi
# Define the identity of the package.
PACKAGE='genius'
VERSION='1.0.18'
VERSION='1.0.19'
cat >>confdefs.h <<_ACEOF
......@@ -15520,7 +15520,7 @@ fi
ac_config_files="$ac_config_files genius.spec Makefile src/Makefile lib/Makefile lib/calculus/Makefile lib/combinatorics/Makefile lib/equation_solving/Makefile lib/functions/Makefile lib/linear_algebra/Makefile lib/misc/Makefile lib/sets/Makefile lib/number_theory/Makefile lib/statistics/Makefile lib/symbolic/Makefile lib/commutative_algebra/Makefile ve/Makefile gtkextra/Makefile pixmaps/Makefile pixmaps/32x32/Makefile pixmaps/48x48/Makefile po/Makefile.in help/Makefile"
ac_config_files="$ac_config_files genius.spec Makefile src/Makefile lib/Makefile lib/calculus/Makefile lib/combinatorics/Makefile lib/equation_solving/Makefile lib/functions/Makefile lib/linear_algebra/Makefile lib/misc/Makefile lib/sets/Makefile lib/number_theory/Makefile lib/statistics/Makefile lib/symbolic/Makefile lib/commutative_algebra/Makefile ve/Makefile gtkextra/Makefile examples/Makefile pixmaps/Makefile pixmaps/32x32/Makefile pixmaps/48x48/Makefile po/Makefile.in help/Makefile"
cat >confcache <<\_ACEOF
# This file is a shell script that caches the results of configure
......@@ -16079,7 +16079,7 @@ cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1
# report actual input values of CONFIG_FILES etc. instead of their
# values after options handling.
ac_log="
This file was extended by genius $as_me 1.0.18, which was
This file was extended by genius $as_me 1.0.19, which was
generated by GNU Autoconf 2.69. Invocation command line was
CONFIG_FILES = $CONFIG_FILES
......@@ -16145,7 +16145,7 @@ _ACEOF
cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1
ac_cs_config="`$as_echo "$ac_configure_args" | sed 's/^ //; s/[\\""\`\$]/\\\\&/g'`"
ac_cs_version="\\
genius config.status 1.0.18
genius config.status 1.0.19
configured by $0, generated by GNU Autoconf 2.69,
with options \\"\$ac_cs_config\\"
......@@ -16573,6 +16573,7 @@ do
"lib/commutative_algebra/Makefile") CONFIG_FILES="$CONFIG_FILES lib/commutative_algebra/Makefile" ;;
"ve/Makefile") CONFIG_FILES="$CONFIG_FILES ve/Makefile" ;;
"gtkextra/Makefile") CONFIG_FILES="$CONFIG_FILES gtkextra/Makefile" ;;
"examples/Makefile") CONFIG_FILES="$CONFIG_FILES examples/Makefile" ;;
"pixmaps/Makefile") CONFIG_FILES="$CONFIG_FILES pixmaps/Makefile" ;;
"pixmaps/32x32/Makefile") CONFIG_FILES="$CONFIG_FILES pixmaps/32x32/Makefile" ;;
"pixmaps/48x48/Makefile") CONFIG_FILES="$CONFIG_FILES pixmaps/48x48/Makefile" ;;
......
AC_INIT([genius], [1.0.18])
AC_INIT([genius], [1.0.19])
AC_CONFIG_SRCDIR([src/calc.c])
AM_INIT_AUTOMAKE([dist-xz])
......@@ -282,6 +282,7 @@ lib/symbolic/Makefile
lib/commutative_algebra/Makefile
ve/Makefile
gtkextra/Makefile
examples/Makefile
pixmaps/Makefile
pixmaps/32x32/Makefile
pixmaps/48x48/Makefile
......
exampledir = \
$(datadir)/genius/examples/
example_DATA = \
cantor.gel \
dalemb-pulse.gel \
eulers-method-exp-run.gel \
eulers-method-graphs-exp.gel \
laplace-fdm.gel \
linapprox.gel \
lorenz.gel \
newton-calc-sqrt2.gel \
newton-sqrt2.gel \
shocks.gel \
sierpinski.gel \
standing-waves.gel \
strange-attractor.gel \
taylor-exp.gel \
taylor-sin.gel \
fourier-series-animation.gel \
fourier-series-half-sawtooth.gel \
rsa.gel \
easy-matrix-examples.gel \
peano.gel
EXTRA_DIST = \
$(example_DATA)
This diff is collapsed.
# 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)))
);
PlotWindowPresent(); # Make sure the window is raised
LinePlot(Cantor,[0,1]);
# Category: Differential Equations
# Name: D'Alembers solution animation of a plucked string
#
# Solution to the wave equation
# The initial conditions are: position at F(x) and velocity at 0
#
# A pulse function. Feel free to set this function to whatever you want,
# though you should have ends at 0
function F(x) = (
# This makes the functions periodic
while x < -1 do x = x + 2;
while x > 1 do x = x - 2;
if x < 0 then
-F(-x)
else if x < 0.45 or x > 0.55 then
0
else (
if x < 1/2 then
20*(x-0.45)
else
20*(0.55-x)
)
);
#t a paramater
function yy(x) = (F(x-t) + F(x+t))/2;
LinePlotDrawLegends = false;
PlotWindowPresent(); # Make sure the window is raised
for n=1 to 1000 do (
t = n*0.005;
LinePlot(yy,[0,1,-1.1,1.1])
)
# Category: Linear Algebra
# Name: Finding simple integer matrices (good classroom examples)
#
# Eigenvalues
# -----------
#
# Find an integer matrix with given eigenvalues.
#
# Start with the eigenvalues
D = diag(1,2,3);
do (
# Find some eigenvectors
do (
E = randint(11,3,3) - 5*ones(3,3)
) while det(E) == 0;
# Make the matrix
A = E*D*E^-1;
) while not IsMatrixInteger(A);
print("Integer matrix with given egeinvalues");
# print A
A
#
# Row reduction
# -------------
#
# Integer matrix where the row reduced form is also
# integer. That is find a random 3 by 4 matrice with
# reduced row echelon form (rref) with only integer entries.
# The entries of the matrix are between -5 and 5.
do (
B = randint (11,3,4) - 5*ones(3,4)
) while not IsMatrixInteger(rref(B));
print("Integer matrix with integer RREF form");
# print B
B
# print rref(B)
rref(B)
#
# Row reduction with free variables
# ------------------------------------------
#
# Find a random 3 by 4 matrix with reduced row echelon
# form (rref) with only integer entries, the entries of the matrix are between
# -5 and 5. Furthermore the rref form will have a zero row, so probably will
# be a consistent system with some free variables.
do (
C = randint (11,3,4) - 5*ones(3,4)
) while not IsMatrixInteger(rref(C)) or CountZeroColumns(rref(C).') == 0;
print("Integer matrix with integer RREF form that includes zero row");
# print C
C
# print rref(C)
rref(C)
# Category: Differential Equations
# Name: Estimation of exp(4) using Euler's Method
# we will measure time it takes
ct=CurrentTime;
sp=(CurrentTime-ct);
print("Estimation of e^4 with Euler's method");
print("h is the step size we use");
# Rounding to specific number of digits
function ourround(num) = round(num*10000.0)/10000.0;
function ourroundb(num) = round(num*100000000.0)/100000000.0;
for k=1 to 21 do (
ct = CurrentTime;
eu = EulersMethod(`(x,y)=y,0,1,4,2^k);
ct2 = (CurrentTime-ct-sp);
print("h=2^"+(3-k)+" gets "+ourroundb(eu)+" (e^4=" + ourroundb(e^4) + ", error="+ourroundb(|eu-e^4|)+") .. in " + ourround(ct2) + " secs");
);
# Category: Differential Equations
# Name: Euler's Method graphs for the exponential
# You can play around with different
# differential equations, the equation is dy/dx = g(x,y)
function g(x,y)=y;
LinePlotWindow=[-0.2,4,0,e^4+0.2];
LinePlotDrawLegends=false;
LinePlotClear();
PlotWindowPresent(); # Make sure the window is raised
LinePlotDrawPoints(0,1,"thickness",10,"color","red");
AskButtons("The initial point (0,1)","Next");
# h is step size, x0, y0 are the initial conditions
h=1;
x0=0;
y0=1;
xx=[x0];yy=[y0];
for j=2 to (4/h)+1 do (
xx@(j) = xx@(j-1)+h;
yy@(j) = yy@(j-1)+g(xx@(j-1),yy@(j-1))*h;
);
LinePlotDrawLine ([xx',yy'],"color","darkgreen");
AskButtons("Step size h = 1","Next");
h=(1/2);
for j=2 to (4/h)+1 do (
xx@(j) = xx@(j-1)+h;
yy@(j) = yy@(j-1)+g(xx@(j-1),yy@(j-1))*h
);
LinePlotDrawLine ([xx',yy'],"color","blue");
AskButtons("h = 0.5 = 1/2","Next");
h=(1/4);
for j=2 to (4/h)+1 do (
xx@(j) = xx@(j-1)+h;
yy@(j) = yy@(j-1)+g(xx@(j-1),yy@(j-1))*h
);
LinePlotDrawLine ([xx',yy'],"color","orange");
AskButtons("h = 0.25 = 1/4","Next");
h=(1/8);
for j=2 to (4/h)+1 do (
xx@(j) = xx@(j-1)+h;
yy@(j) = yy@(j-1)+g(xx@(j-1),yy@(j-1))*h
);
LinePlotDrawLine ([xx',yy'],"color","brown");
AskButtons("h = 0.125 = 1/8","Next");
h=(1/16);
for j=2 to (4/h)+1 do (
xx@(j) = xx@(j-1)+h;
yy@(j) = yy@(j-1)+g(xx@(j-1),yy@(j-1))*h
);
LinePlotDrawLine ([xx',yy'],"color","darkgreen");
AskButtons("h = 0.0625 = 1/16","Next");
h=(1/32);
for j=2 to (4/h)+1 do (
xx@(j) = xx@(j-1)+h;
yy@(j) = yy@(j-1)+g(xx@(j-1),yy@(j-1))*h
);
LinePlotDrawLine ([xx',yy'],"color","blue");
AskButtons("h=0.03125=1/32","Next");
# The real solution
for j=2 to (4/h)+1 do (
xx@(j) = xx@(j-1)+h;
yy@(j) = e^(xx@(j))
);
LinePlotDrawLine ([xx',yy'],"color","red");
AskButtons("The real solution","End");
# 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 3 do (
for n = 1 to elements(hvals) do (
h = hvals@(n);
LinePlot(F, fs@(n))
)
)
# 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();
PlotWindowPresent(); # Make sure the window is raised
# 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();
);
# 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;
PlotWindowPresent(); # Make sure the window is raised
# 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");
);
# Category: Calculus
# Name: Linear approximation by a tangent graphically
function f(x) = sin(ln(x+1))^2;
df = SymbolicDerivative(f);
# Where to approximate
a = 2;
# The approximation
function lf(x) = df(a)*(x-a)+f(a);
function DoGraph(x) = (
PlotCanvasFreeze();
LinePlot(f,lf,[-0.5,5,-0.1,2]);
LinePlotDrawLine([x,0,x,min(f(x),lf(x))],"color","orange");
LinePlotDrawLine([x,min(f(x),lf(x)),x,max(f(x),lf(x))],"color","red");
LinePlotDrawLine([-0.5,f(x),5,f(x)],"color","black","thickness",1);
LinePlotDrawLine([-0.5,lf(x),5,lf(x)],"color","purple","thickness",1);
PlotCanvasThaw();
print("at x=" + x + " error = |" + lf(x) + " - " + f(x) + "| = " + |lf(x)-f(x)|);
);
PlotWindowPresent(); # Make sure the window is raised
for x=2 to 5 by 0.0222 do (
DoGraph(x);
wait(0.003)
);
for x=5 to -0.5 by -0.0222 do (
DoGraph(x);
wait(0.06)
);
for x=-0.5 to 2 by 0.0222 do (
DoGraph(x);
wait(0.003)
);
# 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)];