# Overview and Introduction

Euler Math Toolbox is an integrated system of the numerical kernel Euler and the computer algebra program Maxima.

• The numerical part, the GUI, and the communication with Maxima have been developed by R. Grothmann, a professor of mathematics at the University of Eichstätt, Germany. Many open source numerical algorithms and libraries have been used.
• Maxima is a mature and very rich open source program for symbolic computations and infinite arithmetic. It is maintained by a group of developers in the net.
• Some other programs (Latex, Povray, Tiny C Compiler, Python) can be used in Euler to enable faster computations or better graphics.

The tutorial you are reading now is an introduction to this mighty program. You should learn the basics and see what Euler can do for you. For more tutorials and examples, or for the full reference, see the following sources.

If you are reading this in EMT as a notebook proceed by pressing return to execute the commands.

## The Command Line

When you execute a command, the cursor can be at any position in the command line. You can go back to a previous command or skip to the next command with the arrow keys. Or you can click into the comment section above the command to go to the command.

When you move the cursor along the line the opening and closing pairs of brackets or parentheses will highlight. Also, watch the status line. After the opening bracket of the sqrt() function, the status line will display a help text for the function. Execute the command with the return key.

>sqrt(sin(10°)/cos(20°))

0.429875017772


To see help for the most recent command, open the help window with F1. There, you can enter text to search for. On an empty line, the help for the help window will be displayed. You can press escape to clear the line, or to close the help window.

You can double click on any command to open the help for this command. Try double clicking the exp command below in the command line.

>exp(log(2.5))

2.5


You can copy and paste in Euler too. Use Ctrl-C and Ctrl-V for this. To mark a text, drag the mouse or use shift together with any cursor key. Moreover, you can copy the highlighted brackets.

## Basic Syntax

Euler knows the usual mathematical functions. As you have seen above, trigonometric functions work in radian. To convert to degrees, append the degree symbol (with the F7 key) to the value, or use the function rad(x). The square root function is called sqrt in Euler. Of course, x^(1/2) is also possible.

To set variables, use either "=" or ":=". For the sake of clarity, this introduction uses the latter form. Spaces do not matter. But a space between commands is expected.

Multiple commands in one line are separated with "," or ";". The semicolon suppresses the output of the command. At the end of the command line a "," is assumed, if ";" is missing.

>g:=9.81; t:=2.5; 1/2*g*t^2

30.65625


EMT uses a programming syntax for expressions. To enter

you have to set the correct brackets and use / for fractions. Watch the highlighted brackets for assistance. Note that the Euler constant is named E in EMT.

>E^2*(1/(3+4*log(0.6))+1/7)

8.77908249441


Fractions can be used for the output of numbers. A continued fraction approximation will be computed. Moreover, Maxima has an infinite integer arithmetic (see below).

In the following command line, we also learn how we can refer to the previous result within the same line.

>1/3+1/7, fraction %

0.47619047619
10/21


## Output Formats

The internal accuracy of EMT is about 16 decimal places, which is the IEEE standard. Numbers are stored in this internal format.

But the output format of EMT can be set in a flexible way.

>longestformat; pi,

3.141592653589793

>format(10,5); pi

  3.14159


The default is defformat().

>defformat; // default


There are short operators which print ony one value. The operator "longest" will print all valid digits of a number.

>longest pi^2/2

      4.934802200544679


There is also a short operator for printing a result in fractional format. We have already used it above.

>fraction 1+1/2+1/3+1/4

25/12


Since the internal format uses a binary way to store numbers, the value 0.1 will not be represented exactly. The error adds up a bit, as you see in the following computation.

>longest 0.1+0.1+0.1+0.1+0.1+0.1+0.1+0.1+0.1+0.1-1

-1.110223024625157e-016


But with the default "longformat" you will not notice this. For convenience, the output of very small numbers is 0.

>0.1+0.1+0.1+0.1+0.1+0.1+0.1+0.1+0.1+0.1-1

0


## Units

EMT can convert and print units with a special operator. In the example, we convert light years to km.

In the following form of the command, the result is a string.

>0.45ly -> " km"

4.25732871266e+012 km


Euler assumes that all numbers are in SI (systeme international) units, i.e., meters, seconds etc. Values converted to other units should not be saved.

>d:=2km; d, d->miles

2000
1.24274238447


The print command can print a number with a specified number of digits after the comma and a specified length.

>print(pi,5,10)

   3.14159


In the following example, we compute the area of a circle with radius of 2 inches in square cm. Then we use print() to print the result.

>r:=2in; print(r^2*pi->cm^2,2,10," cm^2")

     81.07 cm^2


There is a special unit %. You can use it after each number.

>1200*119%

1428


But you can also convert.

>round(45/112,4)->" %"

40.18 %


Or try the following.

>print(45/112->%,2,unit=" %")

     40.18 %


The degree symbol (press F7 to get it) can also be used like a unit. The trigonometric functions of Euler expect the arguments in radian measure.

>sin(90°)

1


## Command Lines

Euler can spread computations over several lines (called a multi-line command). For this, connect the lines with "..." at the end of the line. You can press Ctrl+Return to continue a line in the next line, or to break a line in two at the current position.

>alpha:=72°; beta:=108°; ...
cos(alpha)*sin(beta)+cos(beta)*sin(alpha)

0


Note that all command lines execute only when you press return. To execute the commands from the start till the end of a section in the correct order, press Shift-Return. This will execute all commands between two headings or empty lines. To execute all commands, go the start of the notebook and press Ctrl-R.

Assume we set the following start value.

>x:=2;


Then we can execute the following line over and over again to get a convergence to the square root of 2.

>x:=(x+2/x)/2

1.5


Euler has a special command for such iterations.

>iterate("(x+2/x)/2",2)

1.41421356237


# Plots

EMT plots functions in a separate window. This window gets the focus only during plots. To see the window at any other time, use the tabulator key. On modern screens, you should be able to place the two windows side by side.

You can size and position the graphics window as you like. Euler will remember the screen layout. The layout will depend on the current screen resolution.

There is a special mode of EMT, where the plot appears in the text window. To see the plot, you then need to press the tabulator key.

## Plotting Functions in one Variable

Euler can plot expressions, functions or data in 2D or 3D. 2D plots are generated with plot2d, and 3D plots with plot3D.

The easiest way to plot uses expressions. Expressions are strings containing an expression in the variable "x".

>plot2d("sin(x)/x",-2pi,2pi);


Press the tabulator key to see the plot, if the windows is hidden.

Of course, EMT has functions like sinc(x) which is defined as

So this example could also have been plotted using "sinc(x)".

More functions can be added to the same plot using the parameter >add. The colors are set with "color=...". There are 16 predefined colors. But Euler can use any color with rgb(red,green,blue).

Note the : after the following plot! This inserts the current graphics into the notebook after the command. These images will be saved in PNG format, and they will be used in the HTML export.

>plot2d("1-x^2/3!+x^4/5!",color=cyan,>add):


The option >user makes an interactive plot. The user can shift the plot window with the cursor keys, and enlarge or reduce it with +/-. The space key resets to the original window, and the return key ends the plot. The mouse can be used to specify a plot range.

>plot2d("sin(x)*exp(-x)",a=-2,b=2,grid=3, ...
title="+/-, arrow keys, space or return!",>user):


The function plot2d has many more options. For details, refer to the documentation. Moreover, there is an introduction about plot2d(). See the following notebook.

## Functions in two Variables

EMT can plot beautifully in 3D too. The command plot3d requires

• an expression in "x" and "y",
• a function of two variables,
• or data matrices.

The easiest way uses an expression in the variables x and y.

>plot3d("x*y",r=2,>contour):


The features of plot3d include implicit plots. These plots show the zero set of a function in three variables.

>plot3d("x^2+y^2+4*x*z+z^3",>implicit,r=2,zoom=2.5):


The following plot is an anaglyph. To see the amazing 3D effect, you need red/cyan glasses.

>plot3d("x^2+y^3",>anaglyph,>contour,angle=30°):


Often, a spectral color scheme is used for plots. This emphasizes the heights of the function.

>plot3d("x^2*y^3-y",>spectral,>contour,zoom=3.2):


More information and examples can be found in the following notebooks. Double click to see the HTML exports.

## Plotting Data

EMT can plot data in a big variety of ways. The following is a bar plot of some random data.

>x=0:10; y=random(1,10); plot2d(x,y,>bar):


Here is a plot of data and a regression line added in one single plot.

>x=[1,2,3,4]; y=[1.2,1.8,3.2,3.9];  ...
plot2d(x,y,c=1,d=4,>points); ...
p=polyfit(x,y,1);  ...


There are also statistical plots of various kind. See the following for more details.

>p=normal(10,1000); boxplot(p):


In the following example, we generate the binomial distribution for n=20 and p=1/3. For this we use the matrix language of EMT (see below). We plot the data as connected lines, and add a plot of points on top of this.

>n=20; k=0:n; p=1/3; b=bin(n,k)*p^k*(1-p)^(n-k); ...


Here is a plot of rows of functions. The data is given in a row vector x, and a matrix y, with one function in each row. y is generated using the matrix language of EMT.

>n=10; k=(0:n)'; x=0:0.01:1; plot2d(x,bin(n,k)*x^k*(1-x)^(n-k),0,1):


# Numerical Mathematics

EMT has more numerical methods then we can mention in this introduction. Among them are procedures with infinite accuracy, as well as interval methods, which deliver guaranteed inclusions. For more information, see the following.

All these functions accept an expression in x (or in x and y) just as the plot function, or alternatively the name of a function. We demonstrate functions later in this introduction and, for the moment, use expressions instead.

Let us compute

Note that this integral cannot be evaluated exactly. So we are stuck with numerical approximations.

The simple "gauss" computes an integral using Gauss quadrature with only 10 evaluations of the function.

>gauss("exp(-x)*sin(x)/log(x)",2,3)

0.0659785778609


But there are other methods, including adaptive methods. The function integrate() will use an adaptive Gauss method.

>integrate("exp(-x)*sin(x)/log(x)",2,3)

0.0659785778609


Another frequent task is to solve equations numerically. The following uses the secant method to solve an equation for one variable. Let us solve

>solve("cos(x)-x",1)

0.739085133215


For a further example, we compute an interest rate. Assume we invest 1000$now, and get three times a return of 400$. If we discount to the current date, we have

Setting x=1/(1+i), we have to find the zero of the polynomial

between 0 and 1, and print the result. The evalpoly function evaluates such polynomials. For the solution, we use the bisection method.
For the print, we use the print command, which returns a formatted string.

>p:=[1000,-400,-400,-400];  ...
q:=bisect("evalpoly(x,p)",0,1);  ...
print((1/q-1)*100,unit="%")

      9.70%


Euler has some packages, which are not part of the core. You need to load these packages. One example is the package interest, which computes interest rates.

>load interest; rate([1000,-400,-400,-400])

9.70102574033


Of course, Euler can also compute all real and complex zeros of a polynomial p. The first zero is the real zero in [0,1].

>polysolve(p), q:=real(%[1]);

[ 0.911569+0i ,  -0.955784+1.35241i,  -0.955784-1.35241i ]


We print the result using a concatenation of two strings.

>"Rate: "|print((1/q-1)*100,unit="%")

Rate:       9.70%


As a further example, we solve

for x. To do so, we need an expression inside an expression. This can be achieved with double quotes.

>solve(''integrate("exp(-x^2/2)",0,x)'',1,y=1)

1.27554773642


# Symbolic Mathematics

The symbolic algebra program Maxima runs separately in the background as soon as you start EMT. But both system can share symbolic expressions. With a few exceptions, the syntax of symbolic expressions is the original Maxima syntax, as you find it in books about Maxima. For an introduction, see the following.

Like all computer algebra programs, Maxima has symbolic variables and an "infinite" integer arithmetic.

Symbolic expressions in Euler start with &... They can be used in other symbolic expressions. They can also be evaluated in the numerical part of Euler.

In the following example, "x" is a variable which must not have a value. This is the main difference to the numerical part of Euler, where variables can only be used if they have a value.

>&expand((1+x)^5), &factor(%)

                  5      4       3       2
x  + 5 x  + 10 x  + 10 x  + 5 x + 1

5
(x + 1)



The &... scans the following expression, passes it to Maxima and returns the result as a string. This string has a symbolic flag and will be printed as a symbolic expression. You can leave a space after the &, if you like.

>& x+x/2+y/3-x*y

                                   y   3 x
- x y + - + ---
3    2



We can define symbolic variables containing symbolic expressions, and use these variables later in other symbolic expressions.

The following defines a symbolic expression for EMT and Maxima. In EMT, the mathematical constants are denoted with capital letters, using E, I and Pi.

>fx &= x^2*exp(x)

                                 2  x
x  E



For the numerical side of EMT, a symbolic variable is just a string. The important difference to a numerical expression is that the string will always print in symbolic form, unless we force it to become a non-symbolic string.

>"String = "+fx

String = x^2*E^x


Symbolic expressions can be used just like any other expression for plotting or in all numerical algorithms which accept expressions.

>plot2d(fx,r=2):


Using the symbolic expression expr defined above, we let Maxima compute the second derivative of the expression, and plot the result.

>plot2d(&diff(fx,x,2),r=2):


Or we can use the expression for the second derivative to find the turning point

of the graph numerically in Euler.

>tp := solve(&diff(fx,x,2),-0.5)

-0.585786437627


We can also evaluate a symbolic expression numerically at any given point

An expression in the variable x can be evaluated using expression(value). This is a simple alternative to functions (see below).

>df &= diff(fx,x); df(tp)

-0.461158792007


We can ask Maxima to solve the equation

exactly for x.

>sol &= solve(diff(fx,x,2))

                 [x = - sqrt(2) - 2, x = sqrt(2) - 2]



To extract the second solution, we need the right hand side of the second element of this vector. We get a string.

>&rhs(sol[2])

                             sqrt(2) - 2



It is also possible to use the "with" command to evaluate a symbolic expression using values for variables. Then, the evaluation is done by Maxima in symbolic form. Since sol[2] is an assignment of the form x=... it can be used after "with".

The "with" statement is one of the extensions of Maxima in EMT.

>&x^2 with x=2, &x^2 with sol[2]

                                  4

2
(sqrt(2) - 2)



Some trigonometric values are known to Maxima. Note, that you can use the degree symbol in symbolic expressions too, another extension of Maxima in EMT.

>&sin(45°)

                                  1
-------
sqrt(2)



The following demonstrates the infinite integer arithmetic. We now call Maxima directly to get the 3D display of results.

To call Maxima directly start the command line with ":: ". This is necessary for the following command, since &... simplifies the result for the output, which would multiply out the factorization.

>:: factor(50!)

          47  22  12  8   4   3   2   2   2
2   3   5   7  11  13  17  19  23  29 31 37 41 43 47



The result of the factor command is a product. It can be stored to a symbolic variable, retaining the product structure. To keep the product from expanding on the output, use the tick '.

>af &= factor(243234); &'af

                                 2
2 3  13513



As we saw above, Maxima can also differentiate and integrate. In the following example, we factor the result using a flag "factor". Flags can be added with "|".

>&integrate(log(x)*x,x) | factor

                           2
x  (2 log(x) - 1)
-----------------
4



"factor" can also be used as a function.

>&factor(integrate(log(x)*x^2,x))

                           3
x  (3 log(x) - 1)
-----------------
9



## Solving Equations

Equations can be solved symbolically with "solve". We met this before.

>&solve(x^2-4*x+1=0,x)

                  [x = 2 - sqrt(3), x = sqrt(3) + 2]



The solutions can be evaluated numerically in a direct way.

>&solve(x^2-4*x+1=0,x); %()

[0.267949,  3.73205]


Maxima has a numerical arithmetic too.

>&solve(x^2-4*x+1=0,x); &float(%)

            [x = 0.26794919243112, x = 3.732050807568877]



Maxima has even a big floating point arithmetic with arbitrary precision. The default number of digits is 32.

>&solve(x^2-4*x+1=0,x); &bfloat(%)

        [x = 2.6794919243112270647255365849413b-1,
x = 3.7320508075688772935274463415059b0]



With "solve", we can find the interest rate in the problem above exactly. But the solution is not nice. In most cases, there is no exact solution at all. This justifies the numerical part of Euler.

>&solve(1000-400*x-400*x^2-400*x^3,x); x3 &= x with %[3]

           sqrt(827)   149 1/3             2              1
(--------- + ---)    - ---------------------- - -
3/2     108          sqrt(827)   149 1/3   3
4 3                  9 (--------- + ---)
3/2     108
4 3



By the way, we can print this result into a comment in Latex, simply be inserting the line "maxima: x3". For this to work, Latex must be installed properly.

We showed several Latex commands in comments already. This has always been done with a line "latex: ...". Here is another example. A line "latex: x+y=4, \quad x^2+y^2=12" yields

By the way, the following line is an empty line, which will display only, if it has the focus.

## Systems of Equations

For systems of equations, we use a vector of equations, and a vector of variables to solve for. The return value is a vector of solutions, where each solution is a vector of assignments "var=...".

We can use

 expression with [var1=value1,var2=value2, ...]


to insert solutions into an expression. In the following example, we insert all variables according to the first solution vector.

>&solve([x+y=4,x^2+y^2=12],[x,y]), &x*y with %[1], &expand(%)

        [[x = 2 - sqrt(2), y = sqrt(2) + 2],
[x = sqrt(2) + 2, y = 2 - sqrt(2)]]

(2 - sqrt(2)) (sqrt(2) + 2)

2



There are some numerical functions of EMT which take the help of Maxima. The documentation is the following section of the reference.

An example is the Newton method, which computes the derivative of the expression with Maxima. In the example, we solve x^x=2, and check the result.

>x0 := mxmnewton("x^x",1,y=2), x0^x0-2

1.55961046946
0


However, this is only an abbreviation for the following command.

>newton(&x^x,&diff(x^x,x),1,y=2)

1.55961046946


For a more thorough introduction to Maxima, see the following.

As a further example, we compute the critical points of a function exactly, and check the second derivative in the first point.

>expr &= (x^2+x)*exp(x);  ...
&solve(diff(expr,x),x), &ratsimp(diff(expr,x,2) with %[1])

                      - sqrt(5) - 3      sqrt(5) - 3
[x = -------------, x = -----------]
2                 2

sqrt(5)
- ------- - 3/2
2
- sqrt(5) E



Indeed, there is a point of maximal value.

>plot2d(expr,-4,0):


# Vectors and Matrices

Matrices and vectors can be used in Euler for linear algebra. But often they are used for tables of values.

A matrix

is defined row by row.

>A := [2,1,3; 1,2,1; 3,1,2]

            2             1             3
1             2             1
3             1             2


In EMT, the determinant can be computed numerically. This works very fast, even for large matrices.

>det(A)

-8


In symbolic expressions, determinants can be computed for symbolic matrices.

Matrices in Maxima can be defined just as in Euler. Note that this is an extension to Maxima in EMT. In the default Maxima, you need to use the function matrix(row,row,...).

>&[a,1,1;1,b,a;1,1,1], &factor(determinant(%))

                             [ a  1  1 ]
[         ]
[ 1  b  a ]
[         ]
[ 1  1  1 ]

(a - 1) (b - a)



The eigenvalues of A are always complex values in Euler. But we can make them real, if we know, that they are indeed real values.

>real(eigenvalues(A))

[5.56155,  -1,  1.43845]


In Maxima, the result is symbolic, including the multiplicities.

>&eigenvalues([2,1,3;1,2,1;3,1,2])

              7 - sqrt(17)  sqrt(17) + 7
[[------------, ------------, - 1], [1, 1, 1]]
2             2



We defined the matrix A using := as a numerical value for Euler. This numerical matrix will not be known to Maxima.

If we wish to define a numerical value for Maxima too, we use &:=.

>A &:= [2,1,3; 1,2,1; 3,1,2]

            2             1             3
1             2             1
3             1             2


The difference to &= is that in Euler the matrix is not an expression, which needs to evaluated, but a value.

Let us compute the inverse of the matrix A. The flag "detout" keeps the determinant as a multiple of the result. Since the 2D output immediately multiplies the determinant inside the matrix, we use the direct input for Maxima.

>:: invert(A)|detout

                           [  3    1   - 5 ]
[               ]
[  1   - 5   1  ]
[               ]
[ - 5   1    3  ]
- -----------------
8



The matrix A is also known in numerical commands, since we defined it with "&:=".

>invert(A)

       -0.375        -0.125         0.625
-0.125         0.625        -0.125
0.625        -0.125        -0.375


We could print this in fractional form too.

>fraction invert(A)

     -3/8      -1/8       5/8
-1/8       5/8      -1/8
5/8      -1/8      -3/8


We can use any numerical value of Euler in Maxima, using the "@..." syntax, even if we did not define the value for Maxima using "&=" or "&:=".

>M := [1,2;3,4]; &invert(@M)

                             [ - 2   1  ]
[          ]
[  3     1 ]
[  -   - - ]
[  2     2 ]



A vector is simply a matrix with one row or column in Euler.

>b:=[1;1;1]

            1
1
1


To solve Ax=b, we use "A\b".

>x:=A\b; fracprint(x)

      1/8
3/8
1/8


Let us check the result!

The matrix product is computed with ".". Do not use "*" for this purpose, since this multiplies the matrices element-wise!

>A.x

            1
1
1


# The Matrix Language

The main principle of the matrix language is that all operators or functions are evaluated element for element.

>sin([0,pi,2pi]), cos([0,pi,2pi])

[0,  0,  0]
[1,  -1,  1]


Thus we can add or multiply vectors easily.

>b=[1,2,3], x=[5,6,7], ...
2*b+4*x

[1,  2,  3]
[5,  6,  7]
[22,  28,  34]


One purpose of the matrix language is to make tables of functions without having to program loops.

In the following example, we generate a vector containing the 101 numbers 0, 0.01 etc. to 1. Then we square all elements of the vector, and sum the result. Multiplied by the step size 0.01 this is an approximation of the Riemann integral.

>t:=0:0.01:1; sum(t^2)*0.01

0.33835


Tables of function can also be used in plots.

>plot2d(t,t^3-t):


If vectors and matrices are used in one operation, the vector is blown up to a matrix in a natural way.

In the following example, the vector 1:10 is multiplied by the transposed vector of itself. The result is the matrix containing the elements i*j. For the output, we use a more narrow format.

>format(6,0); (1:10)'*(1:10), longformat;

    1     2     3     4     5     6     7     8     9    10
2     4     6     8    10    12    14    16    18    20
3     6     9    12    15    18    21    24    27    30
4     8    12    16    20    24    28    32    36    40
5    10    15    20    25    30    35    40    45    50
6    12    18    24    30    36    42    48    54    60
7    14    21    28    35    42    49    56    63    70
8    16    24    32    40    48    56    64    72    80
9    18    27    36    45    54    63    72    81    90
10    20    30    40    50    60    70    80    90   100


In the same manner, we can plot systems of functions. If the parameter is a column vector, the result of the function expression will be a matrix of function values, with one function for each parameter in each row.

>n=(1:10)'; plot2d("x^n",0,1):


For a final example, we generate a large matrix with 2 in the diagonal and 1 in the two adjacent diagonals, and compute all eigenvalues of the matrix.

Here is an example of such a matrix.

>n=5; fracprint(setdiag(setdiag(diag(n,n,0,2),-1,1),1,1))

        2         1         0         0         0
1         2         1         0         0
0         1         2         1         0
0         0         1         2         1
0         0         0         1         2


The eigenvalues of such a matrix can be computed easily.

>n=10; sort(real(eigenvalues(setdiag(setdiag(diag(n,n,0,2),-1,1),1,1))))

[0.081014052771,  0.317492934338,  0.690278532109,  1.169169974,
1.71537032345,  2.28462967655,  2.830830026,  3.30972146789,
3.68250706566,  3.91898594723]


The eigenvalues of this matrix are well known.

>2*(cos(pi*(n:-1:1)/(n+1))+1)

[0.081014052771,  0.317492934338,  0.690278532109,  1.169169974,
1.71537032345,  2.28462967655,  2.830830026,  3.30972146789,
3.68250706566,  3.91898594723]


# Programming Euler

The user can add functions to EMT. In fact, a big part of Euler is implemented using functions in the Euler programming language.

The most basic way to define a function is the one-line function.

>function f(x) := x^x


Note that this function will work for vectors automatically, since expressions work for vectors.

>f(0:5)

[1,  1,  4,  27,  256,  3125]


We can also define symbolic functions. These functions contain symbolic expressions, and can be used in all symbolic or numerical expressions.

>function f(x) &= x^3-x

                                 3
x  - x



Euler can plot functions simply by name.

>plot2d("f",0,2):


Of course, these function can be used in expressions for plot2d as usual.

>plot2d("f(x)/(x^3+1)",-1,1):


If you wish to include a function definition of a one-line function into a multi-line statement, you need to finish it with a semicolon in front of the "...".

>function g(x) &= x+exp(-x^2);  ...
plot2d("g",-2,2):


A symbolic function can be used in other symbolic expressions.

>&diff(f(x),x)

                                  2
3 x  - 1



A symbolic function is evaluated before its definition, as we see in the following examples. There are also purely symbolic functions, which are evaluated when they are called, but we do not cover this here.

>function g(x) &= diff(f(x),x)

                                  2
3 x  - 1



We can use a symbolic function in Euler's numerical solvers, or in Maxima's exact solver. The numerical result will depend in the starting value for the approximation.

>solve("g",0.6), &solve(g(x)), %()

0.57735026919

1            1
[x = - -------, x = -------]
sqrt(3)      sqrt(3)

[-0.57735026919,  0.57735026919]


More complex functions have to be entered in several lines. To make this easier, there is an internal editor, which can be started with F9. Alternatively, the function can be defined in a separate file, which must be loaded with the "load" command.

The following example is a function with branches. As you see, the programming language is an extended Basic. Parameters can be restricted to types of values. This avoids confusing errors. We have used this in the following example.

Moreover, parameters can have default values. In the example, the default value for "n" is 2.

Such a function would no longer work for vectors "x". To make it work, we add the keyword "map". This forces the function to be applied for each element of a vector or matrix. This is called "vectorization" of a function.

>function map f (x:number, a:number, n:integer=2) ...
if x<a then return 0;
else return (x-a)^n
endif;
endfunction


The function can be used in an expression for the plot2d command as follows. We add the branch point of the function to the plot.

>plot2d("f(x,1)",r=2); plot2d(1,0,>points,>add):


Functions with a vector valued parameter can also be defined in the following form.

>function f([x,y]) &= [x+y-1,x^2+y^2-0.8]

                                   2    2
[y + x - 1, y  + x  - 0.8]



Then, the image of a vector is a vector.

>f([0.1,0.9])

[0,  0.02]


But the function can also be used with two scalar parameters.

>f(0.1,0.9)

[0,  0.02]


EMT has several methods to solve a system of several variables. One of these methods is the Broyden algorithm. We solve

>x:=broyden("f",[1,2]), "Error: "|norm(f(x))

[0.112701665379,  0.887298334621]
Error: 0


In this case, Maxima can find the solution exactly.

>&solve([x+y=1,x^2+y^2=4/5])[2], %()

                  sqrt(15) + 5      5 - sqrt(3) sqrt(5)
[y = ------------, x = -------------------]
10                   10

[0.887298334621,  0.112701665379]


There is an introduction into programming in EMT. There are many numerical and symbolic examples.

For a final example, we minimize a function of two variables using the Nelder-Mead algorithm.

>function f([x,y]) := exp(x*y-y)+x^2+y^2
>nelder("f",[1,1])

[-0.122196931313,  0.370308545614]


# Further Features of Euler

Euler is like a Swiss army knife. It covers a big range of problems, much more than we could mention here.

Euler can use complex numbers, both symbolically and numerically.

>(1+I)^2, &expand((1+I)^2)

0+2i

2 I



Even plots of complex functions are possible.

In the example, we plot the image of the unit circle under the mapping E^z.

>t:=linspace(0,2pi,100); r:=linspace(0,1,25);  z:=r*exp(I*t'); ...
plot2d(exp(z),grid=1,cgrid=10):


See the following for complex numbers in Euler.

Euler has an interval arithmetic. This is useful to estimate the maximal error of a computation.

Assume a tower is 25.1km away and appears at an angle of 5.2°. How high is the tower? The parameters are defined as intervals, and the output is an interval containing the possible values. The degree symbol can be entered with F7, and the plusminus symbol with F8.

>d:=(25.1±0.05)km; a:=5.2°±0.05°; d*tan(a)

~2257,2311~


There are interval algorithms which return verified results; i.e., the computer guarantees a unique solution within the bounds.

An example is the interval Newton method. We solve x^x=2 again.

>mxminewton("x^x",~1,2~,y=2)

~1.559610469462368,1.559610469462371~


Euler has an exact scalar product, using a long accumulator. This allows to solve badly conditioned linear systems.

>A:=hilbert(10); x:=ones(10,1); b:=A.x; xlgs(A,b)

                  1
1
1
1
1
1
1
1
1
1


Using expressions, Euler provides a lot of service functions in a simple way.

An example is the function "sequence", which computes a recursive sequence of numbers or vectors. The used does not have to use loops for this.

Let us generate the Fibonacci sequence.

>sequence("x[n-2]+x[n-1]",[1,1],10)

[1,  1,  2,  3,  5,  8,  13,  21,  34,  55]


An alternative would be a loop.

>v=[1,1]; for i=1 to 8; v=v|(v[-2]+v[-1]); end; v,

[1,  1,  2,  3,  5,  8,  13,  21,  34,  55]


Differential equations or systems of differential equations can be solved numerically in Euler, and exactly in Maxima.

Let us solve y'=-x*exp(y) with the initial value y(0)=1. This can be solved exactly in Maxima. The solution is given in implicit form only.

>sol &= ode2('diff(y,x)=-x*exp(y),y,x)

                                    2
- y   x
E    = -- + %c
2



We can solve for %c using the initial condition.

>solic &= ic1(sol,x=0,y=1)

                                - 1     2
- y   E    (E x  + 2)
E    = ---------------
2



Now we can solve for "y", and define a function for the solution.

>function g(x) &= y with solve(solic,y)

                                  2 E
log(--------)
2
E x  + 2



Let us plot it.

>plot2d(&g(x),0,10):


EMT gets the same result numerically.

>t:=0:0.01:10; s:=ode("-x*exp(y)",t,1); plot2d(t,s):


As a further example, we compute the solution of the differential equation

in [0,2].

>x=0:0.01:2; plot2d(x,ode("sqrt(y*x)-sin(pi*x)",x,1)):


# Configure Euler

There is not much need to configure anything in EMT, since the defaults are designed for the best experience.

However, you can make your life easier by installing and selecting a good font for the text window. I use the free font "Source Code Pro" at 10pt.

Also, make sure ClearType is enabled in the screen settings of Windows.

>O=2; l=O*1000*1i; // might be confusing with the default font


You can select a larger or smaller font for the graphics window too. This might be necessary, if you need very small prints. If you do so, restart Euler.

The default screen font for graphics is good for 10-20cm prints or screen sizes. The first of the following plots clearly needs a bigger font and fatter lines too.

>plot2d("x^2"); insimg(10); insimg(25);


Here is the same small graphics with a larger font. Note that we have to reset the font to the default after the insimg() command.

>setfont(10pt,5cm); plot2d("x^2"); insimg(10); setfont();


If you want to include formulas, you should install Latex. There is a section in the HTML documentation devoted to this.

The following line will run only if you have Latex properly installed.

>\$factor(diff(x^x,x,2))


# Help in EMT

EMT comes with a complete reference, a documentation in web pages, and many examples.

Jut mark a word, a number, or a sequence of symbols in a line (like "simpson" in the following command) with a double click.

The help window will open and show the help of the command sinpson().

Or go with the cursor along the word "simpson", and watch the status line. Once you pass the opening bracket you can see the parameters there. If you press F1 now, the browser will open with the index at "simpson".

>simpson("x^x",1,2)

2.05044623596


To list all variables (including system variables) containing a specific string use the following command. Omitting the strings lists all variables defined by the user.

>listvar x

fx                  x^2*E^x
defaulttextcolor    52042266
DifMatrix           Type: Real Matrix (5x11)
x3                  (sqrt(827)/(4*3^(3/2))+149/108)^ ...
x0                  1.55961046946237
expr                (x^2+x)*E^x
x                   Type: Real Matrix (1x201)


For own functions, every user can add a help line. See the introduction into programming for more information. Here is an example for a one-line function.

>function fdamped(x) := exp(-x^2)*cos(x) // Damped oscillation function


Now the status line will work for this function, and the help command will print the help line.

>help fdamped

fdamped is an Euler function.

function fdamped (x)

Entered from command line.

Damped oscillation function



# Finally

Finally, I wish you much success with EMT.

If you want to get in contact with me or other users, have a look at the homepage of Euler at

Best wishes
René Grothmann

Euler Home