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. Maxima is a mature, and very rich open source program. Some other programs (Latex, Povray, Tiny C Compiler) can be used from Euler too. This is an introduction notebook for Euler. For more introductions and examples, or for the reference, refer to the following pages. Introduction Notebooks Example Notebooks Reference You can double click on these links in Euler and the browser will open the HTML page. You can also double click on any command to open the reference for the command. Try double clicking the sqrt command below in the Euler program. The reference will open and you can see either the help for the Maxima command or the Euler command. You can copy and paste the examples for the Euler command into an Euler notebook. Please enter the following commands with the return key. The cursor can be at any position in the command line. You can go back to previous commands with the arrow keys. If you read this in the browser, load the introduction into Euler to execute the commands, or copy the commands from the browser to Euler.
>sqrt(sin(10°)/cos(20°))
0.429875017772
Euler knows the usual mathematical functions. As you see, trigonometric functions work in radians. 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. Multiple commands in one line are separated with "," or ";". The semicolon supresses 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
Euler can convert and print units. 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+012km
Euler assumes that all numbers are in the IS (international standard) units, i.e., meters, seconds etc. Values converted to other units should not be saved.
>d=2km; d, d->miles
2000 1.24274238447
Units In numerical computations, 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 example, we also learn, how to refer to the previous result within the same line.
>1/3+1/7, frac(%)
0.47619047619 10/21
The output format of Euler can be set in a flexible way.
>longestformat; pi,
3.141592653589793
>shortestformat; pi
3.14
The default is longformat.
>longformat; // default
The internal accuracy of Euler is about 16 decimal places, which is the IEEE standard. Since this is 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.
>longestformat; 0.1+0.1+0.1+0.1+0.1+0.1+0.1+0.1+0.1+0.1-1
-1.110223024625157e-016
Usually you will not notice this with the default format.
>longformat; 0.1+0.1+0.1+0.1+0.1+0.1+0.1+0.1+0.1+0.1-1
0
Euler plots functions in a separate window. This window get the focus only during plots. To see the window at any other time, use the tabulator key. On modern wide screens, you might be able to place the two windows side by side. There is a special mode of Euler, where the plot appears in the text window. To see the plot, you need to press the tabulator key. 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, Euler 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=true" (or ">add"). The colors are set with "color=...". There are 16 predefined colors. But Euler can use any color with rgb(red,green,blue). To see the names of the 16 predefined colors, double click on plot2d. The plot can be inserted into the notebook window. For this, end the command line with ":" (or use the command "insimg;"). These images will be saved with the notebook in PNG format, and they will be used in the HTML export of the notebook.
>plot2d("1-x^2/3!+x^4/5!",color=cyan,>add):
The option "user=true" (or simply ">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 following command is too long to fit in the default width of the text window. It is spread over two lines with "...". The command can be executed from either line.
>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, use "help plot2d", refer to the documentation. Moreover, there is an introduction notebook about plot2d. Euler can plot 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 expressions.
>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. We can also set the >insimg option in plot2d and plot3d, instead of calling "insimg;" later.
>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.5):
More information and examples can be found in the following notebooks. Double click to see the HTML export of these notebooks. 02 - Introduction to 2D Graphics 03 - Introduction to 3D Graphics 00 - Overview of Plots in Euler Finally, here is a plot of data in 2D. 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 Euler.
>n=10; k=(0:n)'; x=0:0.01:1; plot2d(x,bin(n,k)*x^k*(1-x)^(n-k),0,1):
Euler 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. 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 "integrate" computes an integral using Gauß quadrature with 10 sub-intervals, i.e., 100 evaluations of the function.
>integrate("exp(-x)*sin(x)/log(x)",2,3)
0.0659785778609
The default method (0) is Gauß integration with 10 subintervals. But it is possible to use an adaptive Runge method (1) or the LSODA algorithm (2).
>integrate("exp(-x)*sin(x)/log(x)",2,3,method=1)
0.0659785778609
Usually, the very quick and accurate Gauß quadrature with only one sub-interval is sufficient. It takes only 10 function evaluations.
>gauss("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. 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. The following command are connected by ... to a multi-line command. You can edit all three lines with the internal editor F9.
>p:=[1000,-400,-400,-400]; ... q:=bisect("evalpoly(x,p)",0,1); ... print((1/q-1)*100,unit="%")
9.70%
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.911568504717+0i -0.955784252358+1.35240604348i -0.955784252358-1.35240604348i ]
We print it using a concetanation of two strings.
>"Rate: "|print((1/q-1)*100,unit="%")
Rate: 9.70%
For more information on numerical methods, see the following introduction notebooks. 06 - Introduction to Numerical Analysis 08 - Introduction to Interval Computation 14 - Introduction to Exact Computation 17 - Introduction to Optimization 19 - Introduction to Large Systems As a further example, we solve
for x.
>solve(''integrate("exp(-x^2/2)",0,x)'',1,y=1)
1.27554773642
The symbolic algebra program Maxima runs separately in the background as soon as you start Euler. 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. Like all computer algebra programs, Maxima has symbolic variables and an "infinite" integer arithmetic. Symbolic expressions in Euler start with &... 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)
We can define symbolic variables containing symbolic expressions, and use these variables later in other symbolic expressions. The following defines a symbolic expression for Euler and Maxima. In Euler, the mathematical constants are denoted with capital letters, using E, I and Pi.
>expr &= x^2*exp(x)
2 x x E
For Euler, 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 = "+expr, expr,
String = x^2*E^x 2 x x E
Symbolic expressions can be used just like any other expression for plotting. After all, it is just a special string containing the expression.
>plot2d(expr,r=2):
Using symbolic expression expr defined above, we let Maxima compute the second derivative of the expression, and plot the result.
>plot2d(&diff(expr,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(expr,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(expr,x); df(tp)
-0.461158792007
We can ask Maxima to solve the equation
exactly for x. The third solution is meaningless.
>sol &= solve(diff(expr,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 Euler.
>&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.
>&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
Equations can be solved 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 also be evaluated numerically in a direct way.
>&solve(x^2-4*x+1=0,x); %()
[ 0.267949192431 3.73205080757 ]
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 solve the interest rate problem above exactly. But the solution is not nice. Moreover, often 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 insertng 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
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 Euler which take the help of Maxima. 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 notebook 10 - Introduction to Maxima As a further example, we compute the critical points of a function exactly, and check the second derivative in the first point.
>&solve(diff((x^2+x)*exp(x),x)), &ratsimp(diff((x^2+x)*exp(x),x,2) with %[1])
- sqrt(5) - 3 sqrt(5) - 3 [x = -------------, x = -----------] 2 2 sqrt(5) - ------- - 3/2 2 - sqrt(5) E
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 Euler, the determinant is 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 Euler. In 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 must be real.
>real(eigenvalues(A))
[ -1 1.43844718719 5.56155281281 ]
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
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.
>fracprint(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 elementwise!
>A.x
1 1 1
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.
>2*b+4*x
2.5 3.5 2.5
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 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 more information about the matrix language of Euler and about linear algebra in Euler consult the following notebooks. 01 - Introduction to the Matrix Language 04 - Introduction to Linear Algebra 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
Here the eigenvalues of a larger matrix.
>n=20; sort(real(eigenvalues(setdiag(setdiag(diag(n,n,0,2),-1,1),1,1))))
[ 0.0223383475497 0.0888543884275 0.198062264195 0.347522451368 0.53389625634 0.753020396314 0.999999999591 1.26931795524 1.55495810042 1.85054002918 2.14945892716 2.44504794981 2.73065823859 3.00007468976 3.24679423854 3.46646405491 3.6519455662 3.80251176546 3.91073948159 3.97779489934 ]
The user can add functions to Euler and Maxima. 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,<margin):
Of course, these function can be used in expressions for plot2d as usual.
>plot2d("f(x)/(x^3+1)",-1,1,<margin):
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",-4,4):
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.
>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 ]
Euler has several methods to compute a function of several variables. One of these methods is the Broyden algorithm.
>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 notebook into programming in Euler. There are many numerical and symbolic examples in other notebooks. 05 - Introduction to Programming 06 - Introduction to Numerical Analysis 10 - Introduction to Maxima 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 ]
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):
See the following notebook for complex numbers in Euler. 07 - Introduction to Complex Numbers 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~
See the following notebook for more information about the interval methods of Euler. 08 - Introduction to Interval Computation 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):
Euler gets the same result numerically.
>t:=0:0.01:10; s:=ode("-x*exp(y)",t,1); plot(t,s):
For more information about differential equations in Euler, see one of the following notebooks. 11 - Introduction to Differential Equations 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)):
There is not much need to configure anything in Euler, 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 Notebook window. I use the free font "Source Code Pro" at 10pt. Here is a screen dump of Euler with this font.
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);
If you want to include formulas, you should install Latex. There is a section in the HTML documentation devoted to this.
>$factor(diff(x^x,x,2))
Euler 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 browser will open in the reference, positioned at the item "simpson". Press the link in the browser to go to the function "simpson". 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
>listvar
x3 (sqrt(827)/(4*3^(3/2))+149/108)^ ... g 9.81 t Type: Real Matrix (1x1001) d ~25050,25150~ n 20 k Type: Real Matrix (11x1) x Type: Real Matrix (1x201) p Type: Real Matrix (1x4) q 0.911568504716715 expr x^2*E^x tp -0.585786437626905 df x^2*E^x+2*x*E^x sol E^-y = x^2/2+%c af 2*3^2*13513 x0 1.55961046946237 A Type: Real Matrix (10x10) M Type: Real Matrix (2x2) b Type: Real Matrix (10x1) r Type: Real Matrix (1x26) z Type: Complex Matrix (101x26) a ~0.089884456477708,0.0916297857297023~ v Type: Real Matrix (1x10) i 9 solic E^-y = E^-1*(E*x^2+2)/2 s Type: Real Matrix (1x1001) O 2 l 0+2000i
In the program, there is the function "help". This function does also print examples.
>help evalpoly;
evalpoly is an Euler function. function evalpoly (t: numerical, p: vector) Function in file : util evaluates a polynomial p in t. Polynomials are stored as a row vector with the constant coefficient in front. The function works for complex polynomials too. Search Maxima for help:
Note, that many examples and commands can be accessed through the menu. Also observe the status line, where help for the current command is displayed. The function "mxmhelp" reads the internal help of Maxima, and returns the relevant information.
>mxmhelp remvalue
-- Function: remvalue (<name_1>, ..., <name_n>) -- Function: remvalue (all) Removes the values of user variables <name_1>, ..., <name_n> (which can be subscripted) from the system. `remvalue (all)' removes the values of all variables in `values', the list of all variables given names by the user (as opposed to those which are automatically assigned by Maxima). See also `values'.
Finally, I wish you much success with Euler. If you want to get in contact with me or other users, have a look into the Forum at Sourceforge or the Wiki. The homepage of Euler is http://euler.rene-grothmann.de/ Best wishes René Grothmann