iconEuler Reference

Basic Utilities

Basic utility functions.

This file collects some important utility functions.

Colors

white:=0;
black:=1;
red:=2;
green:=3;
blue:=4;
cyan:=5;
olive:=6;
lightgray:=7;
gray:=8;
darkgray:=9;
orange:=10;
turquoise:=12;
lightblue:=13;
lightorange:=14;
yellow:=15;

Reset Euler

Resetting Euler is best done with the menu item, or with Ctrl-N. Then Maxima is restarted too. All variables are lost. You will be asked to save your notebook first. After reset, Euler calls the reset function below.

Epsilon:=epsilon();
ResetEpsilon:=epsilon();
ResetView:=_view();
I$:=I;
verticallabels:=0;
E$:=E;
eulergamma:=0.577215664901532860606512;
function Pi () := pi();
function reset 

  Resets many internal settings.
  
  This function resets the default settings for colors, line width,
  the default view, and other basic settings for Euler graphics. It
  does also unclip the window, and release the hold flag.
  
  Moreover, the function resets the default format to long, and
  restores the default epsilon.
  
  See: 
restart (Euler Core)
function resetepsilon 

  Reset the default epsilon and return the current epsilon.
function exec (program:string, param:string="", dir:string="",
    print:integer=0, hidden:integer=0, wait:integer=1)

  Execute an external program
  
  This is a utility function for the built-in exec command. It runs
  an external program, and by default waits for it to finish. The
  result of the program can be returned in form of vector of strings.
  Communication is via standard named pipes. The pipes stdout and
  stderr are read as output from the program.
  
  If wait is false and print is true, the function starts the
  program, and generates pipes to and from the program. These pipes
  can later be written to with execwrite(string) or
  execwriteln(string) and read from with execread(), returning a
  vector of strings. Only one such program is available. Trying to
  start a second program with open pipes terminates the first one.
  
  program : the name of the program (plus path, if not in the system
  path).
  
  param : Parameters separated by blanks. If the parameters contain
  blanks, they must be enclosed by double quotes. Use strings as in
  
  param=''"first parameter" "second parameter"''
  
  dir : The working directory of the program. This can be used to
  locate the program instead of a full path.
  
  print : If true and wait is false, the function returns the output
  immediately in form of a vector of strings. If true and wait is
  true, the program will print the output of the program.
  
  hidden : If true, no window will be generated.
  
  wait : If true, the function will wait for the command to be
  finished, or for the escape key.
  
  Examples:
  
  >exec("cmd","/c dir /w *.en",home(),>print,>hidden,>wait)
  Volume in Laufwerk C: hat keine Bezeichnung.
  Volumeseriennummer: ECF3-71E6
  
  Verzeichnis von C:\euler\docs\Programs
  ...
  
  >filename=eulerhome()+"test.txt"; ...
  writematrix(random(5,5),filename,"%1.5f"); ...
  exec("cmd","/c start "+filename,eulerhome(),<wait);
  
  >exec("cmd","",home(),>print,>hidden,<wait);
  >execwriteln("dir /w");
  >execread()
  Microsoft Windows [Version 6.1.7601]
  Copyright (c) 2009 Microsoft Corporation. Alle Rechte vorbehalten.
  ...
  >execkill();
  
  See: 
exec (Euler Core),
execwrite (Euler Core),
execwriteln (Euler Core),
execread (Euler Core)

Vector and Matrix Functions

Functions to generate matrices or vectors with values spaced in various ways, as well as functions providing informations about vectors and matrices.

function matrix 

  matrix(v1,v2,v3,...) returns a matrix with rows v1,v2,v3,...
function equispace (a:real scalar, b:real scalar, n: positive integer scalar)

  Generates n+1 arcsin spaced values in [a,b].
  
  The arcsin distribution generates points which are the extremal
  points of the Chebyshev polynomial. These points are well suited
  for discrete approximation on an interval.
  
  See: 
linspace (Euler Core),
chebzeros (Basic Utilities)
function chebzeros (a: real scalar, b: real scalar, n: positive integer scalar)

  Generate the zeros of the n-th Chebyshev polynomial in [a,b]
  
  See: 
linspace (Euler Core),
equispace (Basic Utilities)
function length (v)

  Returns the length of a row or column vector.
  
  In fact, the function returns the maximum of the number of rows,
  and the number of columns of a matrix.
function differences (s)

  Computes vector of the differences s[i+1]-s[i]
  
  See: 
fold (Euler Core)
function tail (s, n:integer)

  The rest of the vector s starting from the n-th element.
  
  tail(s,-2) returns the last two elements of s.
  
  See: 
head (Basic Utilities)
function head (s, n:integer)

  The vector, up to the n-th element
  
  The function works for negative n too. head(s,-2) returns all
  elements, but the last.
  
  See: 
tail (Basic Utilities)
function field (x:vector, y:vector)

  Returns {X,Y} such that the X+i*Y is a rectangular grid
  
  x and y must be 1xN and 1xM vectors.
  
  This is not necessary in most cases, since operators in the Euler
  matrix language combine x and y' automatically.

Text Menus

This is a simple text menu. It can be used for files with a user choice of options.

function menu ()

  Displays a menu and returns the number of the chosen item
  
  This is a simple menu in text form inside the text window of Euler.
  The menu items are the arguments to this function. The items should
  be labelled (a), (b), etc. The user can press the keys a, b, etc.,
  or the return key. In this case, the functin returns -1. Else the
  function returns the number of the chosen argument.

Number Bases

Functions for hexadecimal or binary input and conversion.

function baseinput (s:string, b:index=16)

  Read a number in base b.
function hex (s:string)

  Convert a hex string.
  
  See: 
printhex (Basic Utilities),
baseinput (Basic Utilities)
function dual (s:string)

  Convert a hex string.
  
  See: 
printdual (Basic Utilities),
baseinput (Basic Utilities)
function printbase (x:real scalar, base:index=16, digits=13,
    integer=false)

  Prints the real number x with mantissa and exponent to base b.
  
  The output is of the form 1.xxxxx...xxx*2^n with mantissa of
  length digits. If integer is true, the value is assumed to
  be integer, and it prints in the form xxxxx. x is between 0 and
  base, where A=11, B=12, etc.
  
  >dual("10001001"), printdual(%,>integer)
  137
  10001001
  >baseinput("24256",7), printbase(%,base=7,>integer)
  6313
  24256
  >6+5*7+2*7^2+4*7^3+2*7^4
  6313
  
  See: 
baseinput (Basic Utilities)
function printdual (x:real scalar, integer=false, length=1)

  Prints the real number x with dual mantissa.
  
  The output is of the form 1.xxxxx...xxx*2^n. If integer is true,
  then the output is of the form xxxxxx with x=0 or x=1.
  
  >dual("10001001"), printdual(%,>integer)
  137
  10001001
  >printdual(0.1)
  1.1001100110011001100110011001100110011001100110011010*2^-4
  
function printhex (x:real scalar, integer=false)

  Prints the real number x with hexadecimal mantissa.
  
  The output is of the form 1.xxxxx...xxx*16^n. If integer is true
  the output is of the form xxxxx where x is 0,...,9,A,B,C,D,E,F.
  
  >hex("DDFFD"), printhex(%,>integer)
  909309
  DDFFD
  >printhex(0.1)
  1.999999999999A*16^-1
  
function printstr (x, n:index, mode=1)

  String with x and n characters according to mode
  
  mode=-1 : left justified
  mode=0 : centered
  mode=1 : right justified

Interpolation

Aliases to function in Euler Core

function interpolate (x:vector, y:vector)

  Interpolate the values in y at x
  
  Alias to interp. Return the vector of divided differences.
  
  See: 
interp (Euler Core),
evaldivdif (Basic Utilities)
function evaldivdif (t:numerical, d:vector, x:vector)

  Evaluate the divided differences d at t
  
  Works like interpval with other order of parameters. The first
  parameter contains the points, where the polynomial should be
  evaluated.
  
  Example:
  >evalpoly(0:10,[0,0,1]) // x^2
  [ 0  1  4  9  16  25  36  49  64  81  100 ]
  
  See: 
evalspline (Numerical Algorithms)
function evalpoly (t:numerical, p:vector)

  evaluates a polynomial p in t.
  
  Polynomials are stored as a row vector with the constant
  coefficient in front. The function works for complex polynomials
  too.

Date

function day (y:integer scalar, m:integer scalar, d:integer scalar, ..
    h:integer scalar=0, min:real scalar=0)

  Converts a date to a number of days.
  
  The computation is based on the Gregorian calendar.
  
  >day(2020,1,1)-day(2010,1,1)
  3652
  
  See: 
date (Basic Utilities)
function date (d:number)

  Convers a day number to the date.
  
  >{y,m,d,h,min}=date(day(2012,11,1,23,12)); [y,m,d,h,min]
  [ 2012  11  1  23  12 ]
  
  See: 
day (Basic Utilities)
function printdate (y:integer scalar, m:integer scalar, d:integer scalar, ..
    h:integer scalar=0, min:integer scalar=0, sec: integer scalar=none)

  Prints a day
  
  >printdate(date(day(2011,9,11,12)+1000))
  2014-06-07 12:00

Continued Fractions

function contfrac (x,n=10)

  Compute the continued fraction of x.
  returns [a,b,c,...] with
  x = a + 1 / (b + 1 / (c + 1/(...
function contfracval (r)

  Evaluate the continued fraction
  x = a + 1 / (b + 1 / (c + 1/(...
  with r = [a,b,c,...]
  Return an Interval {x1,x2}
function contfracbest (x,n=3)

  Return the best rational
  approximation to x

Utilities

function isstring (x)

  Tests, if x is a string.
function expreval (expr:string, x)

  Evaluate the expression, using x and global variables
  
  Note that the variable x is given as a parameter. Other variables
  can be set using assigned variables, as in expreval("x*y",3,y=4).
  Moreover, global variables can be used. Local variables in the
  calling functions cannot be used, however.
  
  This works very much line expr(x), or "a*x*y"(3,4,a=5).
function case (b:real, x, y)

  Returns x, if b!=0, else y.
  
  This function works like if, but evaluates both, x and y. It works
  for matrices b, x and y too.
function max 

  max(A) or max(x,y,...)
  
  Returns the maximum of the rows of A for one argument,
  or the maximum of x,y,z,... for several arguments.
  
  See: 
max (Euler Core),
max (Maxima Documentation)
function min 

  min(A) or min(x,y,...)
  
  Returns the minimum of the rows of A for one argument,
  or the minimum of x,y,z,... for several arguments.
  
  See: 
min (Euler Core),
min (Maxima Documentation)
function unique (v)

  Unique elements of v
  
  This functions uses a buit-in function for arrays of reals.
  
  Returns {w,i} where w is a vector of unique elements and i are the
  indices of these elements
  
  See: 
unique (Euler Core),
unique (Maxima Documentation)

Matrix Functions

function fliplr (A:numerical)

  flips a matrix horizontally.
function flipud (A:numerical)

  flips a matrix vertically.
function rot90 (A:numerical)

  rotates a matrix counterclockwise
function rot (A:numerical, k:integer=1)

  rotates a matrix counterclockwise k times 90 degrees

Documentation Homepage