This file contains main topics for the help window in Euler Math Toolbox (EMT). The list of topics opens when the help window is opened for the first time or if the search string is empty.

If you are reading this file in the browser you see an export to HTML. Use the links to find a specific topic.

- Topics (overview)
- Help (overview)
- Keyboard (overview)
- Installation (overview)
- Notebooks (overview)
- Menu (overview)
- Graphics (overview)
- Variables (overview)
- Variables in Functions (overview)
- Symbolic Variables (overview)
- Units (overview)
- Matrices (overview)
- Matrix Language (overview)
- Calculus (overview)
- Derivatives (overview)
- Integrals (overview)
- Differential Equations (overview)
- Plots (overview)
- Plots in 2D (overview)
- Logarithmic Plots (overview)
- Styles of 2D Plots (overview)
- Implicit Plots (overview)
- Plots in 3D (overview)
- Plot Aspect (overview)
- Statistical Plots (overview)
- Basic Plots (overview)
- Statistics (overview)
- Solve Equations (overview)
- Algebra (overview)
- Optimization (overview)
- Regression (overview)
- Data Types (overview)
- Linear Algebra (overview)
- Matrix Language (overview)
- Expressions (overview)
- Interval Arithmetic (overview)
- Polynomials and Splines (overview)
- Formats (overview)
- Programming Language (overview)
- Symbolic Functions (overview)
- Maxima at Compile Time (overview)
- Comments (overview)
- Scripts (overview)

Double click on any of the topics below. In the help window, you can double click on any item in the text output. Double click the breadcrumbs in the first line to go back to a previous topic.

Help - Help for the Help Window

Keyboard - Keys for the Command line
Comments - Syntax for Comment Sections in Notebooks

Installation - Installation of EMT and additional Modules Notebooks - Commands and Comments in Notebooks Menu - The Menu of of the Notebook Window of EMT Graphics - Save and Export Graphics of EMT

Variables - Variables and Data Types in Euler

Data Types - Syntax for Data Types in EMT

Formats - Formatting the Output nNmbers in Euler

Calculus - Derivatives, Integrals, Differential Equations

Solve Equations - Solve Equations and Systems of Equations

Plots - Plots in 2D and 3D

Algebra - Symbolic Manipulation of Expressions

Linear Algebra - Vectors and Matrices in Linear Algebra

Statistics - Statistics in EMT

Optimization - Linear and non-linear Optimization

Regression - Linear Regression

Polynomials and Splines - Polynomials and Splines in EMT

Programming Language - Functions in EMT

Scripts - External *.e files for EMT

You can open the help window at any time with F1. By default, EMT will display the topic explaining the most recent command. Press escape to clear the input line. While you type, the window will display all available topics. To select the first topic, press return. To select any other topic, double click on it.

The following wildcard characters and commands are supported in the search line.

- text topic starting with the text

- *text topics containing "text"

- ?text full text search for the text in help topics

- &topic (or " topic") topics in the Maxima help

- &*text commands containing "text" in the Maxima help

- _function built-in functions

- function( (or "function ") specific function

- filename.e lists the content of this EMT file

- list ... lists all functions containing the string

- listvar ... lists all variables containing the string

- type ... types the definition of a function

The following key strokes are useful in the help window.

- return key select the first topic

- escape key clears selection or closes dialog

- F1 key switches back to the EMT window

- F2 key opens the current selection in the browser

Double click on any topic in the output of the help window to open that topic.

EMT tries to use the keys in the same way as other programs. But there are some special keys.

- escape: stop current computation, escape from function edit

- TAB: toggle showing the graphics

- ctrl+g: toggle extra graphics window

- up, down: go to previous or next command line

- left, right: go to previous or next character

- ctrl+left, ctrl+right: go to previous or next space

- start, end: go to start or end of line

- page+up, page+down: go to previous or next page

- ctrl+page+up, ctrl+page+down: go to previous or next heading

- F1: toggles between the help window and the notebook

- F3: search next position of the current search (Ctrl-F)

- F5: opens the comment editor

- F7: degree symbol

- F8: plus/minus symbol

- F9: opens the internal editor

- F10: opens the external editor

- F11: full screen mode

- ctrl+F11: magnification mode

- F12: toggle spelling

- ctrl+F12: add errors in marked line to spelling

- return: run the command, or redefine the function

- alt+return: run the command and update the comment

- ctrl+return: splits the line, or go into function edit mode

- shift+ctrl+return: splits the line without adding "..."

- shift+return: run the current block of commands

- ctrl+backspace: join current line to previous line

- ctlr+r: run all subsequent commands

- alt+backspace: delete the command or function line

- alt+insert: insert a command or function line

- alt+u: insert all deleted lines

- alt+delete: forget the deleted lines permanently

- ctrl+delete: clear current command line

- ctrl-+z: go backward in the history of the current line

- ctrl+y: go forward in the history of the current line

- ctrl+c: copy marked Euler text or the marked image

- ctrl+v: insert Euler text

- ctrl+x: cut marked Euler text

- ctrl+alt+f: copy marked text in formatted form

- ctrl+alt+c: copy commands only

- ctrl+alt+v: paste text as commands

- ctrl+f: search a text (F3 searches next)

+ ctrl+n: restart euler
- ctrl+o: open a notebook

- ctrl+u: open in the Euler directory in the documents folder

- ctrl+s: save the notebook

- shift+ctrl+s: save as a new name, optionally delete old notebook

- ctrl+e: export notebook to HTML and save notebook

- ctrl+p: export notebook as PDF file

- ctrl+l: fold all multi-lines and function bodies

- ctrl+h: open help in the browser (alternative to F1 and button)

See:

function (Euler Core),

python (Euler Core)

The full version of EMT installs

- the interface

- the numerical kernel of EMT

- the programming language

- Euler files with utilities for EMT

- Tutorials and Examples as Notebooks and HTML

- the Maxima system

- the documentation in HTML

- documentation files for in-program help

- the Tiny C compiler

- the Python interface

- the LPSOLVE DLL

- the JE editor for Euler files (Java runtime required)

To get full advantage of EMT, you can install the following addons.

- a Latex system like MikTeX

- a Python 2.x interpreter like Anaconda

- the Povray raytracer

- any good code editor (replacement of JE)

If the binaries of Latex are not in your system path you can configure Latex in EMT. If you install Anaconda its Python interpreter will be found by EMT. It is accessed via the Python DLL in Windows. The Povray executable is stored in a string if it not in the system path. See the tutorial about Povray for details. The external editor can be configured inside EMT too.

The simple interface of EMT consists of the following windows.

- the notebook window with its menu and status line

- the optional graphics window (toggles with Ctrl-G)

- the help window (opens with F1)

- the comment editor (opens with F5 or right click into comments)

- the internal editor (opens with F9 or right click into functions)

- the external editor (opens with F10)

In the notebook window, command lines can be entered. Each command line consists of up to four elements.

- a comment in green (optional)

- the command line in red

- the output of EMT in black

- a graphics

The command line can be a multi-line, with "..." connecting the lines. In this case, all connected commands in the multi-line are executed at once no matter where the cursor is in the multi-line.

A special case are functions (not one-line functions). They consist of a header line in red, and a body in blue, which ends with a line containing "endfunction". More about this in the section about programming EMT.

To edit a comment, use the comment editor. Press F5 to open this editor. More on this in the section about Comments.

To include the current graphics into the notebook below the command, use a colon ":" at the end of the command line. An alternative is the command insimg().

See:

Keyboard (Overview),

Comments (Overview),

Menu (Overview)

The main menus in EMT are the following.

- File : Store and save notebooks and graphics

- Recent : A list of recently opened notebooks

- Edit : Editing (with keyboard shortcuts)

- Options : Settings for various things

- User Menu : User items and loaded Euler files

- Tasks : Links to sections in the help

- Help : Links to the documentation and to tutorial notebooks

Let us give some more tips about various menu items and settings.

Load and Save Notebooks

Notebooks are usually saved into "Euler Files" in the user directory. The file dialog remembers the last directory. The directory of the notebook will become the default directory and data files without a path are searched in this file. Note that images are stored into a sub-directory "images" by default. If notebooks are saved into another position EMT will ask to delete the old notebook and its files.

To open tutorials there is a menu entry in the "Help" menu. It is possible to open a second notebook in another copy of the program. This second notebook is marked as secondary and will not remember its settings.

About loading and saving graphics, see the section about Graphics in EMT.

Edit Notebooks

You will usually just enter or edit a command line and execute it with the return key. But it is possible to execute a complete section of command lines at once with shift-return, and all commands from the current one to the end with ctrl-return.

EMT has a command history. See the menu or the section about the Keyboard for more details. You can also use cut and paste as usual with Ctrl-X, Ctrl-C and Ctrl-V.

Command lines can be split into multi-lines (ctrl-return) or in two separate lines (shift-ctrl-return), and joined to one line (ctrl-back).

With F12 a simple spell checker is available in English or in German. To add a word to the checker mark the word and press Ctrl-F12. To search for a word use Ctrl-F and F3.

Options

This is more than we can explain here. Some general keys are included here.

- tab key : see the graphics

- Ctrl-G : toggle the graphics window

- Ctrl-F11 : toggle the display size

- F11 : toggle automatic window layout

The graphics is displayed in a square window by default. But the aspect can be set permanently here. Alternatively, it can be set for each graphics with the aspect() command.

EMT supports folding of mutli-lines and functions (ctrl-l). They are only fully visible if they have the focus. For a single line this can be achieved with %% or %+ at the start of the line.

User Menu

This will be filled if you load an Euler file containing the "menu" or "submenu" command.

See:

Graphics (Overview),

Keyboard (Overview)

Graphics are stored internally in a meta file format. Thus they can be resized when the graphics window changes its dimensions, and exported to various sizes. The aspect should be kept the same. By default, the graphics window displays a square containing the graphics.

Note that such an internal vector format helps only withing a small range of sizes. To design a graphics for various print sizes requires changing the fonts, the line widths and the complete layout of the graphics. See the tutorial about graphics in EMT for more information, especially the command setfont().

EMT can export graphics in the following ways.

- PNG with or without anti-aliasing

- Bitmap to the clipboard

- SVG (scalable vector format)

- Windows Metafile to the clipboard

The preferred way to save a graphics is PNG in a proper size for printing. For a 10cm print width you will need about 2000 pixels. But you can also copy and paste to Word or any other Windows program using the Windows Metafile.

Graphics can be inserted into the notebook with the ":" at the end of the command line. For more control over the graphics size, use insimg(). These files are saved along with the notebook as PNG, by default in a subdirectory "images". Optionally, a three times larger file is saved additionally without anti-aliasing. This is useful for print media like PDF which have their own good anti-aliasing.

It is possible to load graphics into EMT notebooks in comments (using image: ...) and below commands (loadimg() command). It is also possible to load graphics into matrices with RGB-values (loadrgb() command)

See:

Comments (Overview),

loadrgb (Euler Core),

insimg (Euler Core),

insimg (Plot Functions)

From the viewpoint of the user, Euler has the following data types.

- real numbers and real matrices,

- complex numbers and complex matrices,

- intervals and interval matrices,

- strings and string vectors,

- symbolic strings,

- compressed matrices,

- collections,

- binary data.

Numerical vectors are just matrices with one row or column. Column and row vectors make a difference. Collections are just immutable collections of other data. There are also expandable lists via glist().

To store a value into a numerical variable, use := or =.

>a := 3.5 >b = 5 // alternative >v = 1:5 // variable containing a vector

For symbolic variables, see

Symbolic Variables - Variables in Maxima

Names of variable can contain $ (should be reserved for units), hard spaces (enter with ctrl-space), or an underscore (enter as double underscore __) They can start with %. The special variable % refers to the previous result (only outside of functions).

Here are some typical examples of values in Euler.

>-1.234 // decimal dot, not comma! >1.45e22 // 1.45*10^22 >[1,2,-5,6] // 1x4 vector >[1,0;0,1] // identity matrix id(2)

>5+6i // complex number 5+6*I >[I,2*I,3+4*I] // complex vector

>Pi, E, I // constant functions

>"This is a string" >''Say "Hello!"'' // string containing "

>["Vector","of","strings"]

>~1.5,1.7~ // interval >1±0.1 // interval, use F8 for the plus/minus >~Pi~ // small interval around pi

For more Information see

Variables in Functions - about local and global Variables

Matrices - about matrices and sub-matrices

Symbolic Variables - Variables in Maxima

There are local and global variables. Inside a function, only local variables and parameters are visible. To access global variables, "useglobal" or "global var" must be present.

>function changeA () ... $ global A; $ A=random(4,4); $ endfunction >A=id(6); >changeA(); A,

To generate a global variable with a given value use "global var=value".

>function newvar (x) ... $global nv=x; $endfunction >newvar(4); nv, 4

Variables ending with $$ are automatically global variables.

>a$$ = 1:4 // assign to a global variable a$$ >v = a$$ // retrieve value of global variable a$$

Moreover, variables can be set as global.

>v=1:3; >setglobal v; >function changev () ... $ v[2]=5; $ endfunction >changev(); v,

Note that one-line functions set "useglobal" automatically. So all global variables can be used. But parameters have precedence.

>function f(x) := a*x >a=6; f(5) 30

Note that it is not a good style to use global variables to return values from functions. Instead, multiple returns should be used. Moreover, it is not a good style to access a global variable in a function (with the exception of units). Instead, pass the variable as an argument to the function. But for efficiency and simplicity, it is often nicer to use global variables.

The evaluation of an expression can also see global variables, in fact only global variables and variables given as arguments to the evaluation.

>function ev(fx,x) := fx(x) >a=6; ev("a*x",2) 12

Arguments take precedence over global variables.

>a=5; f(2,3) 6 >"a*x"(2,a=3) 6 >"a*x"(2) 10

Furthermore, there is a global list type. Lists can grow as long as needed.

>glist("v"); >for i=1 to 1000; glistadd("v",i^2); end; >s=0; for i=1 to 1000; s=s+glistvar("v",i); end; s, >sum((1:1000)^2) // check

See:

global (Euler Core),

gvar (Euler Core),

glist (Euler Core)

Symbolic variables are created with &=. These variables are defined in the Maxima subsystem, and copied to EMT as strings which are marked as symbolic. Symbolic strings print via Maxima as 2D display formulas.

>f &= x^3-x >df &= diff(f,x) // evaluates, then assigns to df >df // prints as display formula >df(5) // evaluates with x=5 like a string expression

Symbolic variables of Maxima can be used in EMT as expressions for numerical algorithms, since there is a symbolic string variable in EMT with the same name.

>f &= exp(x)*(x^2+1); >df &= diff(f,x); >solve(df,1,y=2) // solve f'(x)=2 numerically 0.248792696686 >plot2d(df,-3,1): // plot f'(x)

In Euler, a symbolic variable (set with &=) is simply a string.

>f &= x^3-x; >"String: "+f

If you need a value in Euler and Maxima, use &:=. Then the variable on the numerical side of EMT is no longer a symbolic string, but a value.

>A &:= [1,2;3,4] // A in both worlds >eigenvalues(A) // can be used numerically >&eigenvalues(A) // can be used symbolically >A.A // numerical result >&A.A // symbolic result

Elements of symbolic matrices can be changed in Maxima as usual.

>A &= [x,1;2,3] >&A[1,1] := y // Note: A[1,1] &= y does not work !!! >&det(A)

A variable can also be defined just for Maxima with &&= (purely symbolic variable). There will be no symbolic string variable in the numerical side of EMT. You can still access the expression in the variable with &variable. Note that &&= does not evaluate the right hand side symbolically before the definition. It evaluates when it is called at runtime.

>expr &&= integrate(x^3,x); >&expr

For more information, see

Symbolic Functions - programming Maxima

Maxima at Compile Time - create advanced functions

The -> operator converts units. If the conversion goes to a string, the units in this string will be used, and the units will be printed after the result.

>2km/h->miles/min >2km/h->" m/s"

For a list of all units see the file units.e.

See:

units (Euler Core),

units (Maxima Documentation)

Euler has vectors and matrices. Vectors are just 1xn (row vectors) or nx1 (column vector) matrices. To enter a matrix, separate the elements by a comma and the rows by a semicolon.

>A = [1,2;3,4] >v = [5,6] // row vector >w = [5;6] // column vector >v.A // A.v does not work !!! >A.v' // v' is the transpose of v >A.w >w'.w // scalar product

Note that . is the matrix product. The usual operators and functions work element for element. This is the matrix language of EMT.

>sqrt(A) // takes the square root of all elements of A >A*A // squares all elements of A

Matrices can also be formed of vectors and other matrices.

>A=[1,2;3,4]; // 2x2 matrix >b=[1;2]; // column vector >A|b // horizontal concatenation >A_b' // vertical concatenation >[b,b^2,b^3] // matrix of columns >[b';b'^2] // matrix of rows

Matrix elements or sub-matrices are referred to with square brackets. For vectors, only one index is necessary, of course. For matrices, one index refers to the complete line.

>A=[1,2,3;4,5,6;7,8,9] >A[2,2] >A[1] // first row >A[,2] // second column >A[1:2,1:2] // 2x2 sub-matrix >A[-1] // last row >A[[2,1]] // rows 2 and 1

Matrices can be assigned to sub-matrices, if they fit. Values can be assigned to sub-matrices.

>A[1:2,1:2]=[3,4;5,6] >A[1]=A[2]+A[3] >A[3]=-1

There are numerous functions to generate or handle matrices and vectors. Here are just a few examples.

>setdiag(setdiag(2*id(5),-1,1),1,1) // tri-diagonal matrix >diagmatrix(1:5) >A=normal(3,3); A=A/getdiag(A) // normalize diagonal to 1 >nonzeros(isprime(1:20)) // nonzero indices of vector >A=random(3,3); k=mnonzeros(A>0.5) // nonzero indices of matrix >mset(A,k,-A) // set indices to value or matrix

See:

Matrix Language (Overview)

Basic Rule

Operators and functions are applied element-wise to their operands, and the result is a matrix of the same size.

In case, the operands or parameters do not fit in size, Euler tries to expand the smaller one to the size of the larger one by duplication.

>sqrt(1:5) [ 1 1.41421356237 1.73205080757 2 2.2360679775 ]] >(1:5)*4 [ 4 8 12 16 20 ]] >(1:5)^2 [ 1 4 9 16 25 ]] >short (1:5)*(2:6)' 2 4 6 8 10 3 6 9 12 15 4 8 12 16 20 5 10 15 20 25 6 12 18 24 30

If one of the operands is only a vector, the other a matrix, the

operators work, as if the vector was duplicated to the size of the matrix. E.g., if a column vector v and a matrix A are combined, the result is a matrix R[i,j], applying the operator to v[i] and A[i,j]. If a row vector v and a column vector w are combined the result combines v[i] with v[j].

All matrices must have the same size. Row vectors must have the same number of rows as any parameter matrix, and column vectors the same number of columns. If the operands do not fit together, there will be an error message.

Scalar values can be combined with any matrix or vector. In this case, the scalar is combined with all elements of the matrix or vector.

EMT can do calculus symbolically and numerically. Have a look at the following sections to learn more.

Derivatives - Compute Derivatives

Integrals - Compute Integrals

Differential Equations - Solve Differential Equations

For symbolic methods, you can also refer to

For general information about numerical methods in EMT, there are tutorials, examples and references.

Symbolic differentiation is done with &diff by Maxima. Here are some examples.

>expr&=x^2*cos(x*y); >&diff(expr,x) // derivative at s >&diff(expr,x,n) // n-th derivative at x >&diff(expr,x,1,y,1) // derivative to x and y >&diffat(expr,x=pi) // derivative to x at a >&diff(expr,x) with [x=pi,y=5] // alternative >&diffat(expr,x=pi,5) // n-th derivative to x at a

There are functions for the gradient, the Jacobian and the Hessian matrix.

>expr &= x^2-x*y+y >&gradient(expr,[x,y]) >sol &= solve(gradient(expr,[x,y])) >&hessian(expr,[x,y]) with sol[1]

Numerical differentiation is done with diff(). Note that numerical differentiation is numerically inaccurate or very expensive.

>diff(expr,a) // derivative at a >diff("x^x",1) // e.g.

>function f(x,a) := x^x*sin(a*x) >diff("f",1;5) // e.g. with a=5

>diff(expr,a,n) // n-th derivative at a

Integration is available symbolically and numerically with a variety of methods.

For symbolic integration, use &integrate.

>&integrate(expr,x) // anti-derivative >&integrate(expr,x,a,b) // definite integral >&assume(y>0); &integrate(x^y,x) // necessary sometimes

Or define an integral first, then evaluate it.

>function F(x) &= integrate(f(x),x) >F(b)-F(a) // works better sometimes

>F &= integrate(f(x),x) // alternative way using an expression >(F with x=b)-(F with x=a) // evaluate expressions

For numerical integration, the default integrate() uses an adaptive Gauss scheme.

>integrate(expr,a,b) // adaptive Gauss >integrate("exp(-x^2)",0,1) // e.g.

>function f(x,a) := exp(-x^2*a) >integrate("f",0,1;5) // e.g. with a=5

Some more methods for integration are available. (gauss, gauss5, romberg, simpson, adaptiveint). Some are from the AlgLib library (alintegrate, alsingular). The fastest method is gauss5.

>gauss5("exp(-x^2)",0,1) // 5 evaluations of the function >gauss5("exp(-x^2)",0,1,20) // 20 subintervals, 100 evaluations

There are also advanced methods using intervals for guaranteed inclusions.

>mxmiint(expr,a,b)

The results are very narrow intervals. But the effort is big. igauss() is another function which gets guaranteed bounds.

>expr &= exp(-x^2); >igauss(expr,0,1,10,&diff(expr,x,20)) // compute 20-th derivative >igauss(expr,0,1,10,dexpr20est=1e12) // provide estimate

Differential Equations can be solved by Maxima symbolically up to degree 2 with ode2.

>&ode2('diff(y,x,2)+'diff(y,x)+y=x^2,y,x)

To solve for initial values, there are ic1 (for one initial value) and ic2 (for two).

>sol &= ode2('diff(y,x,2)+y=x^2,y,x) // general solution >ysol &= ic2(sol,x=0,y=0,'diff(y,x)=1) // set initial values >function f(x) &= y with ysol; // define a function from ysol

Maxima has some more advanced functions for differential equations, including systems of differential equations (&desolve, &ode2, &ic1, &ic2, &bc2).

>eq1 &= 'diff(f(x),x) = g(x) // first equation >eq2 &= 'diff(g(x),x)+x^2 = -f(x) // second equation

>&atvalue(f(x),x=0,0); // fix f(0)=0 >&atvalue(diff(g(x),x),x=0,1); // fix g'(0)=1

>sol &= desolve([eq1,eq2],[f(x),g(x)]) // solve >function fsol(x) &= f(x) with sol[1] // make it a function

Numerical solutions can be obtained with many functions in EMT. One is ode(), which uses the LSODA algorithm.

>t=0:0.01:5; plot2d(t,ode("-x*y",t,1)): // e.g.

Second order differential equations need to be translated to systems of equations.

>function f(x,y) := [y[2],sin(y[1])*x] >t=0:0.01:5; y=ode("f",t,[1,0]); >plot2d(t,y[1]):

EMT has more functions for differential equations, including interval functions with guaranteed inclusions (runge, adaptiverunge, heun, lsoda, mxmidgl). For the adaptive versions, you do not need intermediate points.

>lsoda("-x*y",[0,1],1)[-1] // last value of solution, i.e. y(1) >adaptiverunge("-x*y",[0,1],1)[-1] // adaptive Runge method

The function mxmidgl() calls Maxima for a Taylor development of high degree.

>mxmidgl("-x*y",0:0.01:1,1)[-1]

For more information about differential equations refer to the tutorials or the reference.

EMT Math Toolbox has plots in 2D and 3D, both for data and functions. Click on the sections below.

Plots in 2D - Plots in the 2D plane

Plots in 3D - Plots in the 3D space

Implicit Plots - Plots of level lines of functions
Logarithmic Plots - Plots with logarithmic scales

Styles of 2D Plots - Setting own plot labels, grid styles or axis ticks

Statistical Plots - Plots for statistical data

Plot Aspect - Aspect Ratio of the plot window

Basic Plots - Very basic functions for plots

It is possible to plot in Maxima using Gnuplot. or in Python using Math Plot Lib. But we do not cover these subjects here.

For more information on plots, refer to

For planar plots, EMT uses the function plot2d. This function can plot functions and data. It can produce simple graphs, filled polygons, points and bar plots. Moreover, it can compute level lines, level sets and contour plots.

>a:=5.6; expr &= exp(-a*x^2)/a // define expression >plot2d(expr,-2,2): // plot from -2 to 2 >plot2d(expr,r=1,thickness=2): // plot in a square around (0,0) >plot2d(&diff(expr,x),>add,style="--",color=red): // add another plot >plot2d(&diff(expr,x,2),a=-2,b=2,c=-2,d=1): // plot in rectangle >plot2d(&diff(expr,x),a=-2,b=2,>square): // keep plot square

These examples used symbolic expressions in the variable "x". Of course, this works for numerical expressions too.

>p=chebpoly(10); plot2d("polyval(p,x)",-1,1): // plot polynomial >plot2d(''integrate("sin(x)*exp(-x^2)",0,x)'',0,2): // plot integral

And it works for functions. As usual in EMT functions that work for other functions or expressions, you can pass additional parameters (besides x) to the function with semicolon parameters or with a call collection.

>function f(x,a) := x^2/a+a*x^2-x; // define a function >plot2d("f",0,1;0.4): // plot with a=0.4 >plot2d({{"f",0.2}},0,1): // plot with a=0.2 >plot2d({{"f(x,b)",b=0.3}},0,1): // plot with a=0.3

For data plots, you need one or more rows of x-values, and one or more rows of y-values.

>xdata=[1,1.5,2.5,3,4]; ydata=[3,3.1,2.8,2.9,2.7]; // data >plot2d(xdata,ydata,a=0.5,b=4.5,c=2.5,d=3.5,style="."); // lines >plot2d(xdata,ydata,>points,>add,style="o"): // add points

>p=polyfit(xdata,ydata,1); // get regression line >plot2d("polyval(p,x)",>add,color=red): // add plot of line

Thus, we can also plot curves or filled curves.

>t=linspace(0,2pi,1000); // parameter for curve >x=sin(t)*exp(t/pi); y=cos(t)*exp(t/pi); // x(t) and y(t) >plot2d(x,y,r=10): // plot curve >plot2d(x,y,r=10,>filled,style="/",fillcolor=red): // fill curve

The plot of multiple functions can be done with >add, possible using a loop. We have used this feature already in the examples above.

>plot2d("(1-x)^10",0,1); // plot first function >for i=1 to 10; plot2d("bin(10,i)*x^i*(1-x)^(10-i)",>add); end; >insimg;

But it can also be done with a matrix of x-values, and a matrix of y-values.

>x=linspace(0,1,500); >n=10; k=(0:n)'; // n is row vector, k is column vector >y=bin(n,k)*x^k*(1-x)^(n-k); // y is a matrix then >plot2d(x,y):

Another method is a vector of expressions. We can get such a vector from Maxima using makelist() and mxm2str().

>plot2d(["sin(x)","cos(x)"],0,2pi): // plot vector of expressions

>v &= makelist(binomial(10,i)*x^i*(1-x)^(10-i),i,0,10) // make list >mxm2str(v) // get a vector of strings from the symbolic vector >plot2d(mxm2str(v),0,1): // plot functions

For more information, refer to the tutorial about 2D plots, or the documentation about plot2d().

plot2d - Reference to the main function for 2D Plots

Plot Aspect - Change the aspect ratio of the plot window

Plots - Overview of Plots

EMT uses the "logplot" parameter for logarithmic scales. 1 is for the x-axis, 2 for both axes, and 3 for the x-axis only.

>plot2d("exp(x+sin(x))",0,100,logplot=1): >plot2d("exp(x+sin(x))",10,100,logplot=2): >plot2d("log(x*(2+sin(x/100)))",10,1000,logplot=3):

This does also work with data plots.

>x=10^(1:20); y=x^2-x; >plot2d(x,y,logplot=2):

Plots - Overview of Plots

By default, EMT computes automatic axis ticks and adds labels to each tick. This can be changed with the grid parameter.

>plot2d("x^3-x",grid=0) // no grid, frame or axis >plot2d("x^3-x",grid=1) // x-y-axis >plot2d("x^3-x",grid=2) // default ticks >plot2d("x^3-x",grid=3) // x-y- axis with labels inside >plot2d("x^3-x",grid=4) // no ticks, only labels >plot2d("x^3-x",grid=5) // default, but no margin >plot2d("x^3-x",grid=6) // axes only >plot2d("x^3-x",grid=7) // axes only, ticks at axis >plot2d("x^3-x",grid=8) // axes only, finer ticks at axis >plot2d("x^3-x",grid=9) // default, small ticks inside >plot2d("x^3-x",grid=10) // no ticks, axes only

The parameter <frame switches off the frame, and framecolor=blue sets the frame to a blue color.

If you want your own ticks, you can use style=0, and add everything later.

>plot2d("x^3-x",grid=0); // plot >frame; xgrid([-1,0,1]); ygrid(0): // add frame and grid

For the plot title and labels of the axes, see the following example.

>plot2d("exp(x)",-1,1); >textcolor(black); // set the text color to black >title("y=exp(x)"); // title above the plot >xlabel("x"); // "x" for x-axis >ylabel("y",>vertical); // vertical "y" for y-axis >label("(0,1)",0,1,color=blue); // label a point >reset: // to revert the text color

The axis can be drawn separately with xaxis() and yaxis().

>plot2d("x^3-x",<grid,<frame); >xaxis(0,xx=-2:1,style="->"); yaxis(0,yy=-5:5,style="->"):

Text on the plot can be set with label(). In the following example, "lc" means lower center. It sets the position of the label relative to the plot coordinates.

>function f(x) &= x^3-x >plot2d(f,-1,1,>square); >x0=fmin(f,0,1); // compute point of minimum >label("Rel. Min.",x0,f(x0),pos="lc"): // add a label there

There are also text boxes.

>plot2d(&f(x),-1,1,-2,2); // function >plot2d(&diff(f(x),x),>add,style="--",color=red): // derivative >labelbox(["f","f'"],["-","--"],[black,red]): // label box

There are interactive sliders, which can set values by the user. The function dragvalues() provides this.

>function plotf([a,b]) := plot2d("exp(a*x)*cos(2pi*b*x)",0,2pi;a,b); >dragvalues("plotf",["a","b"],[-1,2],[[-2,2];[1,10]], ... > heading="Drag these values:",hcolor=black):

Plots - Overview of Plots

To draw the set f(x,y)=c for one or more constants c you can use plot2d() with its implicit plots in the plane. The parameter for c is level=c, where c can be vector of level lines. Additionally, a color scheme can be drawn in the background to indicate the value of the function for each point in the plot. The parameter "n" determines the fineness of the plot.

>expr := "2*x^2+x*y+3*y^4+y"; // define an expression f(x,y) >plot2d(expr,level=0): // Solutions of f(x,y)=0 >plot2d(expr,level=0:0.5:20,>hue,contourcolor=white,n=200): // nice >plot2d(expr,level=0:0.5:20,>hue,>spectral,n=200,grid=4): // nicer

This works for data plots too. But you will have to specify the ranges for the axis labels.

>x=-2:0.05:1; y=x'; z=expr(x,y); >plot2d(z,level=0,a=-1,b=2,c=-2,d=1,>hue): >z=z+normal(size(z))*0.2; >plot2d(z,level=0.5,a=-1,b=2,c=-2,d=1):

It is possible to fill regions of values for a specific function. For this, level must be a 2xn matrix. The first row are the lower bounds and the second row contains the upper bounds.

>plot2d(expr,level=[0;1],style="-",color=blue): // 0 <= f(x,y) <= 1 >plot2d(expr,level=[0:0.2:5;0.05:0.2:5.05],color=lightgray):

The following is the set of the maximal value of four linear conditions less than or equal 3. This is A[k].v<=3 for all rows of A. To get nice corners, we use n relatively large.

>A=[2,1;1,2;-1,0;0,-1]; >function f(x,y) := max([x,y].A'); >plot2d("f",r=4,level=[0;3],color=green,n=111):

3D Plots in EMT are done in central projection. The algorithm used is very quick and usually produces very nice plots. For photo-realistic output, you can install Povray and use it from EMT. EMT can also do anaglyph plots for red/cyan glasses.

The most elementary form shows the graph of a function in x and y and uses an expression in x and y or a function.

>plot3d("x^2+y^2"): >plot3d("x*abs(y)^1.4", ... > contour,>spectral,angle=-60°,height=20°,scale=1.1): >plot3d("x^2+y^3",>contour,angle=30°,level=-2:0.2:2): >plot3d("x^y-y^x",a=0,b=4,c=0,d=4,n=200,level=0,light=[0,1,0]):

>function f(x,y,a) := x^2+y^a >plot3d("f";4.5,a=0,b=1,c=0,d=1,>contour,angle=20°): // with a=4.5

For general surfaces, three functions can be used. Then, no scaling takes place and the default view and zoom is used.

>plot3d("x*y"): >plot3d("x","y","x*y",xmin=-2,xmax=2,ymin=-2,ymax=2, ... > scale=[2,2,1],n=10):

Matrices of x-, y-, and z-coordinates can be used to represent the surface. The matrix language of EMT allows that x can be row vector and y a column vector only.

>x=-2:0.05:2; y=x'; plot3d(x,y,x*y,scale=[2,2,1]; grid=10):

For an example with shading, we plot a ball.

>s=linspace(0,2pi,180); t=linspace(-pi/2,pi/2,90)'; >plot3d(cos(s)*cos(t),sin(s)*cos(t),sin(t), ... > >hue,grid=[6,4],<frame,color=blue,scale=1.5,height=45°,angle=45°):

For clouds of points or lines, use >points or >wire.

>A=normal(3,500); plot3d(A[1],A[2],A[3],>points): // cloud of points >W=cumsum(A); plot3d(W[1],W[2],W[3],>wire): // path in 3D

For more information, refer to the tutorial for 3D plots or the documentation of plot3d.

Plot Aspect - Change the aspect ratio of the plot window

plot3d - Main function for 3D plots

Plots - Overview of Plots

The default plot uses a square plot window. You can change this with the function aspect(). Do not forget to reset the aspect later.

>aspect(2); >plot2d(["sin(x)","cos(x)"],0,2pi): >aspect();

In 3D Plots, we can change the scaling of the z-values. The following is a polar plot, which graphs the function on a disk.

>aspect(2); >plot3d("x^2+y^4",fscale=0.4,scale=1.6,>contour,>spectral>polar): >reset;

The reset() function restores plot defaults including the aspect ratio.

There are many functions which are specialized on statistical plots. For a demonstration, refer to the tutorial on statistics.

One of the often used plots is a column plot.

>columnsplot(cumsum(random(10)),style="/",color=blue):

It can also show strings as labels.

>months=["Jan","Feb","Mar","Apr","May","Jun", ... > "Jul","Aug","Sep","Oct","Nov","Dec"]; >values=[10,12,12,18,22,28,30,26,22,18,12,8]; >columnsplot(values,lab=months,color=red,style="-"); >title("Temperature"):

To plot an experimental statistical distribution, you can use distribution=n with plot2d.

>w=randexponential(1,1000); // exponential distribution >plot2d(w,>distribution): // or distribution=n with n intervals

Or you can compute the distribution from the data and plot the result with >bar in plot3d, or with a column plot.

>w=normal(1000); // 0-1-normal distribution >{x,y}=histo(w,10,v=[-6,-4,-2,-1,0,1,2,4,6]); // interval bounds v >plot2d(x,y,>bar):

The statplot() function sets the style with a simple string.

>statplot(1:10,cumsum(random(10)),"b"):

For more statistical plots, refer to the tutorial on statistics, or the following introduction.

Statistics - Introduction to Statistics in EMT

There are also very basic functions of plots. The following is just a brief introduction into these elementary functions.

plots - Core functions for elementary Plots.

There are screen coordinates, which always range from 0 to 1024 in each axis, no matter if the screen is square or not. Ant there are plot coordinates, which can be set with setplot(). The mapping between the coordinates depends on the current plot window. E.g., the default shrinkwindow() leaves space for axis labels and a plot title.

In the example, we just draw a few random lines in various colors. For details on these functions, study the core functions of EMT.

>clg; // clear screen >window(0,0,1024,1024); // use all of the window >setplot(0,1,0,1); // set plot coordinates >hold on; // start overwrite mode >n=100; X=random(n,2); Y=random(n,2); // get random points >colors=rgb(random(n),random(n),random(n)); // get random colors >loop 1 to n; color(colors[#]); plot(X[#],Y[#]); end; // plot >hold off; // end overwrite mode >insimg; // insert to notebook

It is necessary to hold the graphics, since the plot() command would clear the plot window.

To clear everything we did, we use

>reset;

For another example, we draw a plot as an inset in another plot. This is done by defining a smaller plot window. Note that this window does not provide room for the axis labels outside the plot window. We have to add some margin for this as needed. Note that we save and restore the full window, and hold the current plot while we plot the inset.

>plot2d("x^3-x"); >xw=200; yw=100; ww=300; hw=300; >ow=window(); >window(xw,yw,xw+ww,yw+hw); >hold on; >barclear(xw-50,yw-10,ww+60,ww+60); >plot2d("x^4-x",grid=6); >hold off; >window(ow);

A plot with multiple figures is achieved in the same way. There is the utility figure() function for this.

The Tutorial about plots contains another example of a function made of basic plot routines.

See:

window (Plot Functions),

figure (Plot Functions)

EMT can generate random numbers for various distributions. They are usually named rand... with a few exceptions. E.g.

>mean(normal(100000)) // 0-1-normal distributed values >dev(random(100000)) // uniformly distributed values in ]0,1[

>w=randnormal(1,100000,1000,10); > // 1x100000 matrix of 1000-10-norm. values >plot2d(w,>distribution): // plot the distribution

>w=intrandom(1,600,6); // 1x600 matrix of dice throws >getmultiplicities(1:6,w) // count multiplicities >mean(randexponential(1,100000,2)) // exponential distribution

EMT has many distribution functions and their inverses.

>normaldis(3) // 0-1-normal distribution function >[invnormaldis(2.5%,1000,10),invnormaldis(97.5%,1000,10)] > // 90% confidence interval of 1000-10-normal distribution >invcchidis(chicdis(30,10),10) // inverse complimentary chi-square

Most density functions are also present. They are named like qnormal().

>plot2d(normal(1000),>distribution); // plot empirical data >plot2d("qnormal(x,0,1)",>add,color=red,thickness=2): > // add expected density

Here are some examples of statistical indicators, derived from empirical data.

>x=normal(1000); >boxplot(x): >mean(x), dev(x) >median(x) >getfrequencies(x,-4:4) // count number of items in intervals >covar(x[1:2:999],x[2:2:1000]) // empirical covariance >quartiles(x) // quartiles, neglecting outliers >quantile(x,10%) // 10% quantile >plot2d(-4:4,empdist(-4:4,sort(x))): // empirical distribution

There are statistical tests too.

>X=normal(3,10); // get 3 rows of data to test for same mean >varanalysis(X[1],X[2],X[3]+2) // will be rejected >mediantest(X[1],X[2]+2) // will be rejected >signtest(X[1],X[2]+2) // will be rejected

>v=randexponential(1,1000,0.5); >x=getfrequencies(v,0:0.1:1) // frequencies of exponential data >y=ones(1,10)*sum(x)/10 // assumed uniform distribution >chitest(x,y) // will be rejected

For statistical plots refer to

Statistical Plots - Special plots for statistics

For more information about statistics in EMT, refer to

To solve a an equation or a system of equations symbolically, use &solve(). The function returns a vector of solutions. To insert one of the solutions into an expression, use with.

>&solve(diff(x^3-x,x)) // all critical values (assume expr=0) >expr &= x^3-x >&solve(diff(expr,x)=0,x), &expr with %[1] // value at maximum

Systems are solved in a similar way. The solution is a vector of solutions, which are in turn vector of equations [x=3,y=4] etc.

>sol &= solve([x^2+y=4,x-2*y=a],[x,y]) // system of 2 equations >&[x,y] with sol[1] with a=4 // get first solution with a=4

To solve an equation numerically, the default function is solve(), which uses a secant algorithm.

>solve("x^x-3",1) // solve near 1 >solve(&diff(x^x,x),0.5) // with symbolic expression >solve(&diff(x^x,x),1,y=2) // target value y=2 near 1

>function f(x,a) := x^x-a*x >x1 := solve("f",1,2;0.2,y=1) // with a=0.2 between 1 and 2

There are more algorithms, some of them with guaranteed inclusions.

>bisect("x^3",1,2,y=2,eps=0.01) // reduced accuracy >ibisect("x^3",1,2,y=2) // guaranteed inclusion >secantin("x^x",0,0.2,y=0.9) // keep solution in interval

>expr &= diff(x^x,x) >newton(expr,&diff(expr,x),0.5) // Newton for expr=0 >inewton(expr,&diff(expr,x),0.5) // guaranteed and fast solution

To solve a system of equations, Broyden's algorithm is fast and converges for close starting points.

>function f(x) := [x[1]^2+x[2]^2-10,x[1]+2*x[2]-4] >broyden("f",[0,3]), f(%) // solve and test result

>function f([x,y]) := [x^2+y^2-10,x+2*y-4] // easier definition of f

For the Newton algorithm, we need the Jacobian.

>function f([x,y]) &= [x^2+y^2-10,x+2*y-4] // f >function Df([x,y]) &= jacobian(f(x,y),[x,y]) // Jacobian of f >newton2("f","Df",[0,3]) // Newton algorithm >inewton2("f","Df",[0,3]) // guaranteed inclusion

Expanding and factoring of symbolic expressions can be done with very large expressions.

>&factor(diff(expand((1+x)^20),x)) >&factor(x^6+x^2+1) >&factor(x^6+x^2+1) | modulus:=13 // factor in Z modulo 13 >&expand((1+x)^4+(1+x)^2+1/(1+x)^2+1/(1+x)^4,2,2) // limit expansion

To factor numbers, use a direct mode.

>:: factor(100!)

There are various to extract parts of an expression.

>expr &= expand((a*x^3+a^2*x+b*x+y)*(a*x+y)) >&part(expr,2) // second term in expression >&collectterms(expr,x) // make a polynomial of x >&coeff(expr,x,2) // coefficient of x^2 >&combine(a/b+c/d+e/b) // combine fractions

For simplification, there are many methods.

>&ratsimp(1/x+1/x^2+(x+1)/x) // try to simplify a fraction >&partfrac((x^2+1)/(x^2-1),x) // sum as partial fractions >&trigsimp((sin(x)+cos(x))*(2*sin(x)+cos(x))) // apply rules for trig >&radcan((log(1+2*a^x+a^(2*x))/log(1+a^x))) // apply rules for radicals

There are many options for expansions and reductions.

>&trigexpand(sin(5*x),x) // make it a polynomial in sin(x), cos(x) >&trigreduce(sin(x)^5,x) // make it a trigonometric series

>&log(a*b) | logexpand:=all // apply rules of log >&logcontract(log(x)+log(y)) // collect sums of log

>&sqrt(x^y) | radexpand:=all // apply rules for sqrt >&multthru(a*x+1,b+c) // multiply into sum >&distrib((1+x*(2+x))*(1+y)) // apply distrib. rule >&rootscontract(sqrt(x)*sqrt(y)) // contract roots >&scsimp(a*b+b*c,a*b+d=1,b*c=d) // simplify with rules

Do not forget, that you can map a function to each argument.

>&map(sqrt,x+y) >&map(ratsimp,(1+x)/(1-x^2)+(x^2+2*x+1)/(x^2-1))

You can get examples for manipulations.

>:: example(radcan)

Functions of one variable are minimized with fmin(). With several variables, use the Nelder Mead algorithm or Powell's algorithm

>fmin("x^3-x",0,1), "x^3-x"(%) >function f([x,y,z]) &= x^2+y^2+z^2+exp(-x*y*z)+x >nelder("f",[0,0,0]) // start from x=y=z=0 >powellmin("f",[0,0,0]) // start from x=y=z=0 >&grad(x^2+y^2+z^2+exp(-x*y*z)+x) with [x=-1/2,y=0,z=0]

Alternatively, the Broyden algorithm could be used for grad f=0.

>function f([x,y,z]) &= x^2+y^2+z^2+exp(-x*y*z)+x >function df([x,y,z]) &= grad(f(x,y,z)) >broyden("df",[0,0,0])

The simplex algorithm can be called via simplex() or the LPSOLVE library.

>A=[1,2;3,4;4,2] // mxn matrix A >b=[10,8,7]' // column vector b >c=[1,1] // row vector c >simplex(A,b,c,>max) // solve cx->max with Ax<=b, x>=0

Here is an example with equalities

>A=random(5,10); b=sum(A); >c=ones(1,10); >simplex(A,b,c,eq=0,>max)

Another example with a mix of >= and <=.

>A=[1,1;1,1;1,-1;1,-1] // 4 inequalities -1<=x+y<=1, -1<=x-y<=1 >b=[-1,1,-1,1]' // right hand side >eq=[1,-1,1,-1]' // equations >=, <=, >=, <= >restr=[0,0] // no restriction x>=0 >c=[1,1.2]; // target function >simplex(A,b,c,eq,restr,>max) // solve

For integer problems, use intsimplex() or the efficient LPSOLVE.

>A=random(10,2); b=ones(10,1)*100; >c=[1,1]; >simplex(A,b,c,>max) >intsimplex(A,b,c,>max) >ilpsolve(A,b,c,>max)

For non-linear problems, you can use the Newton-Barrier method.

>A=1+random(1000,2); // 1000 linear conditions >b=100+random(1000,1)*100; // right hand side >A=A_-id(2); b=b_zeros(2,1); // add x>=0 >function f([x,y]) &= 1/(x*y); // target function >function df([x,y]) &= gradient(f(x,y),[x,y]); // gradient >function Hf([x,y]) &= hessian(f(x,y),[x,y]); // Hessian >newtonbarrier("f","df","Hf",A,b,[1,1])

Here is an example with a linear target function.

>A=random(40,5)_-id(5); b=ones(40,1)*10_zeros(5,1); >c=ones(1,5) >simplex(A,b,c,>max) // for comparison >function f(x) := -c.x'; // x is a row vector here >function df(x) := -c; >function Hf(x) := 0; >x=newtonbarrier("f","df","Hf",A,b,ones(1,5)*0.01)

See:

simplex (Linear Programming)

For more examples and the reference see

Linear regression with polynomials can be done with polyfit().

>function f(x) := 0.8*x+0.1; // correct function >x=0:0.1:1; y=f(x)+random(cols(x))*0.4; // random values >plot2d(x,y,>points); // plot values >p=polyfit(x,y,1) // fit with polynomial of degree 1 >plot2d("polyval(p,x)",>add,color=red): // add fit to plot

General linear fits can be done with fit(A,y). This minimizes |Ax-y|.

>function f(x) := exp(-0.2*x)+0.5*exp(-0.4*x)+0.3 > // of type a*exp(-0.2*x)+b*exp(-0.4*x)+c >x=0:5; y=f(x)+random(cols(x))*0.4; >plot2d(x,y,>points); // plot random data >A=exp(-0.2*x')|exp(-0.4*x')|1 >a=fit(A,y') >function ff(x) := a[1]*exp(-0.2*x)+a[2]*exp(-0.4*x)+a[3] >plot2d("ff(x)",>add,color=red): >mean(ff(x)-y), dev(ff(x)-y) // 0 and norm of difference

For non-linear fits of all kinds, one choice is Nelder-Mead.

>function f(x) := exp(-0.2*x)+0.5*exp(-0.4*x) > // of type exp(c*x)+0.5*exp(d*x) >x=0:5; y=f(x)+random(cols(x))*0.1; >plot2d(x,y,>points); // plot random data >function ff(x,[c,d]) := exp(c*x)+0.5*exp(d*x); >function ferr(v) := sqrt(sum(ff(x,v)-y)^2) >v=nelder("ferr",[-1,-1]) >plot2d("ff(x,v)",>add,color=red):

The numerical data types of EMT are based on the IEEE standard with an accuracy of 16 decimal digits. The default output does not show all significant places.

>1/3 // default output of a single number >longest 1/3 // all digits >fraction 1/3 // output as fraction >shortest pi // very short output >long exp(1+2*I) // complex number, long output >sin(pi), longest sin(pi) // rounding towards 0

There are more formats for the output and input.

>print(1000*1.03^5,2,15," Euro") // print function >degprint(21.567°) >printdate(date(day(2011,9,11,12)+1000)) >printhex(sqrt(2))

To enter vectors and matrices use [].

>A=[1,2,3;4,5,6] // 2x3 matrix >A[1] // first row >A[,2] // second column >A[1,2:3] // first row, column 2 to 3 >[1,2,3;4] // second row auto-filled with 0 >[1,2;3,I] // complex matrix >v=1:10 // row vector 1 to 10 >v[5:7] // elements 5 to 7

Matrix Language - Matrix Language of EMT

EMT can also use strings and vectors of string.

>"Just a string!" >"Strange character: "+char(156) // number to character >strtochar("Help") // get numbers >r=6.7; "Area of circle with radius "+r+" = "+(pi*r^2) >plot2d(["cos(x)","sin(x)"],0,2pi):

Expressions - Expressions in EMT

There are also intervals. The rule of operators and functions is that all possible points in the intervals are used.

>~-1,2~*~-1,2~ // all x*y with -1 <= x,y <=2 >~-1,1~^2 // all x^2 with -1 <= x <= 1 >exp(~-1,1~) // all exp(x) with -1 <= x <= 1

Interval Arithmetic - Guaranteed Inclusions

There are many methods to solve a linear system in Euler.

>A=[1,2;3,4] >b=[1;4] >A\b // Gauss algorithm

>A=redim(1:9,3,3) // singular matrix ! >b=sum(A) >fit(A+normal(size(A)),b) // fit with orthogonal methods >svdsolve(A,b) // fit using singular values

For hand work there is a pivotize() function.

>A=[0,1,2;3,4,5;1,2,0]; b=sum(A); >M=A|b // produce the Gauss scheme >fraction pivotize(M,2,1) >fraction pivotize(M,1,2) >fraction pivotize(M,3,3)

>A=[0,1,2;3,4,5;1,2,0]; M=A|sum(A) >echelon(M) // all in one step

There are also function to handle a Gauss-Jordan scheme. See the tutorial on Linear Algebra for an example.

There are a lot more algorithms for Linear algebra.

>A=redim(1:9,3,3) >kernel(A) >svdkernel(A) // orthogonal basis of kernel

>eigenvalues(A), real(%) >{v,X}=eigen(A); v, // LAPACK algorithm for eigenvalues >real(inv(X).A.X)

>{U,v,W}=svd(A); >v // singular values

>{R,Q,c}=qrdecomp(A); // QR decomposition >Q'.R // is A

For symbolic linear algebra, you can define symbolic matrices or transport a numerical matrix to Maxima.

>A &= [1,2,3;4,5,6;7,8,x] >&determinant(A), &solve(%=0)

>A=[1,2;3,4]; // numerical matrix >&invert(@A) // use direct in symbolic expression >&eigenvalues(@A)

>mxmset("A",random(2,2)) // define a matrix A in Maxima >&A

All operators and functions in EMT should obey the matrix language. I.e., they vectorize (map) to all elements of matrix operands.

>v=1:5 >v*v, sum(%) // vector of v[i]*v[i] and sum of it >v^3 // vector of v[i]^3 >3*v // vector of 3*v[i] >[1;2]*v // column vector and row vector combine to matrix >v.v' // for the matrix product, use "."!

Row and column vectors combine to matrix. Matrices and vectors combine to matrices.

>A=[1,2;3,4] >A*[4,5] // multiply columns with 4 and 5 >A*[4,5]' // multiply rows with 4 and 5

You can vectorize own functions using the map keyword.

>function map f(x) := integrate("sinc(x)",0,x) >f(0:0.5:2)

- Program Language of EMT

In the numerical kernel of EMT, expressions are strings, which may be marked as symbolic. Then they print va Maxima.

>expr := "x^3-x" // expression in string >plot2d(expr,-1,1): // plot expression >expr &= x^3-x // symbolic expression >expr // prints via Maxima >plot2d(expr,-1,1): // plot it

Expressions can be evaluated numerically. The variables x,y,z are assigned automatically. Other variables can be assigned by assigned parameters or via global variables.

>expr &= a*x^2 >a=4; expr(2.5) // use global variable >expr(2.5,a=5) // use assigned variable >"x*y^2"(3,4) // direct evaluation

Thus many algorithms of EMT can use expressions in x or functions. But as soon as additional parameters are involved, which are not global, functions should be preferred.

>a=5; plot2d("a*x^3-x",0,1): // use global a >function f(x,a) := a*x^3-x >plot2d("f",0,1;4): // use a=4 as semicolon parameter >plot2d("f(x,4)",0,1): // alternative

Symbolic expression can be evaluated by Maxima with "with". This is a nice way in EMT to use "at".

>expr &= exp(-x^2) >&expr with x=a >&expr with x=5.67 >&expr with x=sqrt(log(y)) >&x^2+y^2 with [x=5,y=4] >&at(x^2+y^2,[x=5,y=4]) // original Maxima syntax

"with" is a simple way to use results of "solve".

>&solve(x^3-2*x+1,x), &x with %[1] >&solve([x+y=5,x-2*y=4]); &[x,y] with %[1]

A special problem worth mentioning here is the conflict between an expression and a function with the same name. To avoid this, use names like fx, fxy or expr, which are not used for functions. If a function and an expression with the same name exists, the expression will be used.

The rule for interval arithmetic is that operators combine all elements of the parameter intervals and return an interval containing all these results. Functions are applied to all elements of the parameter interval similarly.

>~1,2~ * ~7,8~ // result: ~1*7,2*8~ >~-1,1~ * ~1,1~ // result: ~-1,1~ !!! >~-1,1~^2 // result: ~0,1~ !!! >sin(~-1,1~) // result: ~sin(-1),sin(1)~

Often, we express a function in terms of an expression. Then the rules for expressions overestimate the result of the function. There are clever methods to get closer inclusions.

>expr &= x^4-x^3+x^2+x-1 >x=1±0.02 // another way to enter an interval, use F8 >expr(x) // simple evaluation >expr(fmin(expr,left(x),right(x))) // best lower estimate >expr(fmax(expr,left(x),right(x))) // best upper estimate >ieval(expr,x) // using sub-division of interval

Integrals are good for obtaining guaranteed solutions.

>ibisect("x^3-x",1,2,y=1.4) // interval bisection >expr &= x^x >inewton(expr,&diff(expr,x),1,y=1.4) // interval Newton >mxminewton(expr,1,2,y=1.4) // automatic call of Maxima >mxmiint("x^x",1,2) // elaborate inclusion of integral >est20=ieval(&diff(exp(-x^2),x,20),0,2) > // estimate of 20-th derivative >igauss("exp(-x^2)",0,2,dexpr20est=est20) // close approximation >longest integrate("exp(-x^2)",0,2) // for comparison

There are also interval methods for linear system and for non-linear systems of equations.

Numerical polynomials are stored as vectors v of coefficients with the constant coefficient in v[1]. They can be evaluated and manipulated to some degree.

>p=[1,2,3]; // 1+2x+3x^2 >plot2d("evalpoly(x,p)",-1,1): >plot2d("evalpoly",-1,1;polydif(p)): // derivative of p >polymult(p,p) // coefficients of p^2

There are some special polynomials.

>chebpoly(10) // coefficients of 10-th Chebychev polynomial >cheb(0.6,10) // evaluate it in 0.6 >legendre(8) // Legendre polynomial

Interpolation can be done with the Newton scheme.

>p=[1,-1,2,-1] // a polynomial >xdata=1:4; ydata=evalpoly(xdata,p) // evaluated in 1,2,3,4 >dd=divdif(xdata,ydata) // divided differences >plot2d(xdata,ydata,>points); // plot points >plot2d("evaldivdif(x,dd,xdata)",>add): // plot interpolation >polytrans(xdata,dd) // get back the polynomial >q=polyfit(xdata,ydata,2) // fit polynomial of degree 2 >plot2d("evalpoly(x,q)",color=green,>add): // add to plot

Symbolic Polynomials can be derived from the vector with "sum". The converse can be done with "makelist".

>p &:= chebpoly(10) // vector of coefficients in Maxima and EMT >pol &= sum(p[k]*x^(k-1),k,1,11) // make it a polynomial >&makelist(coeff(pol,x,k),k,0,10), vpol = %() // get the vector back

Furthermore, EMT can compute the zeros of polynomials numerically.

>p=1|zeros(1,10)|1 // z^11 + 1 >plot2d(polysolve(p),>points): // Baurhuber iteration, plot zeros >polysolve(p,>usematrix) // eigenvalues of companion matrix

Interpolation with cubic splines are can be done with "spline".

>xdata=-5:5; ydata=zeros(size(xdata)); ydata[6]=1; // data points >plot2d(xdata,ydata,a=-5,b=5,c=-2,d=2,>points); >s=spline(xdata,ydata); // compute spline >plot2d("evalspline(x,xdata,ydata,s)",>add): // evaluate >t=linspace(-5,5,1000); >max(abs(evallinspline(t,xdata,ydata)-evalspline(t,xdata,ydata,s))) > // maximal distance between lineare and cubic spline

For B-Splines, use nspline().

>plot2d("nspline";(1:4)',2,1:7,a=0,b=8):

The internal accuracy of Euler number is the IEEE standard of about 16 decimal digits. Euler does not print all digits by default. This saves space and looks better. For one number, the following operators can be used.

>pi >longest pi >long pi >short pi >shortest pi >fraction 1/3+1/7

To format a number, there are many more functions. The result is always a string. Note that you can append strings with +.

>print(pi,5,10) // with number of digits and total length >K=1012.56; i=3.75%; >"E = "+print(K*(1+i),2,unit="$") // with additional unit >printdollar(K*(1+i)^4) // shortcut >degprint(pi/4) >degprint(0.56,<dms) // not with minutes and seconds >"polar: "+polarprint(1+I) >frac(1/3)+" + "+frac(1/7)+" = "+frac(1/3+1/7) // convert to frac >printf("pi = %10.2f",pi) // C style printf >"x = "+(pi*4+1) // string plus number in default format

You can also set the output format permanently.

>format(5,2); // 5 places with 2 digits after decimal dot >pi >12121.454354 >random(3,3) >1:10 >format(10); // nice format with 10 digits of accuracy >pi

By default, Euler makes a difference between the output of scalars, vectors and matrices. By default, scalars use a longer format, and vectors use a denser format. The function format(n,m) applies to all output, however.

>reset; // reset output >pi // uses the longer scalar format >1:10 // uses a dense vector output >random(3,3) // uses the default matrix format >denseoutput(0); 1:5 // turn off dense output >denseoutput(2); 1:5 // default >setscalarformat(5); pi // use 5 digits of accuracy for scalars

Some commands change the format for the subsequent output.

>shortestformat; random(2,8), pi // only for matrices >shortformat(>all); pi // for all output >longestformat; pi // always for all output >goodformat(12); pi >format(8,5); random(4,4) // for all output >goodformat(8,4); random(4,4), pi // for matrices only >goodformat(4,>all); random(4,4), pi >fracformat(10); intrandom(6,6,6)/intrandom(6,6,6) // fractions >defformat; // reset the default

Large matrices are eclipsed by default. There are several ways to see the full matrix.

>largematrices on; // or off - toggles the eclipsed output >showlarge A // shows A without eclipses >shortest A // may help to see the full matrix A

There are one-line and multi-line programs.

>function f(x) := x^3-x; // one-line function >function map f(x) // multi-line function ... $ if x>0 then return x^2 // if x>0 would not work for vectors x $ else return x^3 $ endif; $endfunction

To start a multi-line function type "function f(x)" and press Ctrl-Return. To edit a multi-line function click into its body. Use Ctrl-Return for line breaks, and Ctrl-Back for joining lines. Alternatively, you can press F9 and edit in a separate editor.

A variety of control structures are available, which work in one-line commands too, but usually spread several lines in programs. The loop with "repeat" is eternal, but can be left with until, while, or break;

>function f(x) ... $repeat $ xnew=(x+2/x)/2; $ until x~=xnew; $ x=xnew; $end; $return x; $endfunction

Other loops start with "for" and "loop". The for loop can loop over a vector.

>s=0; loop 1 to 10; s=s+#; end; s, >s=0; for i=1 to 10; s=s+i; end; s, >s=0; for i=10 to 1 step -1; s=s+i; end; s, >v=1:10; s=0; for i=v; s=s+i; end; s,

The "if" structure can have "else" and "elseif" branches. It needs an "endif". The condition does not work for vectors. So we need to vectorize with "map".

>function map f(x) ... $ if x<0 then return -1; $ elseif x==0 then return 0; $ else return 1 $ endif; $endfunction

Multiple return values are possible. Only the first return value will be used as an argument to another function, unless the modifier "args" is set.

>function f(a,b) := {b,a} >{x,y}=f(1,2); x, y, >function args f(a,b) := {b,a} >{x,y}=f(f(1,2)); x, y, // would not work without "args"

Parameters can be restricted to specific data types.

>function map f(a:real) := integrate("sinc(x)",0,a) >f(0:0.5:2)

For details on this, see the reference.

parameters - Reference for parameters

function - Reference for functions

trace - How to find errors in functions
alias - Define an alias for a function

Symbolic functions are functions which are defined for Maxima and for the numerical kernel of EMT. These functions must be one-line functions defined with &=. The definition can spread over several lines nevertheless.

>function f(x) &= x^x >function df(x) &= diff(f(x),x) >function h(x) &= diff(f(x),x) + ... > diff(f(x),x,2)

The body of the function is evaluated symbolically before it is defined. Thus df() in the example above is a valid function for EMT which can be evaluated numerically quickly and efficiently. Moreover, it can be used in other symbolic functions.

>plot2d("df",0,2); >&df(x+1)

There are also purely symbolic functions. These functions are known only to Maxima. They are not evaluated at the time they are defined. The following function computes df/dx^2+df/dy^2. It must of course be evaluated, when it is used, not at the time of its definition.

>function L(f) &&= diff(f,x,2)+diff(f,y,2) >u &= ratsimp(realpart((x+I*y)^3/exp(x+I*y))) >&ratsimp(L(u)) // should be 0, since u(x,y) is harmonic)

See:

Using a symbolic function inserts a Maxima result at compile time into the numerical EMT function.

>function f(x) &= integrate(x^3*cos(x),x) >type f // inspect the function

Symbolic expressions can also be inserted into multi-line functions. Again, the expression is evaluated at compile time, and the result is inserted into a normal EMT function. Take care to set brackets, since the result of the symbolic evaluation is inserted verbatim.

>expr &= x^x-2; >function newtoniterator (x) $ return x-(&:"expr")/(&:"diff(expr,x)"); $ endfunction >type newtoniterator // look at the definition >x=2; newtoniterator(x) >iterate("newtoniterator",x)

Comments can contain some markups.

- * Heading

- ** Sub-Heading

- ---

- latex: F(x) = \int_a^x f(t) \, dt

- mathjax: \frac{x^2-1}{x-1} = x+1

- maxima: 'integrate(x^3,x) = integrate(x^3,x)+C

- http://www.euler-math-toolbox.de

- See: http://www.google.de | Google

- image: test.png

Images cannot be read from the Web. For "See:", local web links are possible.

Paragraphs consists of one long line in the editor. Line breaks will start a new line. Paragraphs should be separated with an empty line.

Spell checking is toggled with F12. To enter a word into the private dictionary mark the word and press Ctrl-F12.

Most of the functions of EMT are not in the C core, but written in the programming language of EMT and loaded from Euler files (*.e) when the program starts. Euler files can be edited with any editor. To start the editing, enter

>load file

into the notebook and press F9 (internal editor) or F10 (external editor, by default JE). The file will be saved in the directory of the current notebook. In the case of the internal editor, EMT will wait for the editing to finish.

Scripts can contain

- definitions of functions (function ...)

- EMT commands (>...)

- calls to Maxima (>:: ...)

- comment functions (function comment name ...)

- maxima comment functions (maximafunction name ...)

- entries for the user menu (addmenu ...)

- comment sections (comment ... endcomment)

- single line comments (// ...)

- load commands for other Euler files (load filename)

Make sure, functions have proper comment lines. For core functions or functions in C loaded by a DLL, there are comment functions. For functions defined in Maxima in EMT, there is the maximafunction definition.

:: h(x) := x^3;

maximafunction h (x) ## Computes x^3 endfunction

Then

>help &h

will work. And &h will be known in the help window.

Help for Euler files is available by entering filename.e in the help window, or by double clicking on the line consisting of the load command.

Scripts can be run on the command line. Output will be lost however unless files are used. Use the parameter "-script script.e" to start EMT for a script. Details are explained in the web documentation.