home *** CD-ROM | disk | FTP | other *** search
/ Crawly Crypt Collection 1 / crawlyvol1.bin / apps / math / euler / doc / euler.doc next >
Text File  |  1993-04-16  |  56KB  |  1,519 lines

  1.  
  2.  
  3.                     EULER, The numerical Laboratory
  4.                  ======================================
  5.  
  6.                            Documentation
  7.                        =====================
  8.  
  9.                             Version 3.04
  10.                          ==================
  11.  
  12.  
  13.  
  14.  
  15. INTRODUCTION
  16. ------------
  17.  
  18. EULER consists of the following files:
  19.  
  20.     EULER (the program, which may also have another name)
  21.     EULER.CFG (is loaded after start of the program)
  22.     UTIL.E (is loaded from EULER.CFG)
  23.  
  24. There are some additional files, which help using the program:
  25.  
  26.     HELP.E (help texts)
  27.     DEMO.E (a demo file, see the demo section)
  28.     EULER.DOC (this file)
  29.     EXPAMPLES.DOC (some example sessions)
  30.  
  31. To load EULER, copy the above files in a directory, and start EULER. A
  32. startup screen indicating the version date will appear. The program
  33. will prompt for input, using a DOS-like text screen.
  34.  
  35. The idea of EULER is a system with the following features:
  36.  
  37. - Interactive evaluation of numerical expressions with real or complex
  38.   values, vectors and matrices, including use of variables.
  39. - Built in functions that can take vectors as input and are then
  40.   evaluated for each element of the vector or matrix.
  41. - Matrix functions.
  42. - Statistical functions and random numbers.
  43. - 2D- and 3D-plots.
  44. - A built in programming language with parameters and local variables.
  45. - An online help.
  46. - A tracing feature for the EULER programming language.
  47.  
  48. These features make EULER an ideal tool for the tasks such as:
  49.  
  50. - Inspecting and discussing functions of one real or complex variable.
  51. - Viewing surfaces in parameter representation.
  52. - Linear algebra and eigenvalue computation.
  53. - Testing numerical algorithms.
  54. - Solving differential equations numerically.
  55. - Computing polynomials.
  56.  
  57.  
  58. THE COMMAND LINE
  59. ----------------
  60.  
  61. If EULER is started from a shell, command line parameters for EULER can
  62. be entered. These parameter must be file names and those files are
  63. loaded after the start of EULER (See "loading a file"). Note, that the
  64. file EULER.CFG is always loaded as first file.
  65.  
  66. The file EULER.CFG contains some commands to set up the EULER system,
  67. like defining the default file. It does in turn load the file UTIL.E.
  68. UTIL contains functions which are written in the EULER programming
  69. language and can be considered a part of EULER. But the user should
  70. feel free to change the content of UTIL to his own needs.
  71.  
  72.  
  73. THE DEMO AND THE ONLINE HELP
  74. ----------------------------
  75.  
  76. The best way to get a good idea of EULER is to run the demo. To do that
  77. issue the command
  78.     >load "demo"
  79. Do not enter the prompt ">" and press the Return key. Of course, the
  80. file DEMO must be in the active directory. To get a print of the
  81. output of the demo, enter
  82.     >dump "demo.txt"; load "demo"; dump;
  83. Then the file "demo.txt" will contain the demo texts. If
  84. the demo is interrupted (by the Escape key), the command
  85.     >dump;
  86. must be entered to close the file "demo.txt".
  87.  
  88. You can also learn to program EULER by studying the demo file.
  89.  
  90. It is a good idea to make a print of the HELP file, since all
  91. functions are explained in that file. To load the online help, enter
  92.     >load "help";
  93. Then
  94.     >help command
  95. will show the help text of the command (see "programming EULER").
  96.  
  97.  
  98. THE LINE EDITOR
  99. ---------------
  100.  
  101. Text can be entered after the prompt (>) using the keyboard. If a
  102. letter is mistyped, it can be cancelled with the Backspace key. The
  103. cursor keys -> and <- position the cursor back and forth in the line.
  104. The line editor is always in insert mode, so any character is inserted
  105. at the cursor position. Shift plus <- positions the cursor to the
  106. beginning of the line, and Shift plus -> to the end of the line.
  107. Clr-Home clears all input (Contrl-Up or Escape on some machines).
  108. Control plus -> or <- position the cursor one word to the right or
  109. left. Finally, the input is entered by pressing Return. Then EULER
  110. will start to interpret the command. Note, that the cursor can be at
  111. any position of the input line, when Return is pressed.
  112.  
  113. Previous input can be recalled with the cursor-up and cursor-down
  114. keys. If a command is recalled this way and entered with Return,
  115. cursor-down recalls the next command; i.e., cursor-up and cursor-down
  116. are always based on the last recalled command. Pressing Clr-Home (see
  117. above) not only clears the input line, but also makes the last command
  118. the base for recalling. Thus Clr-Home plus cursor-up recalls the
  119. previous command.
  120.  
  121. Pressing the Help key (or the insert key, depending on the version)
  122. extends incomplete commands. Pressing this key again gives another
  123. extension, if there is one. The search goes through the command
  124. history, the implemented functions, the user defined functions and the
  125. builtin commands in that order.
  126.  
  127. There are some other special keys. The Tabulator (TAB, or some other key,
  128. depending on the program version) key switches to the Graphics screen
  129. and from there any key switches back. The Esc key stops any running
  130. EULER program and some internal functions, like the 3-dimensional
  131. plots, the linear equation solver and the polynomial root finder.
  132.  
  133. Input can spread over several lines by the use of "..". The two dots
  134. are allowed at any place, where a space is acceptable. E.g.
  135.     >3+ .. some comment
  136.     >4
  137. is equivalent to
  138.     >3+4
  139. Comments can follow the ".." and are skipped.
  140.  
  141. The function keys may be programmed by the command
  142.     >setkey(number,"text");
  143. The number must be between 1 and 10 and the "text" may be any EULER
  144. string. Then the corresponding function key will produce the text,
  145. when it is pressed. If the function key text is to contain a ", one
  146. can use char(34) and the EULER string concatenation, as in the example
  147.     >setkey(1,"load "|char(34)|"test"|char(34)|";");
  148. which puts
  149.     >load "test";
  150. on the function key F1.
  151.  
  152.  
  153. THE DATA TYPES
  154. --------------
  155.  
  156. EULER uses the following data types
  157.  
  158. - real numbers
  159. - complex numbers
  160. - real matrices
  161. - complex matrices
  162. - strings
  163. - references
  164. - programs
  165.  
  166. The meaning of the first five data types should be clear. EULER tries
  167. to keep an evaluation real. But as soon, as complex data is involved
  168. the computation gets complex. That is why
  169.     >sqrt(-1)
  170. results in NaN (not a number), but
  171.     >sqrt(complex(-1))
  172. gives 0+1*i. complex(x) is a way to turn a number complex. See the
  173. section on expressions for more information on how to enter these
  174. data types.
  175.  
  176. Strings are only used for explaining output, file names and function
  177. key texts. There are only two string operators, the concetanation |
  178. and the function stringcompare.
  179.  
  180. References are used internally for parameters of functions (see the
  181. programming section).
  182.  
  183. Programs are the user defined programs including the functions in
  184. UTIL. 
  185.  
  186. All these data are kept on the stack. Usually, the user does not have
  187. to worry about the stack, since EULER uses normal mathematical notation
  188. for expressions. Internally, the evaluation of an expression uses the
  189. stack rather heavily. Programs are kept in the lower area of the stack.
  190. The stack is also used to pass parameters to builtin or user defined
  191. functions and to keep the local variables of these functions.
  192.  
  193. Finally, we remark that the data explained in this section are
  194. different from builtin functions which can be used in the same places
  195. as user defined functions. There are also "commands", which cannot be
  196. used in expressions. Builtin functions and commands are part of the
  197. code of EULER.
  198.  
  199. A complete list of builtin functions, commands and user defined
  200. functions is printed by
  201.     >list
  202. If more information is needed, the command
  203.     >memorydump
  204. is available. A hexdump of any data can be optained with
  205.     >hexdump name
  206. but it will only be useful for insiders.
  207.     >store("filename")
  208. stores the content of the EULER stack into a file.
  209.     >restore("filename")
  210. loads that file. This is a short way of storing a session including
  211. the global variables and functions.
  212.  
  213.  
  214. ENTERING INPUT
  215. --------------
  216.  
  217. EULER input is either a "command", an "expression" or an "assignment".
  218. An example for a command is
  219.     >quit
  220. which quits the EULER system. By and by, we will mention a few others.
  221. Another example is "load".
  222.  
  223. An expression is a valid EULER expression, which has a resulting
  224. value. If it is entered on its own or followed by a comma, this value
  225. is printed.
  226.     >3+4*5
  227. prints the value 23.00000. The print is surpressed, if the expression
  228. is followed by a ";", like in the setkey example above. This makes
  229. sense, since some functions have side effects and their result is not
  230. needed, of since the user does not want to see the long output of
  231. an assignment (see below).
  232.  
  233. The printing is done with a format determined by the function
  234.     >format([n,m])
  235. where n is the total width of print and m is the number of digits after
  236. the decimal dot.
  237.     >format(n,m)
  238. does the same thing, but is a little bit slower since it is a function
  239. in UTIL. The output automatically switches to exponential format, if
  240. there is not enough space to display the number in fixed format.
  241.     >longformat()
  242. is a function in UTIL, which sets a longer output format, while
  243.     >shortformat()
  244. sets a shorter one.
  245.  
  246. An assignment looks like
  247.     >variablename=value
  248. It assigns the value to the variable, which is declared by the
  249. assignment, and prints the value. If the assignment is followed by a
  250. ";", then the printing is surpressed. An assignment may be followed by
  251. ",", which prints the right hand side of the assignment.
  252.  
  253. There are also multiple assignments (see below).
  254.  
  255.  
  256. Expressions
  257. -----------
  258.  
  259. The most simple expressions are variables. Their value is the value
  260. of the variable, and their type is the type of the variable. If the
  261. variable is undefined, interpreting the expressions will stop with
  262. an error message.
  263.  
  264. The basic constant expressions are numbers. Those are entered in the
  265. usual form 100, 100.0, 1e2, or 1.0e+2. The letter "small e" indicates
  266. powers of 10. An appendix "i" indicates multiples of the complex unit
  267. "i". "1+1i" is in fact a sum of 1 and 1i.
  268.  
  269. A matrix is entered in the brackets "[" and "]" row by row. The columns
  270. are seperated by "," and the rows by ";". Example:
  271.     >A=[1,2,3;4,5;6]
  272. This is equivalent with
  273.     >A=[1,2,3;4,5,0;6,0,0]
  274. The matrix is real, if all entries are real, otherwise it is complex.
  275. If a row is shorter than the others, it is filled with zeros. A matrix
  276. constant can spread over several lines. 
  277.  
  278. A submatrix is a matrix, which is made up by the entries of another
  279. matrix. The simplest example is a matrix element
  280.     >A[1,1]
  281. which gives the element in the first row and column of A. Note, that
  282. submatrices can be assigned values. Thus
  283.     >A[1,1]=4.5
  284. is a legal statement. If a submatrix gets complex, the matrix gets
  285. complex. If v is a 1xN or Nx1 matrix (i.e., a vector), then v[1] gives
  286. the first element of v; i.e.,
  287.     >v=[1.5,-2,0,4.8]; v[3]
  288. gives 0. Let us now assume, that A is a matrix, and r and c are
  289. vectors. Then A[r,c] results in a matrix, which consists of the rows
  290. r[1],r[2],... of A, and from these rows, only the columns c[1],c[2],...
  291. are taken. Example:
  292.     >A[[1,2],[1,2]]
  293. is the upper left 2x2 submatrix of A. If a row or column does not
  294. exist, it is simply neglected. Thus, if A is a 4x4 matrix, then
  295. A[[4,7],[4,7]] results in the value A[4,4]. A special thing is A[1],
  296. which gives the first row of A. To be precise, if only one index is
  297. present, then the second index is assumed to be ":". A ":" indicates
  298. all rows or columns; i.e., A[:,1] is the first column of A, and A[:,:]
  299. is A itself. Another example:
  300.     >v=[-1,-2,-3,-4,-5]; v[[5,4,3,2,1,1]]
  301. gives the vector [-5,-4,-3,-2,-1,-1]. If A is a 4x4 matrix, then
  302. A[[2,1]] gives a 2x4 matrix, which consists of the second row of A on
  303. top of the first row. Note, that there may be a 0xN or Nx0 matrix.
  304.  
  305. For compatibility reasons, the square brackets can be replaced by
  306. round brackets. Thus, A(1,1) is the same thing as A[1,1]. But
  307. A[1,1] is faster. Furthermore, if there is a function A, then A(1,1)
  308. will result in a function call to A.
  309.  
  310. A{i} gives the i-th element of the matrix A, as if the NxM Matrix A
  311. was a vector of length N*M. This is useful for making functions
  312. work for matrices, and is really the quickest way to access a matrix
  313. element. It works also, if the matrix A is to small or a real or
  314. complex variable. Then the result is the last element of A.
  315.  
  316. String constants are enclosed in double quotes, like in
  317.     >string="This is a text"
  318. The section on the line editor shows how to insert a double quote into
  319. a string. A single character with ASCII code n can be produced by
  320.     >char(n)
  321.  
  322. If A is a matrix expression (an expression of type matrix), then A'
  323. is the transposed matrix. 
  324.  
  325. The ":" serves to generate a vector quickly. Thus
  326.     >1:10
  327. generates the vector [1,2,3,4,5,6,7,8,9,10]. A step size may be given
  328. as in the example
  329.     >5:-1.5:1
  330. which yields [5,3.5,2]. By numerical reasons, one cannot expect to
  331. hit 1 exactly with 0:0.1:1. However, the program uses the internal
  332. epsilon to stop generating the vector, so that 0:0.1:1 yields the
  333. desired result. By default, the internal epsilon is set so that
  334. even
  335.     >0:0.0001:1
  336. works correctly. 
  337.  
  338. The binary operator "|" puts a matrix aside another; i.e., if A is a
  339. NxM matrix and B is a NxK matrix, then A|B is a Nx(M+K) matrix, which
  340. consists of A left of B. Analogously, A_B puts A atop of B. These
  341. operators work also for numbers, which are treated as 1x1 matrices.
  342. They do even work, if A is a Nx0 or 0xN matrix.
  343.  
  344. The mathematical operators +,-,*,/ work as usual for numbers. For
  345. matrices they work elementwise. The matrix product of A and B is
  346. computed by "A.B". If a is a number and B a matrix, then a+B or
  347. B+a computes the sum of all elements of B with a. This also holds
  348. for the other operators. Of course, -A negates all elements of A.
  349. EULER knows the rule, to compute "*" and "/" before "+" and "-".
  350. One can also write ".*","./" for compatibility with MATLAB. If
  351. A has a different size as B, and neither A or B is a 1x1 matrix or
  352. a number, then A+B results in error.
  353.  
  354. Of course, one can use the round brackets ( and ) to group expressions
  355. like in
  356.     >(1+5)*(6+7^(1+3))
  357.  
  358. The power operator can be written "^" or "**" (or ".^"). It computes
  359. the power elementwise, like all the other operatos. So
  360.     >[1,2,3]^2
  361. yields [1,4,9]. The power may also be negative; i.e., the integer
  362. powers of all numbers are defined. For a matrix, inv(A) computes the
  363. inverse of A (not "A^-1"!). Note, that "^" has precedence, so
  364.     >-2^2
  365. gives -4.
  366.  
  367. Comparison of values can be performed with  >,    >=, <, <=, != (not
  368. equal) or == (equal). They result in 1 or 0, where 1 is TRUE. Again,
  369. these operators work elementwise; i.e,
  370.     >[1,2,3,4]>2
  371. yields [0,0,1,1].
  372.  
  373.     >!A
  374. (not A) gives a matrix, which is 1 on all zero elements of A, and 0 on
  375. all nonzero elements of A. 
  376.     >A && B
  377. gives a matrix, which is 1 whenever the corresponding elements of A
  378. and B are nonzero. 
  379.     >A || B
  380. is 1 whenever the corresponding element of A is nonzero or the
  381. corresponding element of B is nonzero.
  382.     >any(A)
  383. yields 1 if any element of A is nonzero.
  384.  
  385. If S and T are strings, then S|T consists of the string T appended to
  386. S.
  387.  
  388.  
  389. GENERATING A MATRIX
  390. -------------------
  391.  
  392. There are several builtin functions which generate matrices. The most
  393. elementary ones are zeros([N,M]) and ones([N,M]), which can also be
  394. written zeros(N,M) and ones(N,M). They produce a NxM matrix, which is
  395. filled with ones or zeros respectively. The first form, which gives
  396. the size in a 1x2 vector, is faster, since the second form is not a
  397. builtin function, but a user defined function from UTIL. The input for
  398. zeros and ones is the output of the "size" function, which gives [N,M]
  399. for size(A), if A is an NxM matrix. Note, that one can also generate
  400. 0xN and Nx0 matrices. So
  401.     >zeros[0,5]_v_v
  402. is a legal statement, if v is a 1x5 vector. It is also possible to
  403. give size several arguments. Then
  404.     >size(A,B,...)
  405. results in the size of the largest matrix of A,B,... However, all
  406. matrixes in the list must have the same size, unless their size is
  407. 1x1. The use of this feature will become apparent later on. Also
  408.     >cols(A)
  409.     >rows(A)
  410. return the number of columns and rows of a matrix A.
  411.     >length(A)
  412. it the maximum of the number of columns and rows.
  413.  
  414. More generally,
  415.     >matrix([N,M],x)
  416. or matrix(N,M,x) returns a NxM matrix filled with x, which may be real
  417. or complex.
  418.  
  419.     >diag([N,M],K,v)
  420. produces a NxM matrix, which has the vector v on its K-th diagonal and
  421. is 0 everywhere else. If v is not long enough, the last element of v
  422. is taken for the rest of the diagonal. The 0-th diagonal is the main
  423. diagonal, the 1-st the one above, and the -1-st the one below. So
  424.     >diag([5,5],0,1)
  425. produces the 5x5 identity matrix. The same can be achieved with
  426.     >id(5) 
  427. from UTIL. One can also write diag(N,M,K,v), as this is defined in UTIL.
  428.     >diag(A,K)
  429. gives a vector, which is the K-th diagonal of A.
  430.  
  431.     >dup(v,N)
  432. duplicates the 1xM vector N times, such that a NxM matrix is generated,
  433. which has v in each row. If v is an Mx1 vector, then v is duplicated
  434. into the N columns of a MxN matrix. dup works also, if v is a number.
  435. Then it generates a column vector.
  436.  
  437.     >B=band(A,N,M)
  438. sets all elements of A[i,j] to 0, unless N <= i-j <= M.
  439.     >B=setdiag(A,N,v)
  440. sets the N-th diagonal of A to v. v may be a number or a vector.
  441.     >bandmult(A,B)
  442. multiplies to matrices A and B (like A.B), but is considerably faster,
  443. if A and B contain lots of zeros.
  444.     >symmult(A,B)
  445. multiplies symmetric matrices A and B and saves half of the time.
  446.  
  447. Furthermore,
  448.     >flipx(A)
  449. flips the matrix, such that the last column becomes the first, the first
  450. column the last.
  451.     >flipy(A)
  452. does the same to the rows.
  453.  
  454.  
  455. LOADING A FILE
  456. --------------
  457.  
  458. To abbreviate tedious input one may generate a file containing EULER
  459. commands. This file can be generated with any editor (like 1STWORD,
  460. TEMPUS or so). To load that file enter
  461.     >load "filename"
  462. All lines of that file are then interpreted just as any other input
  463. from the keyboard. Also a loaded file may itself contain a load command.
  464. If an error occurs, the loading is stopped and an error message is
  465. displayed. There is a default extension ".e", which you should use for
  466. your files. You need not specify this extension in the load command.
  467.  
  468. The best use of a load file is to define functions in that file (see
  469. "programming EULER").
  470.  
  471.  
  472. BUILTIN FUNCTIONS
  473. -----------------
  474.  
  475. In this section some basic builtin functions are explained. There are
  476. the usual functions:
  477.  
  478. abs, sqrt, exp, log, sin, cos, tan, asin, acos, atan, re, im, conj.
  479.  
  480. They all work for complex values. In this case they yield the
  481. principle value. There are some functions which make sense only
  482. for real values:
  483.  
  484. floor, ceil, sign, fak, bin.
  485.  
  486. floor and ceil give integer approximations to a real number. "bin(n,m)"
  487. computes the binomial coefficient of n and m.
  488.  
  489.     >pi()
  490. (or simply ">pi") is a builtin constant.
  491.     >epsilon()
  492. is an internal epsilon, used by many functions and the operator ~=
  493. which compares two values and returns 1 if the absolute difference is
  494. smaller than epsilon. This epsilon can be changed with the statement
  495.     >setepsilon(value)
  496.  
  497.     >round(x,n)
  498. rounds x to n digits after the decimal dot. It also works for complex
  499. numbers. x may be a matrix.
  500.  
  501.     >mod(x,y)
  502. return x modulus y.
  503.  
  504.     >max(x,y)
  505. and min(x,y) return the maximum (minimum resp.) of x and y.
  506.     >max(A)
  507. and min(A) return a column vector containting the maxima (minima resp.)
  508. of the rows of A.
  509.  
  510. If A is a NxM matrix, then
  511.     >extrema(A)
  512. is a Nx4 matrix, which contains in each row a vector of the form
  513. [min imin max imax], where min and max are the minima and maxima of
  514. the corresponding row of A, and imin and imax are the indices, where
  515. those are obtained.
  516.  
  517. If v is a 1xN vector, then
  518.     >nonzeros(v)
  519. returns a vector, containing all indices i, where v[i] is not zero.
  520. Furthermore,
  521.     >count(v,M)
  522. returns a 1xM vector, the i-th component of which contains the number
  523. of v[i] in the interval [i-1,i).
  524.     >find(v,x)
  525. assumes that the elements of v are ordered. It returns the index (or
  526. indices, if x is a vector) i  such that v[i] <= x < v[i+1], or 0 if
  527. there is no such i.
  528.     >sort(v)
  529. sorts the elements of v with the quicksort algorithm.
  530.  
  531. If A is NxM matrix
  532.     >sum(A)
  533. returns a column vector containing the sums of the rows of A.
  534. Analoguously,
  535.     >prod(A)
  536. returns the products.
  537.     >cumsum(A)
  538. returns a NxM matrix containing the cumulative sums of the columns of A.
  539.     >cumprod(A)
  540. works the same way. E.g.,
  541.     >cumprod(1:20)
  542. returns a vector with faculty function at 1 to 20.
  543.  
  544. The only string function in EULER is
  545.     >stringcompare("string1","string2")
  546. which returns 0, if the strings are equal, -1 if string1 is
  547. alphabetically prior to string2, and 1 else.
  548.  
  549.     >time()
  550. returns a timer in seconds. It is useful for benchmarks etc.
  551.     >wait(n)
  552. waits for n seconds or until a key was pressed.
  553.     >key()
  554. waits for a keypress and returns the internal scan code.
  555.  
  556.  
  557. LINEAR ALGEBRA
  558. --------------
  559.  
  560. There are lots of builtin functions to perform linear algebra. The
  561. matrix product has already been discussed. The operation
  562.     >A\b
  563. takes a NxN matrix A and a Nx1 vector b and returns the vector x such
  564. that Ax=b. If in
  565.     >A\B
  566. B is a NxM matrix, then the systems A\B[:,i] are solved simultanuously.
  567. An error is issued if the determinant of A turns out to be to small
  568. relative to the internal epsilon.
  569.     >inv(A)
  570. computes the invers of A. This is a function in UTIL defined as
  571.     >A\id(cols(A))
  572.  
  573. There are also more primitive functions, like
  574.     >lu(A)
  575. for NxM matrices A. It returns multiple values, which needs explaining.
  576. You can assign its return values to variables with
  577.     >{Res,ri,ci,det}=lu(A)
  578. If you use only
  579.     >Res=lu(A)
  580. all other output values are dropped. To explain the output of lu, lets
  581. start with Res. Res is a NxM matrix containing the LU-decomposition of
  582. A; i.e., L.U=A with a lower triangle matrix L and an upper triangle
  583. matrix U. L has ones in the diagonal, which are omitted so that L and
  584. U can be stored in Res. det is of course the determinant of A. ri
  585. contains the indices of the rows of lu, since during the algorithm the
  586. rows may have been swept. ci is not important if A is nonsingular. If
  587. A is singular, however, Res contains the result of the Gauss algorithm.
  588. ri contains 1 and 0 such that the columns with 1 form a basis for the
  589. columns of A.
  590.  
  591. lu is used by several functions in UTIL.
  592.     >kernel(A)
  593. gives a basis of the kernel of A; i.e., the vectors x with Ax=0.
  594.     >image(A)
  595. gives a basis of the vectors Ax.
  596.  
  597. The primitive function for computing eigenvalues currently implemented
  598. is
  599.     >charpoly(A)
  600. which computes the characteristic polynomial of A. This is used by
  601.     >eigenvalues(A)
  602. to compute the eigenvalues of A. Then
  603.     >eigenspace(A,l)
  604. computes a basis of the eigenspace of l.
  605.     >{l,X}=eigen(A)
  606. returns the eigenvalues of A in l and the eigenvectors in X.
  607.  
  608.  
  609. STATISTICAL FUNCTIONS
  610. ---------------------
  611.  
  612. EULER supports statistical functions, such as distribution integrals
  613. and random variables.
  614.  
  615. First of all,
  616.     >random(N,M)
  617. or random([N,M]) generates an NxM random matrix with uniformly
  618. distributed values in [0,1]. It uses the internal random number
  619. generator of ANSI-C. The quality of this generator may be doubtful;
  620. but for most purposes it should suffice. The function
  621.     >normal(N,M)
  622. or normal([N,M]) returns normally distributed random variables with
  623. mean value 0 and standart deviation 1. You should scale the function
  624. for other mean values or deviations.
  625.  
  626. A function for the mean value or the standart deviation has not been
  627. implemented, since it is easily defined in EULER; e.g,
  628.     >m=sum(x)/cols(x)
  629. is the mean value of the vector x, and
  630.     >d=sqrt(sum((x-m)^2)/(cols(x)-1))
  631. the standart deviation.
  632.  
  633. Rather, some distributions are implemented.
  634.     >normaldis(x)
  635. returns the probability of a normally dstributed random variable being
  636. less than x.
  637.     >invnormaldis(p)
  638. is the inverse to the above function. These functions are only accurate
  639. to about 4 digits. However, this is enough for practical purposes and
  640. an improved version is easily implemented with the Romberg or Gauss
  641. integration method.
  642.  
  643. Another distribution is
  644.     >tdis(x,n)
  645. It the T-distrution of x with n degrees of freedom; i.e., the
  646. probability that n the sum of normally distributed random variables
  647. scaled with their mean value and standart deviation are less than x.
  648.     >invtdis(p,n)
  649. returns the inverse of this function.
  650.  
  651.     >chidis(x,n)
  652. returns the chi^2 distribution; i.e., the distribution of the sum of
  653. the squares n normally distributed random variables.
  654.     >fdis(x,n,m)
  655. returns the f-distribution with n and m degrees of freedom.
  656.  
  657. Other functions have been mentioned above, like bin, fak, count, etc.,
  658. which may be useful for statistical purposes.
  659.  
  660.  
  661. POLYNOMIALS
  662. -----------
  663.  
  664. EULER stores a polynomial a+bx+...+cx^n in the form [a,b,...,c]. It
  665. can evaluate a polynomial with the Horner scheme
  666.     >polyval(p,x)
  667. where x can be a matrix, of course. It can multiply polynomials with
  668.     >polymult(p,q)
  669. or add them with
  670.     >polyadd(p,q)
  671. Of course, the polynomials need not have the same degree.
  672.     >polydiv(p,q)
  673. divides p by q and returns {result,remainder}.
  674.     >polytrunc(p)
  675. truncates a polynomial to its true degree (using epsilon). In UTIL
  676.     >polydif(p)
  677. is defined. It differentiates the polynomial once. To construct a
  678. polynomial with prescribed zeros z=[z1,...,zn]
  679.     >polycons(z)
  680. is used. The reverse is obtained with
  681.     >polysolve(p)
  682. This function uses the Bauhuber method, which converges very stabelly
  683. to the zeros. However, there is always the problem with multiple zeros
  684. destroying the accuracy (but not the speed of convergence). Another
  685. problem is the scaling of the polynomial, which can improve the
  686. stability and accuracy of the method considerably.
  687.  
  688. Polynomial interpolation can be done by
  689.     >d=interp(t,s)
  690. where t and s are vectors. The result is a polynomial in divided
  691. differences (Newton) form, and can be evaluated by
  692.     >interpval(t,d,x)
  693. at x. To transform the Newton form to the usual polynomial form
  694.     >polytrans(t,d)
  695. may be used. Interpolation in the roots of unity can be done with
  696. the fast Fourier transform
  697.     >p=fft(s)
  698. Then p(exp(I*2*pi*i/n))=s[i+1], 0<=i<n-1. For maximal speed, n should
  699. be a power of 2. The reverse evaluates a polynomial at the roots of
  700. unity simultanuously
  701.     >s=ifft(p)
  702.  
  703.  
  704. GRAPHICS
  705. --------
  706.  
  707. The best part of EULER is its graphic capability. There are two
  708. screens, the text screen and the graphic screen. Text output
  709. automatically displays the text screen, and graphic output displays
  710. the graphic screen. One may also switch to the graphic screen by
  711. pressing TAB on input or with the command
  712.     >shg;
  713.  
  714. There are two coordinate systems. The screen coordinates are a
  715. 1024x1024 grid with (0,0) in the upper left corner. Furthermore, each
  716. plot generates plot coordinates mapping a rectangle of the plane on
  717. the screen with the smallest x value left and the smallest y value at
  718. the bottom. To be precise, the rectangle is mapped to the screen
  719. window, which may only cover a part of the display area. See below for
  720. more information on windows.
  721.  
  722. If x and y are 1xN vectors, the function
  723.     >plot(x,y)
  724. connects the points (x[i],y[i]) with straight lines and plots these
  725. lines. It first clears the screen and draws a frame around the screen
  726. window. The plot coordinates are chosen such that the plot fits
  727. exactly into the screen window. This behaviour is called autoscaling.
  728. You can set your own plot coordinates with
  729.     >setplot(xmin,xmax,ymin,ymax)
  730. (or setplot([...])). The autoscaling is then turned off. To turn it on
  731. again,
  732.     >setplot()
  733. or
  734.     >scaling(1)
  735. is used.
  736.     >s=scaling(0)
  737. does also turn off autoscaling and returns the old state of the scaling
  738. flag to s. By the way, the plot command returns the plot coordinates;
  739. i.e., a vector [xmin,xmax,ymin,ymax].
  740.  
  741. The screen window is a rectangle on the screen which can be set by
  742.     >window(cmin,cmax,rmin,rmax)
  743. (or window([...])) in screen coordinates.
  744.  
  745. If x is a 1xN vector and A MxN matrix,
  746.     >plot(x,A)
  747. plots several functions. The same is true with
  748.     >plot(B,A)
  749. if B is a MxN matrix. In this case, the plot is done for corresponding
  750. rows of A and B.
  751.  
  752. The graphic screen is cleared by the plot command. This can be turned
  753. off with
  754.     >hold on;
  755. or
  756.     >holding(1);
  757. To turn holding off,
  758.     >hold off;
  759. or
  760.     >holding(0);
  761. is used. The function holding returns the old state of the holding
  762. flag. This is a way to draw several plots into the same frame.
  763. Combining window and holding is a way to draw several plots in several
  764. windows on the screen.
  765.  
  766.     >xplot(x,y)
  767. works like plot but does also show axis grids. Actually, xplot has
  768. default parameters grid=1 and ticks=1, which determine, if a grid is
  769. plotted and axis laballing is done. Thus
  770.     >xplot(x,y,1,0)
  771. does no ticks. Also
  772.     >xplot(x,y,ticks=0)
  773. may be used for the same purpose (see below in the section about EULER
  774. programming for details on default parameters).
  775.     >xplot()
  776. plots the axis and ticks only.
  777.  
  778. You should use
  779.     >shrinkwindow()
  780. if you intend to use labels (ticks) on the axis. This leaves some
  781. space around the plot.
  782.     >fullwindow()
  783. resizes the plots to the full size. You may also set the x axis grids
  784. on your own with
  785.     >xgrid([x1,x2,x3,...])
  786. or
  787.     >xgrid([x1,x2,x3,...],f)
  788. the latter producing digits at the edge of the plot (ygrid(...) works
  789. respectively). Actually, these functions are defined in UTIL.
  790.  
  791.     >plotarea(x,y)
  792. sets the plot area for the next plot like plot(x,y), but it does not
  793. actually plot.
  794.  
  795.     >title("text")
  796. draws a title above the plot. It is a function in UTIL using
  797.     >ctext("text",[col,row])
  798. which plots the text centered at screen coordinates (col,row).
  799.     >text("text",[col,row])
  800. plots the text left justified. The width and height of the charcters can
  801. be asked with
  802.     >textsize()
  803. returning the vector [width,height] in screen coordinates.
  804.  
  805. If a color monitor is used, EULER can produce colored plots. The plot
  806. color can be modified with
  807.     >color(n)
  808. where n=1 is black, and n=0 is white. Other colors depend on your
  809. system settings. The textcolor and framecolor can be set the same way.
  810.  
  811. There is the possibility to use dotted and dashed lines, or even
  812. invisible lines erasing the background. This is done with the style
  813. one of the commands
  814.     >style(".")
  815.     >linestyle(".")
  816. ("-","--","i"). The function linestyle, also
  817.     >linestyle("")
  818. returns the previous line style. The lines can have a width greater than
  819. 0. This is set with
  820.     >linewidth(n)
  821. The function returns the previous setting.
  822.  
  823. The command
  824.     >mark(x,y)
  825. works like plot. But it does not connect the points but plots single
  826. markers at (x[i],y[i]). The style of the marker can be set with one
  827. of the commands
  828.     >style("mx")
  829.     >markerstyle("mx")
  830. for a cross. Other styles are "m<>" for diamonds, "m." for dots, "m+"
  831. for plus signs, "m[]" for rectangles and "m*" for stars. The function
  832. returns the previous marker style.
  833.     >style("")
  834. resets the plot and marker styles. There is also the command
  835.     >xmark(x,y)
  836.  
  837. The easiest way to produce 3D-plots is
  838.     >mesh(Z)
  839. If Z is a NxM matrix, its elements are interpreted as z-values of a
  840. function defined on a grid of points (i,j). The plot is a three
  841. dimensional plot with hidden lines of the points (i,j,Z[i,j]). It is
  842. autoscaled to fit onto the screen window. The point (1,1,z[1,1]) is
  843. the left foremost point. To improve the look of the plot, one uses
  844.     >triangles(1)
  845. However, this way is considerably slower. Of course,
  846.     >triangles(0)
  847. turns this feature off again. One can also turn off the different fill
  848. styles mesh uses for the two sides of the plot with
  849.     >twosides(0)
  850. This function works also for solid plots described below. It is a faster
  851. way than the use of triangles to avoid the errors, that the mesh plot
  852. frequently makes. By the way, both functions return the old values of
  853. the flags.
  854.  
  855. There is a function which produces matrices X and Y such that X[i,j]
  856. and Y[i,j] are the coordinates in the plane of a point in a
  857. rectangular grid parametrized by (i,j). This function is
  858.     >{X,Y}=field(x,y)
  859. where x and y are row vectors. Then X[i,j] is equal to x[i] and Y[i,j]
  860. is equal to y[j]. So you can easily generate a matrix of function
  861. values; e.g.,
  862.     >Z=X*X+Y*Y
  863. Note that this is not the most economical way. The above Z would be
  864. generated by
  865.     >Z=dup(x*x,cols(y))+dup(y*y,cols(x))'
  866. much more rapidly.
  867.  
  868. A nicer way to plot a surface is
  869.     >solid(x,y,z)
  870. or
  871.     >framedsolid(x,y,z)
  872. where x, y and z are NxM matrices. The surface parameters are then
  873. (i,j) and (x[i,j],y[i,j],z[i,j]) are points on the surface. The
  874. surface should not self intersect; or else plot errors will occur. The
  875. surface is projected onto the screen in central projection, with the
  876. view centered to (0,0,0). You can set the viewing distance, a zooming
  877. parameter, the angles of the eye from the negative y- to the positive
  878. x-axis, and the height of the eye on the x-y-plane, by
  879.     >view(distance,tele,angle,height)
  880. (or view([...])). view returns the previous values and view() merely
  881. returns the old values. framedsolid has a default parameter scale,
  882. which scales the image to fit into a cube with side length 2*scale,
  883. centered at 0, unless scale=0, which is the default value (no
  884. scaling). Thus
  885.     >framedsolid(x,y,z,2)
  886. will scale the plot so that |x|,|y|,|z|<=2.
  887.     >wire(x,y,z)
  888. and
  889.     >framedwire(x,y,z)
  890. work the same way, but the plotting is not solid. If x, y and z are
  891. vectors, then a path in three dimensions is drawn. The color of the
  892. wires is set by
  893.     >wirecolor(c)
  894. If you add an extra value to framedwire or framedsolid like in
  895.     >framedwire(x,y,z,scale)
  896. the plot is scaled to fit into a cube of side length 2scale. The
  897. function
  898.     >{x1,y1}=project(x,y,z)
  899. projects the coordinates x,y,z to the screen and is useful for 3D
  900. path plots. There is a function
  901.     >scalematrix(A)
  902. which scale the matrix A linearly so that its entries are between
  903. 0 and 1.
  904.     >solid(x,y,z,i)
  905. is a special form of solid. If i=[i1,...,in], then the ij-th row
  906. of (x,y,z) is not connected to the ij+1-st row. I.e., the plot
  907. consists of n+1 parts.
  908.  
  909. A contour plot of a matrix is produced by
  910.     >contour(A,[v1,...,vn])
  911. The contour lines are then at the heights v1 to vn. The interpretation
  912. of A is the same as in mesh(A).
  913.  
  914. A density plot is a plot of a matrix, that uses shades to make the
  915. values visible. It is produced with
  916.     >density(A)
  917. The integer part of the values is cut off. So the shades run through
  918. the available shades, if A runs from 0 to 1. A can be scaled to 0 to
  919. f with
  920.     >density(A,f)
  921. f=1 is the most important value. The shades can be controlled with
  922.     >huecolor(color)
  923. if color=0, then the function uses the available colors for shading.
  924. One should set these colors to give a nice color scale from dark to
  925. light. This option is not available on B/W screens. Any positive color
  926. produces shades in that color using dithering. Any negative color
  927. cycles through colors 4 to 16 plus dithering.
  928.     >solidhue(x,y,z,h)
  929. makes a solid view with shades. h are the shading values as in density.
  930.     >framedsolidhue(x,y,z,h,scale,f)
  931. works like a mixture of framedsolid and solidhue. scale=0 and f=1 are
  932. the default values.
  933.  
  934. The plotting of a user defined function f(x,...) can be done with
  935.     >fplot("f",a,b)
  936.     >fplot("f",a,b,n)
  937.     >fplot("f",a,b,,...)
  938. The extra parameters ... are passed to f. n is the number of
  939. subintervals. Note the extra ',', if n is omitted. If a and b
  940. are omitted, as in
  941.     >fplot("f",,,,...)
  942. or
  943.     >fplot("f")
  944. then the plot coordinates of the last plot are used. You can zoom
  945. in with the mouse by
  946.     >setplotm(); fplot("f");
  947. This lets you select a square region of the screen. In any case,
  948. setplotm() sets the plot coordinates to the user selected square.
  949.  
  950. It is possible to sample coordinates from the graphics screen with
  951. the mouse.
  952.     >mouse()
  953. displays the graphics screen and a mouse pointer and waits for a mouse
  954. click. It returns a vector [x,y] which are the plot coordinates of the
  955. clicked spot. Using
  956.     >{x,y}=select()
  957. returns several x coordinates and y coordinates at the points, which
  958. the user selected by the mouse. The selection stops, if the user clicks
  959. above the plot window.
  960.  
  961.  
  962. DIRECTORIES
  963. -----------
  964.  
  965. The active directory can be changed with
  966.     >cd("path")
  967. where path is the new directory and may include a drive letter, like
  968.     >cd("a:\progs")
  969. The command
  970.     >dir("*.e")
  971. displays all files in the active directory, which fit with the pattern.
  972. This is not available on UNIX machines.
  973.  
  974.  
  975. THE META FILE
  976. -------------
  977.  
  978. For special purposes, you can keep a record of your graphic output
  979. on an external file called meta file. You turn on recording with
  980.     >meta "filename";
  981. and turn it off again with
  982.     >meta;
  983.  
  984. The content of the meta file looks like this. All commands start with
  985. a command number (a byte) and the number of arguments (a byte). Then
  986. several arguments follow (int or long or a string). The screen
  987. coordinates are multiplied by 1000 and are stored long, as is hue
  988. and scale. Note that int may be 16-bit or 32-bit depending on
  989. your machine.
  990.  
  991. - 1 c0 r0 c1 r1 color style width
  992.   Draws a line from (c0,r0 to (r1,c1). The style is none=0, solid=1,
  993.   dotted=2, dashed=3.
  994.  
  995. - 2 c r color type
  996.   A marker at (c,r). dot=0, plus=1, start=2, square=3, cross=4,
  997.   diamond=5.
  998.  
  999. - 3 n c1 r1 f1 c2 r2 f2 c3 r3 f3 ... cn rn style
  1000.   A filled rectangle with the specified corners. fill style is solid=0,
  1001.   dotted=1. The corners are (ci,ri) and fi is a flag which determines
  1002.   if the point is to be connected to the next one on the boundary. n
  1003.   is the number of points.
  1004.  
  1005. - 4 c r color centered Text+0(+0)
  1006.   A text at (c,r). The extra 0 makes the text have an even length.
  1007.  
  1008. - 5 scale
  1009.   scales the plot window to 1 : (scale/1024). A 0 means rescaling
  1010.   to full screen.
  1011.  
  1012. - 6
  1013.   clears the screen.
  1014.  
  1015. - 7 c1 r1 c2 r2 hue color
  1016.   Draws a rectangle with upper left corner (c1,r1) and lower right
  1017.   corner (c2,r2). hue is a value from 0 to 1 multiplied by 1000.
  1018.   color is as in the function huecolor().
  1019.  
  1020. - 8 c1 r1 c2 r2 c3 r3 c4 r4 hue color
  1021.   Draws a filled polygon with corner (ci,ri).
  1022.  
  1023. The author has no use for the meta file right now. But clearly someone
  1024. might write a program for printer output, film sequences etc. using
  1025. the meta file. Sorry, but I was unable to use POSTSCRIPT commands. It
  1026. should be trival to translate the above commands however.
  1027.  
  1028.  
  1029. PROGRAMMING EULER
  1030. ----------------
  1031.  
  1032. EULER would not be as powerful as it is, if there wasn't the
  1033. possibility to extend it with user defined functions. A function can
  1034. be entered from the keyboard or better from a load file. Since there
  1035. may be errors in a function, it is best to call an editor, edit the
  1036. function in a file and then load that file.
  1037.  
  1038. Loading a file is done with
  1039.     >load "filename"
  1040. as explained above.
  1041.  
  1042.  
  1043. FUNCTIONS
  1044. ---------
  1045.  
  1046. A function is declared by the following commands
  1047.     >function name (parameter,...,parameter)
  1048.     >...
  1049.     >endfunction
  1050. It can have several parameters or none. If the function is entered
  1051. from the keyboard, the prompt changes to "udf>". "endfunction"
  1052. finishes the function definition. An example:
  1053.     >function cosh (x)
  1054. udf>  return (exp(x)+exp(-x))/2
  1055. udf>endfunction
  1056.  
  1057. Every function must have a return statement, which ends the execution
  1058. of the function and defines the value it returns. A function can be
  1059. used in any expression, just as the builtin functions. If a function
  1060. is not used in an assignment and with surpressed output (followed by
  1061. ";"), it is used like a procedure and its result is evidently lost.
  1062. However, the function may have had some side effect.
  1063.  
  1064. Inside a function one cannot access global variables or variables of
  1065. the function which called the function. To use global variables use
  1066. the command
  1067.     >global variablename
  1068. in the function body. Of course, one can use other functions in
  1069. expressions inside a function, one can even use the function inside
  1070. itself recursively. All variables defined inside a function are local
  1071. to that function and undefined after the return from the function.
  1072. There is no way to define global variables or change the type or size
  1073. of global variables from within a function, even if one defines these
  1074. variables in a "global" statement.
  1075.  
  1076. All parameters are passed as references. That means that a change
  1077. of a parameter results in the change of the variable, which was
  1078. passed as the parameter. For example
  1079.     >function test(x)
  1080.     >  x=3;
  1081.     >  return x
  1082.     >endfunction
  1083.     >a=5;
  1084.     >test(a);
  1085.     >a
  1086. gives the value 3. There is an exeption to this. A submatrix is not
  1087. passed by value. Thus
  1088.     >a=[1,2,3];
  1089.     >test(a(1));
  1090.     >a(1)
  1091. gives the value 1. 
  1092.  
  1093. A function can have a variable number of parameters. The number of
  1094. parameters passed to a function can be determined with the builtin
  1095. function "argn()". If the parameters are not named in the function
  1096. definition, they are given the names arg1, arg2 and so on.
  1097.  
  1098. Parameters can have default values. The syntax ist parameter=value in
  1099. the parameter definition; e.g.,
  1100.     >function f(x=3,y,z=1:10)
  1101. assigns the default value 3 to x and the vector 1 to 10 to z, if the
  1102. function is called in the form
  1103.     >f(,4,)
  1104. If the function is called
  1105.     >f(1,4)
  1106. x has the value 1, y the value 4, and z the value 1:10.
  1107.  
  1108. The function can even be given a named parameter. Consider the
  1109. function
  1110.     >function f(x,y,z=4,w=4,t=5)
  1111. Then
  1112.     >f(1,2,t=7)
  1113. calls the function, as if
  1114.     >f(1,2,4,4,7)
  1115. was entered. Actually the name needs not be a parameter name. Thus
  1116.     >f(1,2,s=7)
  1117. defines a local variable s with value 7.
  1118.  
  1119. A function can return multiple values. This is done with the return
  1120. statement
  1121.     >  return {x,y,...}
  1122. You can assign all the return values of a function to variables, using
  1123.     >{a,b,...}=function(...);
  1124. If the result of such a function is assigned to a number of variables
  1125. smaller than the number of returned values, only the first values are
  1126. used. If is is assigned to a larger number of variables, the last value
  1127. is used more than once. Some builtin functions return multiple values.
  1128.  
  1129. Comments can be included, starting with ##. Comments are not entered
  1130. in the function definition and do not appear, when you type the
  1131. function with
  1132.     >type functionname
  1133. If the lines immediately after the function header start with ##,
  1134. then those lines are considered to be help text. They can be displayed
  1135. with
  1136.     >help functionname
  1137. This is a good way to remember the parameters of the function. Also
  1138.     >list
  1139. can be used to display the names of the user defined functions.
  1140.  
  1141. A function or several functions can be removed with
  1142.     >forget name,...
  1143. By the way, a variable can be removed with
  1144.     >clear name,...
  1145.  
  1146.  
  1147. EULER PROGRAMMING LANGUAGE
  1148. -------------------------
  1149.  
  1150. Like in any other programming language, in EULER there are commands
  1151. for changing the flow of evaluation. These commands can only be used
  1152. inside user defined functions.
  1153.  
  1154. First there is the "if" command.
  1155.     >if expression; ...; else; ....; endif;
  1156. The expression is any EULER numerical expression. If it is a matrix,
  1157. and all its entries are different from zero, then the part from the
  1158. ";" to the "else;" is evaluated. Else the part from "else;" to "endif"
  1159. is evaluated. Of course "..." may spread over several lines. To work
  1160. correctly, keywords like "if", "else", "endif" and others should be
  1161. the first nonblank characters in a line, or should be preceded by "," or
  1162. ";" (plus blanks or TABs). The "else" may be omitted. In this case the
  1163. evaluation skips behind the "endif", if the matrix contains nonzero
  1164. elements (resp. the number is nonzero).
  1165.  
  1166. There is the function "any(A)", which yields 1, if there is any
  1167. nonzero element in A, 0 otherwise. The function is useful in
  1168. connection with the if statement.
  1169.  
  1170. Next, there are several loops.
  1171.     >repeat; ...; end;
  1172.     >loop a to b; ...; end;
  1173.     >for i=a to b step c; ...; end;
  1174. All loops can be aborted by the break command (usually inside an
  1175. "if"), especially the seemingly infinite "repeat". "loop" loops are
  1176. fast long integer loops. The looping index can be accessed with the
  1177. function "index()" or with "#". In a "for" loop the looping index is
  1178. the variable left of the "=". The step size can be omitted. Then it is
  1179. assumed to be 1. As an example, the following loops count from 1 to
  1180. 10:
  1181.     >  i=1;
  1182.     >  repeat;
  1183.     >    i, i=i+1;
  1184.     >    if i>10; break; endif;
  1185.     >  end;
  1186. and
  1187.     >  loop 1 to 10; #, end;
  1188. and
  1189.     >  for i=1 to 10; i, end;
  1190.  
  1191.  
  1192. DEBUGGING EULER PROGRAMS
  1193. ------------------------
  1194.  
  1195. The command
  1196.     >trace on
  1197. sets tracing of all functions on. Then any new line in a user defined
  1198. function will be printed with the function name before it is executed.
  1199. The uses has to press a key, before execution continues:
  1200.  
  1201.     F1    debugs every function.
  1202.     F2    debugs no function called in the current line.
  1203.     F3    will stop debugging until return of the current function.
  1204.     F4    will prompt for an expression and evaluate it.
  1205.     F9    aborts execution of the program.
  1206.     F10    ends tracing for this command.
  1207.  
  1208. Any other key will display the available keys.
  1209.     >trace off
  1210. switches tracing off.
  1211.  
  1212. Note, that with F4 you can evaluate any expression, even if it contains
  1213. local variables or subroutine calls. Tracing is switched off during
  1214. evaluation of the expression.
  1215.  
  1216. A single function can be traced with
  1217.     >trace function
  1218. or
  1219.     >trace "function"
  1220. Execution will stop only in this function. The same command switches
  1221. the trace bit of this function off.
  1222.     >trace alloff
  1223. switches tracing for all functions off.
  1224.  
  1225.  
  1226. PROGRAMMING STYLE
  1227. -----------------
  1228.  
  1229. All internal EULER functions can handle vector or matrix input. And so
  1230. should user defined functions. To achieve this, sometimes nothing
  1231. special needs to be done. E.g., the function
  1232.     >function kap (r,i,n)
  1233.     >  p=1+i/100;
  1234.     >  return p*r*(p^n-1)/(p-1)
  1235.     >endfunction
  1236. is automatically capable to handle matrix intput. Thus
  1237.     >kap(1000,5:0.1:10,10)
  1238. will produce a vector of values. However, if the function uses a more
  1239. complicated algorithm, one needs to take extra care. E.g.,
  1240.     >function lambda (a,b)
  1241.     >  si=size(a,b); l=zeros(si);
  1242.     >  loop 1 to prod(si);
  1243.     >    l{#}=max(abs(polysolve([1,a{#},b{#},1])));
  1244.     >  end;
  1245.     >  return l
  1246.     >endfunction
  1247. shows the fastest way to achieve the aim. "si" will contain the size,
  1248. of the matrix "a" or "b", and will yield an error message, if the
  1249. sizes are different. However, if "a" is a real and "b" a matrix, "si"
  1250. will contain the size of "b" and the program will still run properly.
  1251. The loop will then be over all the elements of "a" or "b". the "{#}"
  1252. indexing works correctly, if the vector is smaller than the index. It
  1253. then yields the last element of a vector, which is OK in the case of a
  1254. real or complex values. See also the function "map" in UTIL explained
  1255. below.
  1256.  
  1257. Forthermore, as a matter of good style, one should use the help lines
  1258. extensively. One should explain all parameters of the function and its
  1259. result. This is a good way to remember what the function really does.
  1260.  
  1261.  
  1262. PASSING FUNCTIONS AS PARAMETERS
  1263. -------------------------------
  1264.  
  1265. It is possible to pass functions to a function. E.g., the function
  1266. "bisect" in UTIL finds the zero of a function using bisection. One
  1267. uses this function in the following way:
  1268.     >function f(x)
  1269.     >  return x*x-2
  1270.     >endfunction
  1271.     >bisect("f",1,2)
  1272. The result will be sqrt(2). If "f" needs extra paramters, those can
  1273. also be passed to "bisect":
  1274.     >funtion f(x,a)
  1275.     >  return x*x-a
  1276.     >endfunction
  1277.     >bisect("f",0,a,a)
  1278. will result in sqrt(a) (for a>=0). The search interval is set to [0,a].
  1279.  
  1280. The way to write a function like "bisect" is to use the "args" function.
  1281.     >function bisect (function,a,b)
  1282.     >...
  1283.     >  y=function(x,args(4));
  1284.     >...
  1285.     >endfunction
  1286. Then "function" will be called with the parameter "x" and all paramters
  1287. from the 4-th on (if any) which have been passed to "bisect". Of course,
  1288. "function" should be assigned a string, containing the name of the
  1289. function which we want the zero of.
  1290.  
  1291.  
  1292. USER INTERFACE
  1293. --------------
  1294.  
  1295. Clearly, EULER is designed to run interactively. The user loads a file
  1296. containing the functions he needs. The file may inform the user of its
  1297. content by simply printing some messages with commands like
  1298.     >"The content of this file is:",
  1299.     >...
  1300. Then the user can use the help facility to retrieve further information
  1301. on the functions, its parameters and so on. He (or she) then calls the
  1302. particular function with the parameters he desires.
  1303.  
  1304. However, it is also possible to run a file as a standalone program.
  1305. If you start EULER from a shell simply put the file into the command
  1306. line. On the ATARI computer, you may also make EULER an application.
  1307. Then all EULER files should have the same extension and clicking on
  1308. such a file will start EULER and load the file. See the ATARI
  1309. documentation for further information.
  1310.  
  1311. If you wish a standalone application, the user will have to enter data.
  1312. You can prompt him with
  1313.     >data=input("prompt");
  1314. The prompt
  1315.    prompt? >
  1316. will appear and the user may enter any valid EULER expression, even if
  1317. it uses variables. Errors are catched and force the user to reenter
  1318. the input. If you wish the user to enter a string, use
  1319.     >string=lineinput("prompt");
  1320. The string may then be evaluated with
  1321.     >data=interpret(string);
  1322. and if it does not consist of a valid EULER expression the result is the
  1323. string "error".
  1324.  
  1325. Output is printed to screen. All expressions and assignments produce
  1326. output unless followed by ";". If formated output is wanted, use
  1327.     >printf("formatstring",realdata)
  1328. The format string obeys the C syntax; e.g., "%15.10f" prints the data
  1329. on 15 places with 10 digits after decimal dot, and "%20.10e" produces
  1330. the exponential format. You can concatenate strings with | to longer
  1331. output in a single line.
  1332.  
  1333. Output is surpressed globally with
  1334.     >output off;
  1335. and
  1336.     >output on;
  1337. turns the output on again. This is useful if a dump file is defined by
  1338.     >dump "filename";
  1339. Then all output is echoed into the dump file. The command
  1340.     >dump;
  1341. turns the dump off. Note that the dump is always appended to the file.
  1342. Furthermore, that file may not be edited while dump is on! In UTIL the
  1343. function
  1344.     >write(x,"x")
  1345. is defined, which writes x in a format readable by EULER on input.
  1346. If you omit the name "x", the name of x is used automatically. This
  1347. is done with the help of the function
  1348.     >name(x)
  1349. which gives a string containing the name of x.
  1350.  
  1351.     >cls;
  1352. clears the screen.
  1353.     >clg;
  1354. clears the graphics. Also to show graphics to the user, use
  1355.     >shg;
  1356. Subsequent output will switch back to the text screen.
  1357.  
  1358. Finally, an error can be issued with the function
  1359.     >error("error text")
  1360.  
  1361.  
  1362. UTILITIES
  1363. ---------
  1364.  
  1365. In UTIL some fuctions are defined, which will to be of general use.
  1366. First there are some functions for solving equations.
  1367.     >bisect("f",a,b,...)
  1368. uses the bisetion method to solve f(x,...)=0. f must be a function
  1369. of the real variable x which may have additional parameters "...".
  1370. These parameters can be passed to bisect and are in turn passed to f.
  1371.     >secant("f",a,b,...)
  1372. uses the secant method for the same purpose.
  1373.  
  1374.     >broyden("f",x)
  1375. or
  1376.     >broyden("f",x,J,...)
  1377. uses the Broyden method to find the roots of f(x,...)=0. This time, f
  1378. may be a function f : R^n -> R^n. Then x is a vector. J is an
  1379. approximation of the Jacobian at x, the starting point. If J==0 or J
  1380. is missing, then the function computes J. Again, additional parameters
  1381. are passed to f.
  1382.  
  1383.     >simpson("f",a,b)
  1384. or
  1385.     >simpson("f",a,b,n,...)
  1386. computes the Simpson integral with of f in [a,b]. n is the discretization
  1387. and additional parameters are passed to f(x,...). f must be able to
  1388. handle vector input for x.
  1389.  
  1390.     >gauss("f",a,b)
  1391. or
  1392.     >gauss("f",a,b,n,...)
  1393. performs gauss integration with 10 knots. If n is specified, then
  1394. the interval is subdivided into n subintervals. f(x,...) must be able
  1395. to handle vector intput for x.
  1396.  
  1397.     >romberg("f",a,b)
  1398. or
  1399.     >romberg("f",a,b,n,...)
  1400. uses the Romberg method for integration. n is the starting discretization.
  1401. All other parameters are as in "simpson". The iteration goes on until
  1402. the accuracy rombergeps is reached, which is epsilon() initially.
  1403.  
  1404. There are some approximation tools. Polynomial interpolation has been
  1405. discussed above. There is also spline interpolation
  1406.     >sp=spline(t,s)
  1407. which returns the second derivatives of the natural cubic spline through
  1408. (t[i],s[i]). To evaluate this spline at x,
  1409.     >splineval(t,s,sp,x)
  1410. is available.
  1411.  
  1412.     >polyfit(t,s,n)
  1413. fits a polynomial of n-th degree to (t[i],s[i]) in least square mode.
  1414. This is an application of
  1415.     >fit(A,b)
  1416. which computes x such that the L_2-norm of Ax-b is minimal.
  1417.  
  1418.     >iterate("f",x)
  1419. or
  1420.     >iterate("f",x,n,...)
  1421. iterates f starting at x n times and returns the vector of iterated
  1422. values. If n is missing or 0, then the iteration stops at a fixed
  1423. point and only this fixed point is returned.
  1424.  
  1425.     >map("f",x,...)
  1426. evaluates the function f(x,...) at all elements of x, if f(x,...)
  1427. does not work because the function f does not accept vectors x.
  1428.  
  1429.  
  1430. HINTS
  1431. -----
  1432.  
  1433. One can make all sorts of mistakes in EULER. This section tries to
  1434. warn you of the more common ones, most os which the author has some
  1435. experience with.
  1436.  
  1437. As already mentioned, you should not assign to the parameter of a
  1438. function. This will generally produce strange errors, which are
  1439. difficult to debug. If you need default values for parameters, use a
  1440. construction like
  1441.     >function f(a,x)
  1442.     >  if argn()==2; xx=x; else xx=4; endif
  1443.     >  ...
  1444. which gives xx the value of the second parameter, with default 4.
  1445.  
  1446. The next mistake is to produce matrices with 0 rows or columns. EULER
  1447. can not do any computation with these matrices. Make sure that every
  1448. index you use is in range. And use special handling, if there is
  1449. nothing to do.
  1450.  
  1451. Another subtlety concerns the use of multiple return values. The
  1452. following simply does not work:
  1453.     >x=random(1,10); sin(sort(x))
  1454. The reason is that sort returns not only the sorted array but also the
  1455. indices of the sorted elements. This works as if sin was passed two
  1456. parameters and EULER will not recognize that use of sin. To work
  1457. around this either assign the sorted array to a variable or put extra
  1458. brackets around it:
  1459.     >x=random(1,10); sin((sort(x)))
  1460. Also a return statement like
  1461.     >return {sort(x),y}
  1462. really returns 3 (or more) values! Use
  1463.     >return {(sort(x)),y}
  1464.  
  1465. One further misfortune results from the use of strings as functions,
  1466. like in
  1467.     >function test(f,x)
  1468.     >    return f(x*x)
  1469.     >endfunction
  1470.     >test("sin",4)
  1471. This works well as long as there is no function by the name of "f". If
  1472. there is, this function is called rather than the sine function. The
  1473. only way to avoid this is to use really strange names for function
  1474. parameters. I prefer "test(ffunction,x)" and used it throughout UTIL.
  1475.  
  1476.  
  1477. VERSION CHANGES
  1478. ---------------
  1479.  
  1480. Here is a list of recent changes to EULER. The new version should be
  1481. downward compatible in most cases. Minor error corrections are not
  1482. listed here.
  1483.  
  1484. - Named parameters and default values for paramters have been
  1485. introduced. Many functions in UTIL.E have been redesigned using the
  1486. new features.
  1487.  
  1488. - Graphic primitives have been changed. Lines can have a width now.
  1489. The density, huecolor and solidhue functions have been introduced.
  1490. This changed the content of the meta file, which has also been
  1491. simplified.
  1492.  
  1493. - New functions in UTIL.E: scalematrix, select, framedsolidhue,
  1494. setplotm.
  1495.  
  1496. - The key function is defined. It waits for a key stroke.
  1497.  
  1498. - The help/insert key extends incomplete commands.
  1499.  
  1500.  
  1501. FINAL WORDS
  1502. -----------
  1503.  
  1504. The author is interested in applications of EULER and will collect
  1505. them. These applications will then be included in program updates
  1506. (maybe in packed form). Some interesting applications are in the
  1507. folder PROGS. The file EXAMPLES.DOC contains sample sessions with
  1508. EULER and shows how to solve problems with this programming system.
  1509.  
  1510. The author wishes anyone success in using EULER.
  1511.  
  1512.  
  1513. Dr. R. Grothmann
  1514. Grafenwerderstr. 14
  1515. W-8059 Wörth
  1516. Germany
  1517.  
  1518. EMail: mga010@ku-eichstaett.de
  1519. ə