iconEuler Home

Current Version 2016-05-11

Besides some minor fixes in the documentation, I added knots and nautical miles to the units.

>180kts -> " km/h"
333.5840928 km/h

I made it more clear in the documentation that units can be overridden by variables. It is safest to use the $ sign with units all the time.

>nm=0; // now 5nm would no longer work ...
 5nm$ -> " km"
9.2662248 km

Version 2016-03-23

Due a post in the forum I expanded plotcubes() a little bit. It works now better. But it is still not perfect. For photo realistic scenes, you should use Povray via EMT.

>function p (M) ...
 clg;
 plotcubes(M,rgb(0.5,0.5,linspace(0.5,1,rows(M))));
 endfunction
>n=4;
>x=0:1/n:1; {X,Y}=field(x,x);  ...
 X=flatten(X)'; Y=flatten(Y)'; Z=random(size(X)); ...
 h=1/(2*n); M=X|(X+h)|Y|(Y+h)|Z|(Z+h);
>plot3d({{"p",M}},>own,>user,zoom=4,center=[-0.5,-0.5,-0.5]):

Changes

Version 2016-26-02

The Ctrl-Z to restore a line became more functionality. It will now remember the 8 last version of this line. A new version is stored whenever the line is executed. Moreover, Ctrl-Y does now undo the restore.

Version 2016-01-15

I wrote a utility file scilab.e to interface with Scilab. Currently, results from Scilab can only be read, if they are simple numbers.

>load scilab
Interface for the SciLab program.

We can optionally start the Scilab process manually.

>// slstart;

Otherwise it is started whenever it is used.

Now it is possible to interpret results of Scilab and convert them to numbers in EMT with slget():

>slget("sum((1:10)^2)")
385

For multi-line returns, EMT cannot interpret the result. Use the function "sl" to send a command to Scilab. (See below for this new type of functions).

>sl 1:24
         column  1 to 12
 
    1.    2.    3.    4.    5.    6.    7.    8.    9.    10.    11.    12.  
 
         column 13 to 23
 
    13.    14.    15.    16.    17.    18.    19.    20.    21.    22.    23.  
 
         column 24
 
    24.  

sl() will return a string of vectors. You can store the result for later.

>s=sl("1:2:10");

The Scilab process is killed with slend(). If EMT is exited, it will also be killed.

>slend;

Here is the stored result.

>s
    1.    3.    5.    7.    9.  

The output of Scilab is truncated by default. Empty lines at the start and the end, and the line "ans =" are then deleted. Set the variables "stripstart", "stripend", "stripans" to change this.

The Modifier "prefixline"

For the Scilab interface, a new type of function was needed, which reads the complete input line as a parameter.

>function prefixline readall (s:string) := ">"+s+"<";
>readall Read everything from this line
 >Read everything from this line<

Computing Games

There was an error in the function game(A), which finds the optimal strategy for a game with matrix A.

>load games
game(A), computes an optimal strategy for the game with matrix A.
>A=[1,-1,4,1;-2,5,2,1;4,1,-3,1]
            1            -1             4             1 
           -2             5             2             1 
            4             1            -3             1 

The meaning of this is: You select a column j, and the other player selects a row i. Then you get the value A[i,j].

For an optimal strategy, you have to select the columns of the matrix with the following probabilities.

>{p,res}=game(A); p, res,
[0.426966,  0.303371,  0.269663,  0]
1.20224719101

Note that you should never select column 1. This will safely gain 1, but the strategy p is better. It will gain more than 1 on average.

The mathematical problem is

Changes

Changes

Version 2015-12-08

Fixed a glitch in the adaptive evaluation for plot2d(). For small intervals, the result took too many points.

>plot2d("x^2",-1e-6,1e-6,grid=9):

Changes

Version 2015-09-23

There were some changes in shrinkwindow() and fullwindow(). The windows are now actually square always, and the full window is a bit larger. The plot3d() functions now makes a bit larger and more centered plots.

This is only a tiny correction. With proper individual settings, plots can now fill more of the image.

>plot3d("x^2+y^3",>spectral,>levels,angle=-40°, ...
    zoom=2.7,center=[0,0,0.4],n=100):

Changes

The plot window should now be exactly square. The plot coordinates will be square only with the >square parameter, however.

>plot2d("x^3-x",>square):

Changes

Version 2015-07-09

There was a bug in xgrid() and ygrid() which needed to be fixed.

>plot2d("x^2",0.01,0.02):

Changes

If you like to format the grids labels yourself use xgrid(), ygrid(). The factor f can be used to avoid large numbers.

>plot2d("x^2",0.01,0.02,<ticks,grid=4); ...
 xgrid(0.01:0.001:0.02,f=0.001); ...
 ygrid(0:0.0001:0.001,f=0.0001):

Changes

Version 2015-07-06

I added a new function adaptive() which adaptively evaluates a function. It works for real and complex scalars and column vectors. The similar functions adaptiveeval() and adaptiveevalone() for plotting are not changed by this new function.

>{x,y}=adaptive("sin(1/(x^2-1))",0,1-epsilon); ...
 plot2d(x,y):

Changes

As you see when looking at the differences the step sizes vary considerably.

>plot2d(differences(x),>logplot):

Changes

Here is another example, where f is vector valued.

>function f(t,a,b) := [sum(sin(t*a)*b);sum(cos(t*a)*b)]; ...
 {t,X}=adaptive({{"f",[1,3,7],[1,0.3,0.3]}},0,2pi);  ...
 plot2d(X[1],X[2],r=2,>filled,fillcolor=lightgray):

Changes

New Functions

There is now a function colsum(), which sums the columns of matrices.

>A=random(3,3); A_colsum(A)
     0.655416      0.200995      0.893622 
     0.281887         0.525      0.314127 
     0.444616      0.299474       0.28269 
      1.38192       1.02547       1.49044 

Of course, this is the same as the following.

>A_sum(A')'
     0.655416      0.200995      0.893622 
     0.281887         0.525      0.314127 
     0.444616      0.299474       0.28269 
      1.38192       1.02547       1.49044 

Version 2015-06-23

The xgrid() and xtick() functions have been fixed to allow labels.

>plot2d("x^3-x",-1.2,1.2,<ticks); xgrid([-1,0,1],xt=["a","b","c"]):

Changes

Using xtick(), this allows Latex formulas.

>plot2d("x^3-x",-1.2,1.2,<ticks);  ...
 xtick([-1,0,1],["x_1","x_2","x_3"],>latex):

Changes

Version 2015-06-18

Vectors and matrices can now be declared "zerobased". This makes the indices start with 0 instead of 1.

>v=1:5; zerobase v; v[0]=v[4]
[5,  2,  3,  4,  5]

Note that linspace(a,b,n) returns n+1 values. Often, you might want to refer to these values as x[0] to x[n]. This is now possible.

>n=10; x=linspace(0,1,n); zerobase x;

The following is an upper Riemann sum for the integral of x^2 in [0,1]. The first value of x, x[0], is not used.

>sum(x[1:n]^2)/n
0.385

Note setting x to a new vector makes it restart with base 1.

>x=1:10; x[1]
1

Moreover, the property cannot be set inside a function to an array passed as an argument to the function. The new base 1 will only be used inside this function.

>function test (x) ...
 zerobase x; x[0]=77;
 return
 endfunction

The original x is changed properly. But it will use base 1 still.

>test(x), x[1]
77

Assigning a zero based vector to another vector copies the flag.

>w=v; w[0]
5

Thus it is possible to write functions, which return zero based vectors or matrices.

>function linspace0 (a,b,n) ...
 v=linspace(a,b,n); zerobase v;
 return v;
 endfunction
>v=linspace(0,1,10); v[1]
0
>v=linspace0(0,1,10); v[0]
0

Fixes

The function gauss() did not work with call collections. This has been fixed.

>function f(x,a) := x^a; ...
 gauss({{"f",4}},0,1)
0.2

Likewise, the function adaptiveint() did have problems with call collections.

>adaptiveint({{"f",4}},0,1)
0.2

Directories

EMT now searches in the current directory first when a file is opened, an Euler file is loaded or help is searched from an Euler file. In previous versions, the existence of a file with the same name in the start directory of EMT would have prevented the user file from being used.

This of course means that the user can manipulate his installation by putting Euler files in the directory of the loaded notebook. To prevent the worst, the file "euler.cfg" now switches to the start directory of EMT to load its files.

Version 2015-06-03

The Gauss method now vectorizes the function or expression by default.

>function f(x:scalar) ...
 if x<0 then return x^2; else return x^3; endif;
 endfunction

Note the type check "scalar" which makes sure that f() is not abused!

The following did not work in previous versions since f() does not work for vector input. Note that integrate() uses the adaptive Gauss algorithm, which in turn uses the Gauss algorithm.

>fraction integrate("f",-1,1)
7/12

For another example, let us compute

Changes

>function map f(p:scalar; T:vector) := sum(T^p)^(1/p);

Since the function f() already vectorizes to p (but not to T because of the semicolon) we do not need to map in the Gauss method. So we turn off the vectorization.

>integrate({{"f",[1,3,2]}},1,2,<maps)
4.49846360039

Version 2015-04-20

I added a parameter for Latex formulas in label boxes.

>plot2d(["x^2/2","x^3"],color=[2,3]); ...
 labelbox(["\frac{x^2}{2}","x^3"],colors=[2,3], ...
   x=0.3,>latex,scale=1.5):

Changes

There is now an option to split a line without adding "...". The keyboard shortcut for this is Shift+Control+Return.

Version 2015-04-10

This version dumps the snippets menu in favor of a menu "Tasks" which links to section of the help file explaining taks you might want to do in EMT.

The User Menu is still there and can be filled with snippets as needed. It does also contain a submenu with loaded Euler files. Calling the menu items in this submenu opens the help window with a list of definitions in the Euler file.

Version 2015-03-17

I have started a tutorial for R users on EMT. Along the way, I learn a lot about R. The tutorial is based on the "Introduction to R" which is installed with the R project on Windows as a PDF.

23 - Introduction for Users of the R Project

The command line switch "-pipe script.e" now exits EMT on any errors. It will no longer open the notebook window. Here is an example of a script in R, which dumps the command output to some file, and saves the current graphics to a PNG.

  dump("output.txt");
  expr&=diff(sin(x)*exp(x),x),
  "Integral from 0 to pi = "+integrate(expr,0,1),
  "Exact = "+(sin(1)*E),
  plot2d(expr,0,1);
  savepng("output.png");
  dump;

The output is

                           x           x
                          E  sin(x) + E  cos(x)
  Integral from 0 to pi = 2.28735528718
  Exact = 2.28735528718

Version 2015-03-02

A lot more functions now accept "call collections". This term stand for a function or expression plus additional parameters in a collection. Call collections are also documented in a better way now including links in the functions that can use them.

>expr &= factor(diff(exp(-s*x^2)/(x^2+1),x))
                                                2
                               2           - s x
                       2 x (s x  + s + 1) E
                     - --------------------------
                                 2     2
                               (x  + 1)

>plot2d({{&expr*x,s=1}},0,1):

Changes

>romberg({{&expr*x,s=1}},0,1)
-0.434882242722

The function fmin() can now search from a single point or in an interval.

>fmin({{&expr*x,s=1}},0)
0.722066270034

Version 2015-02-23

The new method for passing arguments with a function did not work for adaptive integration. This has been fixed.

>adaptiveint({{"a*x^3",a=2}},0,1)
0.5

Protected variables became unprotected if they were changed as global variables inside a function. This has been fixed. Now plot2d() works after plot2d() and a subsequent "clearall". (plot2d() changes global variables like verticallabels).

>plot2d("x^2"); clearall; plot2d("x^2");

Units in expressions can no longer be abused as simple variables. They need a number in front of them.

>"2cm"()
0.02

Version 2015-02-16

EMT now is installed with the recent version 5.35.1 of Maxima. The drawback is that LAPACK is no longer working with this version. This should not be a major problem. You can use the routines provided by the numerical part of EMT. Some missing routines from LAPACK will be added in the future.

The new version of Maxima is quite different internally. So the program is now started via the command "sbcl.exe". To make this possible, some internal things had to be changed in the code of EMT. Moreover, the Maxima version is now installed in a subdirectory "maxima", including Gnuplot.

A new tutorial with more details on Maxima has been added to the tutorials.

22 - Maxima - More Details

Version 2015-01-27

"listvars" is now possible instead of "listvar".

>x=pi; listvars
x                   3.14159265358979

"listvars" will also list global lists. But there is "listlists" too.

>glist("One"); glist("Two"); listlists
One                 global list
Two                 global list

Like with "listvars" it is possible to add a string.

>listlists ne
One                 global list

The function glistput(list,pos,value) now adds a value at the list position even if there was a value before. If the list is empty or the position is behind the end of the list, it appends the element to the list.

>glistput("One",1,"First"); glistadd("One","Second"); glistput("One",1,"Alt");

The function glistvar(list,pos) has been replaced by glistget(list,pos).

>for k=1 to glistlength("One"); glistget("One",k), end;
Alt
Second

Fixes

The evaluation of a string now can use units.

>"4cm"()
0.04

This is used by readTable() to read a table with units. Moreover, the expressions in the values of a table can now contain global variables.

Version 2015-01-23

EMT has now a collection type, It is in primary beta for the moment, and probably will receive more features along the way.

A collection is declared with {{...}} and can contain any objects.

>L={{4,3,5,6}}
4
3
5
6

Elements can be accessed like vector elements.

>loop 1 to length(L); L[#], end;
4
3
5
6

Collections are good to keep return values of functions in one place. Instead of returning multiple return values a function can return a collection.

>function f(x) := {{x,x^2}};
>f(5)
5
25

However, it is also possible to put the multiple results of an existing function into a collection. In the example, sort() returns the sorted vector and the indices of the sorted elements. The collection L contains both vectors.

>L={{sort(random(6))}}
[0.217693,  0.270906,  0.308411,  0.445363,  0.704419,  0.883227]
[4,  2,  6,  5,  3,  1]

Another feature is the execution of a collection, where the first element is the name of a function or an expression.

>function f(x,a) := sin(a*x)
>L={{"f",5}}; L(pi/5)
0

This trick is applied in many plot functions and numerical functions now. It avoid the previous semicolon parameters.

>plot2d({{"f",5}},0,2pi):

Changes

The same works with expression. But the variables in the collection must be named in this case.

>plot2d({{"sin(omega*x)*exp(-x)",omega=5}},0,2pi):

Changes

This works in many numerical functions too.

>integrate({{"sin(omega*x)*exp(-x)",omega=5}},0,2pi)
0.191948568705

Fixes

The : for insimg() has been fixed. It did not work properly after a loop and inserted the image many times.

>plot2d("sin(x)",0,2pi); ...
 for k=2 to 5; plot2d("sin(k*x)",>add,color=getspectral(k/6)); end:

Changes

Version 2014-12-20

The PDF introduction is now in a better state. There are still some things to add.

EMT allows assigned arguments only to override parameters with default values unless the argument is assigned with :=. For functions, which are designed to use a lot of assigned arguments, this can now be released with the modifier "allowassigned".

>function allowassigned f(x) := x*a
>f(4,a=6)
24

However, it is possible to declare variables with :=.

>function g(x) := x*a
>g(4,a:=6)
24

Version 2014-12-10

With >best, the iterate() function now continues to itereate until the error does no longer improve.

>longest iterate("cos(x)",1,>best), longest iterate("cos(x)",1)
     0.7390851332151607 
     0.7390851332157368 

The problem is that iterating will take very long if the limit is 0 and >best is turned on.

>{x,count}=iterate("x/2",1,>best); longest x, count,
 4.940656458412465e-324 
1074

By the way, iterate() also works for vectors. We solve

Changes

by iteration.

>function f([x,y]) := [cos(x+y)/2,cos(y)+x^2];
>v=iterate("f",[1,1],>best); longest v, longest f(v)
     0.2558264481813221       0.777862408428445 
     0.2558264481813384      0.7778624084282351 

Fixes

The code Ctrl-Back now joins the line to the previous no matter where the cursor is in that line. Of course, Ctrl-Return splits the line at the cursor.

The parameter grid=0 was not working for implicit plots.

Moreover, the style "#" did still use a black contour line for filled contour plots. This is now disabled. Use "O#" for a contour.

>fullwindow(); plot2d("(x^2+y^2-1)^3-x^2*y^3",r=1.4,level=[-2;0], ...
    color=rgb(1,0.9,0.9),<grid,style="#",n=200):

Changes

PDF Documentation

I updated the introduction in PDF for the recent version. The work is almost completely done. Three chapters are still missing. This will be continued.

Version 2014-11-28

The marker size is no longer global. Previously, the following code worked only for the graphics screen, but failed for the PNG export.

>function test () ...
   X=random(3,100);
   {v,i}=sort(-X[3]); X=X[,i];
   plot2d(none,r=0.6,cx=0.5,cy=0.5,<grid);
   markerstyle("o#");
   hold on;
   loop 1 to cols(X)
     markersize(X[3,#]*50+20);
     c=1-X[3,#]/2; color(rgb(c,0,c));
     mark(X[1,#],X[2,#]);
   end;
   hold off;
 endfunction
>test:

Changes

Help for Euler Files

The help for Euler Files has been improved. Now it prints simple comment lines (//...) and comment functions via "maximafunction". Moreover, this help will open if a command line containing "load filename" is double clicked.

Second Window for EMT

With Ctrl-Shift-O a second process for EMT can be started. The second version of EMT will have no graphics window and display the graphics in its notebook window. Moreover, it will not save any settings.

This helps to look up things in a tutorial file or in any previous notebook.

Version 2014-11-05

Latex formulas now work with a changed background color now. The bar style "0" now shows the rectangle in the selected color. The SVG export of a graphics with another background color also works now.

>setcolor(0,0.9,0.9,0.9); window(100,100,950,900); ...
 plot2d("x^3-x",color=blue);  ...
 textbox(latex("y=x^3-x",color=blue,factor=1.5), ...
   color=blue,style="O",x=0.55,y=0.8):

Changes

The function reset() now colors resetcolors(), which now correctly resets the default values of the colors.

>reset;

The parameter >frame now draws a frame even if <grid is set.

>plot2d("x^3-x",<grid,>frame); xgrid(-2:2); ygrid(-6:2:6):

Changes

Version 2014-10-06

I improved the ibisect() method for guaranteed interval solutions. It did not work optimally, if the zero was accidentally met. Now I made it a trisection method, which works much better.

>ibisect("x",0,2,y=1)
~0.9999999999991,1.000000000001~

It does also work for functions with interval parameters.

>function f(x,a) := a^x-x^a;

The following calls the function by name with "a" given as a semicolon argument.

>ibisect("f",0.5,1.5;1±0.01)
~0.988,1.02~

As usual, expressions are also possible, if the argument is constant or a global variable.

>ibisect("f(x,1±0.01)",0.5,1.5)
~0.988,1.02~

Fixes

The behavior of the operator "^" had to be fixed once more. Previously EMT evaluated 2^-3^4 as 2^((-3)^4). Now, it follows the convention of Maxima to evaluate this as follows.

>2^-3^2, 2^(-(3^2))
0.001953125
0.001953125

Maxima has the same rule.

>& 2^-3^2, %()
                                  1
                                 ---
                                 512

0.001953125

Version 2014-08-18

There have been some fixes in the graphics routines. E.g., the function ylabel() did only work for the default centered position.

>plot2d("exp(-x)",-1,1,0,2,<ticks,title="y = exp(-x)");   ...
 x0=0.5; y0=exp(-0.5); plot2d(x0,y0,>points,>add);  ...
 plot2d([-1,x0,x0],[y0,y0,0],>add,style="--"); ...
 ylabel("y = "+print(y0,5,0),y0); xlabel("x = "+x0,x0):

Changes

Moreover, the documentation of "plot.e" has been improved.

Version 2014-08-09

I switched back to the previous behavior of the order of the evaluation of powers.

>2^2^3, 2^(2^3), (2^2)^3
256
256
64

This is the way Maxima handles powers.

>&2^2^3
                                 256

It seems most algebra programs evaluate from right to left. But Matlab evaluates from left to right. See the following online resources.

Mathematica
Wolfram Alpha
Matlab

There is a new function diffc() for numerical differentiation, which works for analytic functions. The function must evaluate for complex values.

>longest diff("exp(x)",1), longest diffc("exp(x)",1), longest E,
      2.718281828460438 
      2.718281828459045 
      2.718281828459045 

Fixes

The expression "1e" no longer is interpreted as "1e0". In fact, EMT will issue an error message on exponential numbers which are not well-formed.

Note, that 'E' and 'e' can be used for the exponential format to be able to read external files from other systems. This is sometimes confusing, since E is the Euler number in EMT.

>5E-4, 5*E-4
0.0005
9.5914091423

Version 2014-08-04

A problem with global variables in recursive subroutines has been fixed. It appeared only when the global variable changed its size.

The alias feature for functions was not documented.

>function f(x) := x^4;
>alias falias f; falias(4)
256

Removing f will also remove g.

>forget f; falias(5)
Function falias not found.
Try list ... to find functions!
Error in:
forget f; falias(5) ...
                   ^

Version 2014-07-29

It is now possible to search through the help topics in the help window. Enter "?string" to find the string in the help topics. You can double click on the topic to open it.

You can now debug errors with

  >trace errors

If an error occurs in a function you can inspect local variables or expressions containing these variables. Restarting EMT resets all tracing to off.

Version 2014-07-18

Now the packages are listed as included packages and provided packages. The latter need to be loaded. I inserted some of the Euler files in the examples into the provided packages.

Version 2014-07-08

The settings for the size of the windows and dialogs now depend on the screen size.

Version 2014-06-26

The plot function plot2d() got a new flag >addpoints. This allows the same simple overlay as in statplot() without >add. It works only for data plots.

>plot2d(0:10,bin(10,0:10),>addpoints,pointstyle="o"):

Changes

The function cimean() computes an interval estimator for the true mean of a normal random variable when a vector of data of these data is given.

>data=randnormal(1,7,1000,50), cimean(data,alpha=1%)
[976.11,  957.904,  1066.25,  1081.34,  1055.23,  1047.58,  1040.13]
[966.677,  1097.48]

The function cinormal() computes a confidence interval for normal distributed variables with known mean and standard deviation.

>cinormal(1000,10,alpha=1%)
[974.242,  1025.76]

Version 2014-06-12

The file menu got entries for saving and loading in the "Euler Files" directory of the user home folder. Moreover, the shortcuts are now the more logical Alt-S and Alt-O.

It is now documented that the default method for integrate() must get a vectorized function. The error message has been improved.

The statistical functions bindis() and invbindis() are now documented in the tutorials. binsum() is no longer used.

Fixes

In plot2d(), yl= now works for figures.

>figure(2,2); ...
 for k=1:4; figure(k); plot2d("x^k",yl="y=x^"+k,xl="x",title=""+k); end; ...
 figure(0):

Changes

The non-vertical labels now align correctly on the left edge.

>plot2d("x^3-x",yl="y=x^3-x",xl="x",<vertical,>smaller):

Changes

Version 2014-05-28

The Clopper-Pearson confidence interval is an interval such that for probabilities p outside this interval, the observed result is rare. The default level is alpha=0.05.

>clopperpearson(510,1000)
[0.478526,  0.541415]

But you can use a smaller alpha and get a wider interval.

>clopperpearson(510,1000,0.01)
[0.468812,  0.551091]

Fix

Some commands now require a semicolon or a line end. This should prevent errors like the following.

>function f(x) ...
 useglobal a;
 return a*x;
 endfunction
>a=5; f(6)
Command "useglobal" needs a semicolon!
Try "trace errors" to inspect local variables after errors.
f:
    useglobal a;

Fix

The Alt-U now works differently. It inserts all deleted lines and clears the delete buffer. Previously, the buffer was cleared, if the lines were not deleted in successive order. Alt-Del will delete the undo buffer.

Multi-line commands will now be deleted together as one block.

Version 2014-05-14

To avoid confusion between expressions and functions, EMT now follows the following rules.

 - Expressions take precedence over functions with the same name.
 - Expressions should be named fx, fxy etc.
 - A function kills a global symbolic expression with the same name.
>fx &= "x^x"; fx(3)
27

Do not define functions with such names! The following is for demonstration only. The variable fx will be killed.

>function fx(x) := x^2; ...
 fx(3)
9

Inside of a function, expressions are used instead of functions with the same name. This is what the user expects.

>function h(fx,x) := fx(x);

This does not call the function fx() defined above.

>h("sin",pi/2)
1

Stack Overflow

I improved the behavior for stack overflows. Now, EMT prevents stack overflows in a better way. This is not fool proof but should work in most cases.

>function f(x) := f(f(x));
>if errorlevel("f(2)") then "Some error occured!", endif;
Some error occured!

If a stack overflow still happens, EMT will crash as before. But the new crash dialog contains an error code now.

Euler Home