Introduction to (wx)Maxima
A Computer Algebra System (CAS) is a software program that facilitates symbolic mathematics. The core functionality of a CAS is manipulation of mathematical expressions in symbolic form, rather than merely in numerical form, i.e. as numbers. The program Maxima has the capability of manipulating numerical entities quite well, but it is not limited strictly to manipulations of that kind. The Maxima manual gives a short historical view on the origins of Maxima:
"Maxima is a CAS, derived from the Macsyma (MAC's SYmbolic MAnipulation) system, developed at MIT (Massachusetts Institute of Technology) in the years 1968 through 1982 as a part of the MAC project (Machine Aided Cognition). MIT turned over a copy of the Macsyma source code to the Department of Energy in 1982; that version is now known as DOE Macsyma. A copy of DOE Macsyma was maintained by Professor William F. Schelter of the University of Texas from 1982 until his death in 2001. In 1998, Schelter obtained permission from the Department of Energy to release the DOE Macsyma source code under the GNU Public License, and in 2000 he initiated the Maxima project at SourceForge to maintain and develop DOE Macsyma, now called Maxima."
Maxima is written in Common Lisp ([List processing], see http://en.wikipedia.org/wiki/Lisp_(programming_language)) and runs on different platforms such as Mac OS X, Unix and GNU/Linux as well as under Microsoft Windows. Todays version is maintained by an independent group of users and developers (see http://sourceforge.net/projects/maxima/). Since Maxima is distributed under the GNU-GLP license, it is a free and open source CAS.
In this document we describe the Windows implementation of Maxima and wxMaxima (using the versions Maxima 5.27.0 and wxMaxima 12.04.0). The Windows executable (see http://sourceforge.net/projects/maxima/files/), not only installs the kernel but also a collection of packages that simplify the working environment. The outcome includes a text console (MSDOS mode) and two graphical environments: xMaxima (with permanent help on screen, but only useful in command mode) and wxMaxima. This last is the most advisable one, since it allows to work in screen mode, incorporates a text editor and includes a wide collection of displayable menus as well as shortcuts and buttons to do a lot of mathematical computations without using commands. Besides, two modules of graphical representation are included: gnuplot and openmath.
This introduction is based on information available using the links on http://maxima.sourceforge.net/documentation.html , http://andrejv.github.com/wxmaxima/help.html , http://statmath.wu.ac.at/~leydold/maxima/ , and http://www.time2010.uma.es/Proceedings/Papers/A043_Paper.pdf, [an article in the Proceedings of TIME 2010 (Technology and its Integration into Mathematics Education)] Download and study the examples in http://andrejv.github.com/wxmaxima/tutorials/10minute.zip , http://andrejv.github.com/wxmaxima/tutorials/wxmaxima.zip , http://statmath.wu.ac.at/~leydold/maxima/MaximaSkript.pdf . You can also find installation information and more at the site of Paul Lutus http://arachnoid.com/maxima/installing_testing.html .
Maxima is a CAS (Computer Algebra System) similar to systems like Mathematica, Maple and others. Maxima, however, is a commandline application, which makes it harder to use than its younger cousins. Here is where wxMaxima comes in - it's a GUI (Graphical User Interface) for Maxima, made to make using Maxima simpler and more enjoyable. wxMaxima is developed by Andrej Vodopivec, University of Ljubljana, Slovenia.
Figure 1: The wxMaxima screen
Unlike 'commandline Maxima', which works in a simple input-output manner, wxMaxima introduces the concept of a live mathematical document, in which you mix text, calculations and plots. Each wxMaxima document consists of a number of so called 'cells'. Cells are the basic building blocks of a wxMaxima document. Each cell has a bracket on the left border of the document, indicating where the cell begins and ends. Cells are of different types, e.g. a 'title cell', a 'text cell', ... The most important cell type is an 'input cell'. An input cell holds Maxima code and can be evaluated with Shift+Enter. The code entered in this cell will be sent to Maxima when you press Shift+Enter. Before wxMaxima sends code to Maxima, it checks if the contents of an input cell ends with a ';' or a '$' - if it doesn't, wxMaxima adds a ';' at the end. Maxima requires that lines end with either ';' or '$'. A '$' means the output will be internally executed, but not be shown on screen.
Let's start with some simple calculation examples! Below is an input cell with a simple addition. Place the cursor in it and press Shift+Enter to evaluate it.
-->
1+20;
Remember: you have to use Shift+Enter to evaluate a cell in wxMaxima!By default Shift+Enter is used to evaluate commands, while Enter is used for multiline input. This behaviour can be changed in 'Edit > Configure' dialog by checking 'Enter evaluates cells'. This switches the roles of these two key commands. Any output wxMaxima gets from Maxima will be attached into the output part of the input cell. Input and output will be numbered by Maxima’s console as respectively (%i#) and (%o#).
You can also use variables:
x+x;
In this respect it is important to know that the use of '*' is required for multiplication. Refer to the following two examples. Moreover variable (and other) names are case sensitive.
x+2x;
x+2*x;
x+2*X;
You can send multiple "lines" to Maxima:
sqrt(2 * %pi); float(%);
We use 'sqrt' for the function square root. To type the constant "pi" you use '%pi'. If you installed the proper font, Greek symbols can be shown. See http://arachnoid.com/maxima/installing_testing.html or http://andrejv.github.com/wxmaxima/help.html . To test the ability of wxMaxima to render correctly, type examples of Greek characters in wxMaxima using this notation: %Omega; %omega; The expression "float(%);" contains the "%" symbol and "float". This symbol "%" always holds the result of the last evaluated line (this is not necessarily the cell immediately preceding). "float" refers to the numerical representation of the result. wxMaxima always uses exact calculations so sin(%pi) will evaluate to 0 but sin(3) will not be simplified. In order to get a decimal approximation for sin(3) there are several techniques that can be used: 1) Right-click on the output expression and choose "To Float" from the menu. 2) Enter float(%) in the Input box. Note that % refers to the previously entered expression. 3) Use decimal numbers such as 3.0 instead of 3. Note also that the result of "1/3" and "1.0/3.0" differ. That's because Maxima, unlike numerical matrix packages (Matlab etc.), tries to keep calculations precise - it does not evaluate expressions like 1/3 or sqrt(2) unless asked to. In "1.0/3.0" we used floating point numbers, so Maxima didn't leave the expression unevaluated. Numbered symbols "%o1", "%o2" ... hold the results as they appear when input cells are evaluated. It is possible to refer to the output by referencing using (%o#). When saving a document as a wxMaxima document, extension "wxm", and opening it later, only the input cells are shown. You can use the menu option "Cell > Evaluate all cells" to evaluate all of them. It is possible the numbering of output cells is different after working with the document, so referencing by (%o#) must be used carefully.
Figure 2: Cell > Evaluate all cells
%Omega;
%omega;
sin(3); float(%);
sin(3),numer;
sin(3.0);
1/3 ; 1.0/3.0;
Another option is to select the Numeric menu on the top tool bar and then selecting the "Toggle numeric output" to have all output numerically approximated as a floating point number. !!!! To end this mode select the menu again and choose the numeric mode option again. !!!!
Here is a list of common constants in Maxima, which you should be aware of: %e : Euler's number %pi : the number pi inf : real positive infinity minf or -inf : real minus infinity %i : complex imaginary unit infinity : complex infinity
It is possible to simplify using e.g. "ratsimp":
(a+b)^2;
ratsimp((a+b)^2);
The preceding could more easily be found by using "expand":
expand((a+b)^2);
As you see, Maxima ordens variables in reverse lexicographical order. This ordering can be changed by using ordergreat or orderless, but as you notice in the following this is not the case for products. Note: to get help on any function, just click on the function name and press F1. Try it on ordergreat below.
ordergreat(a,b);
Sometimes the output is rather long:
expand((a+b)^20);
You can hide the output by clicking into the empty triangle at the top of the bracket of the input cell above. The output can be shown again by clicking again into the triangle. A full triangle indicates that the cell's output is hidden.
Sometimes Maxima needs additional information to evaluate an expression and asks us a question. A cursor appears automatically, indicating you need to answer a question. Write an answer below the cell and send it to Maxima with Shift+Enter. Below is an integral with a question. Note: instead of answering with "positive;", you can only type "p".
integrate( 1 / (x^2 + a), x);
We can also inform Maxima beforehand using the function "assume". To revert an assumption, use "forget". (Remember: to get help on any function, just click on the function name and press F1. Try it.)
assume(a > 0)$ integrate( 1 / (x^2 + a), x); forget(a > 0)$
Editing cells is easy - to modify the contents of a cell, click into it. A cursor should appear and the left cell bracket should turn red, to indicate that the cell is being edited. Note however that once you move the cursor past the beginning, a horizontal line appears between cells. Think of this line as a horizontal cursor. Pressing any key will insert a new input cell, while pressing ShiftT+UP/DOWN will select cells in that direction. Activating the horizontal cursor is also possible by clicking between cells; click-dragging will result in a cell selection.
When you have a selection of cells, pressing backspace or delete key will delete the selection. You can also cut, copy and paste cells using menu commands.
When the horizontal cursor is active, typing will result in a new input cell. If you want to insert a cell of some other type, go to the Cell menu or use the respective key shortcut.
Figure 3: Part of the Cell menu
Important =========You can use extra spaces or more lines to make your input more readable! E.g. expand((a+b)^2); is the same as expand( (a + b)^2 );
When you're satisfied with the document you've created, save it using File > Save menu command (or Ctrl+S key command). By default the extension is wxm. Note that the output parts of input cells will not be saved. When you load your document you can evaluate all cells by the 'Cell > Evaluate all cells' menu command (as mentioned above) or respective key command. When you save a document as 'wxMaxima XML document', not only your input and text commentaries, but also the outputs of your calculations are saved. Moreover, you can also insert pictures in such a wxmx document.
You can solve equations using solve:
solve(3*x+2=0, x);
The brackets [] in the output refer to the fact that Maxima gives this result as a "list". A list is any ordered array of items. In Maxima , lists are enclosed in a pair of square brackets [ ] , and the items in a list are separated by commas. If you do not use "=" in the command solve, Maxima assumes you mean "=0".
solve(x^2-4,x);
solve(x^2-4=5,x);
solve(a*x^2 + b*x + c = 0, x);
solve([x+2*y=5,3*x-y=1], [x,y]);
It is possible to assign a label to e.g. equations or an output. Maxima uses some nonintuitive syntax for assigning a value to a label. Here are the rules: Use ":" to assign a value to a variable: a : 3;, a : b; etc. Use "=" to compare values for equality: a = 3;,a = b; etc., also "<" (less than),">" (greater than) and "#" (unequal) Use ":=" to define a function: f(x) := x^2; When an expression has been assigned to some variable, then it remains persistent until it is killed (or Maxima is stopped). Use "kill(name);" to erase a previous assignment of a variable or function: kill(a);, kill(f); Use "kill(all);" to erase all assignments.
eq1: x+2*y=5; eq2: 3*x-y=1; solve([eq1,eq2], [x,y]);
kill(all);
a:3; b:100; a+b;
You can compare expressions or numbers:
is(a=b);
is(a<b);
As mentioned above, Maxima gives the output of e.g. solve as a "list" (see the Maxima manual, 5. Data Types and Structure). If you label this output, you can access the list by way of an index:
sol: solve(x^2-4=0,x);
sol[1];
sol[2];
If you want to use this output, you can use the function ev():
ev(x^2-4,sol[2]);
subst;
You can also extract the right hand side of equations using rhs():
rhs(sol[2]);
As is well known, there are no closed form solutions for the roots of polynomials of degree 5 or larger. The command 'allroots' may be used to get at least a numerical approximation of the roots.
solve(x^5-x^4+2*x^3+x^2-x+5, x);
allroots(x^5-x^4+2*x^3+x^2-x+5);
Some of these solutions are so called complex non-real numbers. The d'Alembert-Gauss theorem expresses the fact that every non-constant polynomial with complex coefficients has a root in the field of the complex numbers. Consequently, every non-constant polynomial of degree n with complex coefficients, has exactly n roots (counted with their multiplicities). It implies that a non-constant polynomial of degree n with real coefficients, has at most n roots (counted with their multiplicities).
solve(x^2+x+1=0,x);
allroots(x^2+x+1);
You can use realroots(expr) or realroots(eqn) to find rational approximations of the real roots of the polynomial expr or polynomial equation eqn of one variable. Coefficients of expr or eqn must be literal numbers; symbol constants such as %pi are rejected. All coefficients are converted to rational equivalents before searching for roots, and computations are carried out by exact rational arithmetic. Even if some coefficients are floating-point numbers, the results are rational. This is done within a tolerance of bound, which you can set yourself in realroots(expr,bound). Maxima uses a standard tolerance bound if you omit this bound. We use realroots on the 5-th degree polynomial from the example above.
realroots(x^5-x^4+2*x^3+x^2-x+5);
realroots(x^5-x^4+2*x^3+x^2-x+5), numer;
While it is quite convenient Maxima performs many of its computation over the field of complex numbers, for many applications it may be annoying when we are interested in purely real solutions. The situation may become even worse as the following example demonstrates. Here the solution is computed by means of Cardano’s formula. It looks like complex numbers.
opl: solve(x^3-x+1/3=0,x);
However, all three solutions are real numbers. You can try to transform these complex numbers into Cartesian form, i.e. into the representation a + b %i where a and b are real (the so-called real and imaginary part, respectively). 'rectform(expr) returns an expression a + b %i equivalent to expr, such that a and b are purely real. You then can try to reduce the imaginary part to 0 by means of the command' trigsimp'. If you do not use trigsimp or if it is not possible to reduce the imaginary part to 0, then a tiny imaginary part might remain when converting the solutions to floating point numbers due to round-off errors. It can be transformed to a purely real solution by using their real parts. However, you must be confident that the solution is not a complex number.
trigsimp(rectform(opl));
float(trigsimp(rectform(opl)));
float(rectform(opl));
Using realroots, you obtain three solutions. This also shows all three solutions are real numbers.
realroots(x^3-x+1/3);
float(realroots(x^3-x+1/3));
The option reset() resets many global variables and options, and some other variables, to their default values. Sometimes you need this resetting apart from kill(all).
kill(all); reset();
For non-polynomial equations, the result is sometimes not found or you only get one solution:
solve([cos(x)=1],[x]);
solve([cos(x)=0],[x]);
solve([cos(x)=sin(x)],[x]);
allroots(cos(x)-sin(x));
solve ([eqn_1, ..., eqn_n], [x_1, ..., x_n]) solves a system of simultaneous (linear or non-linear) polynomial equations (by respectively calling linsolve or algsys) and returns a list of the solution lists in the variables. In the case of linsolve this list would contain a single list of solutions. It takes two lists as arguments. The first list represents the equations to be solved; the second list is a list of the unknowns to be determined. If the total number of variables in the equations is equal to the number of equations, the second argument-list may be omitted. The symbols %r1, %r2, …, are introduced as needed to represent arbitrary parameters in the solution. These variables %r# are also appended to the list %rnum_list, which you can clear using reset().
solve([x+y=5,x-2*y=-4],[x,y]);
solve([x+y=5,x-2*y=-4]);
solve([x-y=2,x^2+y^2=4],[x,y]);
solve([x-y=2,x^2+y^2=4]);
There are no solutions for the following:
solve([x+y=1,2*x+2*y=3],[x,y]);
Sometimes there are an infinite number of solutions:
solve([x+y=1, 2*x+2*y=2],[x,y]);
solve([x+y=1, 2*x+2*y=2],[x]);
solve([x+2*y-z=1, 2*x+4*y-2*z=2, -x-2*y+z=-1],[x,y,z]);
solve([x+2*y-z=1, 2*x+4*y-2*z=2, -x-2*y+z=-1],[x,y]);
solve([x+2*y-z=1, 2*x+4*y-2*z=2, -x-2*y+z=-1],[y,z]);
solve([x+2*y-z=1, 2*x+4*y-2*z=2, -x-2*y+z=-1],[x,z]);
solve([x+2*y-z=1, 2*x+4*y-2*z=2, -x-2*y+z=-1],[x]);
solve([x+2*y-z=1, 2*x+4*y-2*z=2, -x-2*y+z=-1],[y]);
solve([x+2*y-z=1, 2*x+4*y-2*z=2, -x-2*y+z=-1],[z]);
solve( [ x_1-x_2+x_3 -1=0, x_3+x_4 = 1, x_1-x_2 -x_4=0 ], [x_1,x_2,x_3,x_4] );
Be carefull by choosing the variables you want to solve for:
solve([x+y-z=-1, x+y+z=1],[x,y,z]);
solve([x+y-z=-1, x+y+z=1],[x,z]);
solve([x+y-z=-1, x+y+z=1],[y,z]);
solve([x+y-z=-1, x+y+z=1],[x,y]);
solve([x+y-z=-1, x+y+z=1]);
reset();
Solve does not always find (all) solutions of an arbitrary system of equations. Then an empty list is returned. In the following example the “obvious” solution [x=1,y=1], or more generally x=y, is not found. If you use integer exponents, all solutions are found.
solve([x^(-1/2)*y^(1/2)=1, x^(1/2)*y^(-1/2)=1], [x,y]);
ev([x^(-1/2)*y^(1/2)-1, x^(1/2)*y^(-1/2)-1], [x=1,y=1]);
ev([x^(-1/2)*y^(1/2)-1, x^(1/2)*y^(-1/2)-1], [x=a,y=a]);
solve([x^(-1)*y^(1)=1, x^(1)*y^(-1)=1], [x,y]);
Non-polynomial equations cause problems. You can easily manually solve the following system of equations by the substitution and combination method. Explicitly giving commands in Maxima leads to one particular solution, but not to the general solution.
eq1:cos(x)+sin(y)=1;
eq2:cos(x)-sin(y)=1;
solve([eq1,eq2],[x,y]);
/* Combine the equations: add eq1 and eq2 */ eq1nieuw:eq1+eq2;
/* Solve the new equation */ solve(eq1nieuw);
/* Resubstitute in eq2 */ subst(0,x,eq2);
/* Solve eq2 after back substitution */ solve([%], [y]);
kill(all);reset();
Use "matrix" to create matrices: this takes the row vectors of the matrix as its arguments. These must have the same length. Matrices can contain non-number expressions. The wxMaxima menu 'Algebra > Enter matrix...' can be used to enter a matrix. 'Algebra > Generate matrix...' generates, for instance, its entries from a general term. Note that not every command is defined in a pop-up menu.
Figure 4: Algebra > Enter matrix...
Figure 5: Enter the type of matrix
Figure 6: Fill in the form
Use "invert" to calculate an inverse and "." for matrix multiplication.
A: matrix([1,2],[3,4]);
invert(A);
invert(matrix([1,2],[3,4]));
invert(matrix([1,2],[3,6]));
A: matrix([a,b],[c,d]); B: invert(A); /* Remark: this result assumes A is invertible (see the output) A similar assumption applies to solve(a*x=0,x) : you get as only solution [x=0] */ A.B; ratsimp(A.B);
In the last line we used "ratsimp" to simplify the result of "A.B". Maxima has a lot of different simplification functions, depending on what kind of simplification you want. Simplification is a complex topic and if you don't know anything about it, using "ratsimp" may be your best shot.
!!! You can use * and ^ for matrices but it gives you a pointwise multiplication and exponentiation, respectively.
A*A;
A^3;
!!! Always use . and ^^ for matrix multiplication and exponentiation, respectively.
A.A;
A^^2;
A^^-1;
You can obtain the values of the components of a matrix as demonstrated below:
A[1,2];
Since in Lisp, a matrix is similar to a list of lists, you can show rows as follows:
A[1];
A[2];
Consequently, A[1,2] equals A[1][2]:
A[1][2];
Important Vector are usually printed as row vectors. However, Maxima is quite inconsistent when treating vectors. Depending on the given expression it is interpreted as row vector or as column vector. This is very important when you multiply matrices.
X:matrix([1,2]);
A.X;
X.A;
Y:matrix([1],[2]);
Z:transpose(X);
is(X=Y);
is(Y=Z);
A.Y;
Y.A;
In Maxima you can plot curves, surfaces ... by using the commands plot2d, plot3d, .... (see the Maxima manual, 12.3 Functions and Variables for Plotting). The plot is shown in an external window, so when using "Cell > Evaluate all cells", all followingup calculations are suspended until you close the graph window. In the graph window, you can use a crosshair to see the coordinates of points, rotate a 3d-graph and you can set some Options. The graphs use by default Gnuplot, but you can change this behavior with the wxMaxima menu "Plot > Plot Format ...". The x range for the graph must be specified:
plot2d([sin(x), cos(x)], [x,0, 2*%pi]);
If you use the prefix wx with this Maxima command, i.e. you use wxplot2d, the graph is shown by default in the wxMaxima document. When using the wMaxima menu "Plot > Plot2d", this command wxplot2d is used by default. Moreover, the dialog box makes it possible to change some options and the format of the plot (inline, ...), so the graph can be shown in an external window (see the Maxima manual, 12.4 Plotting Options).
Figure 7: The Plot menu
Figure 8: Plot 2d dialog box
It is possible to plot more than one function:
wxplot2d([sin(x), cos(x)], [x,0, 2*%pi]);
One of the options in this "Plot > Plot2d" menu sets the aspect ratio to 1 (i.e. you use the same units on the horizontal and vertical axis). In the menu, at the same time the option "Set zeroaxis" is used. Adding these details involves inserting a "gnuplot_preamble" which is a list of options not available directly in the wxplot2d command.
wxplot2d([sin(x), cos(x)], [x,0, 2*%pi], [gnuplot_preamble, "set size ratio 1; "] );
wxplot2d([sin(x), cos(x)], [x,0, 2*%pi], [gnuplot_preamble, "set size ratio 1; set zeroaxis;"] );
As you probably noticed, the horizontal axis is labeled x. You should label both the horizontal and the vertical axis. This can be done resp. by setting xlabel and ylabel using e.g. [xlabel, string], where string labels the horizontal (=first) axis and [ylabel, string], where string now labels the vertical (=second) axis.
wxplot2d([sin(x), cos(x)], [x,0, 2*%pi], [gnuplot_preamble, "set size ratio 1; "], [xlabel, "X"], [ylabel, "Y"] );
The "gnuplot_preamble" can also be used to show a grid, to move the legend and to set a title. The key (legend) moves to the bottom left in the following example. It could be set at bottom center, bottom left, bottom right, left center, right center, and so forth. Note the syntax. All Gnuplot options are part of a list, with gnuplot_preamble as the first item in this list. All options are between double quotation marks. Each item ends with a semicolon. Text entries are within single quotation marks.
wxplot2d([sin(x),cos(x)], [x,0, 2*%pi], [xlabel, "X"], [ylabel, "Y"], [legend, "sin", "cos"], [gnuplot_preamble, " set grid; set key bottom left; set title 'Two graphs'; " ] );
wxplot2d([sin(x), cos(x)], [x,0, 2*%pi], [xlabel, "X"], [ylabel, "Y"], [legend, "sin", "cos"], [gnuplot_preamble, "set size ratio 1; set grid; set key bottom left; set title 'Two Graphs Aspectratio 1';"] );
You can alter the appearance of continuous lines by by applying "style" and using the form [lines,[thickness,color]]. The first option, thickness, represents the thickness of the lines to be plotted. The larger the value of this first parameter the larger the individual line thickness. The second option, color, represents the color of the lines with default values: 1-blue 2-red 3-magenta 4-orange 5-brown 6-lime 7-aqua The sequence of colors repeat after the number 7, i.e., 8 will be blue, 9 red, etc. We illiustrate [style,[lines,1,2],[lines,3,4]]:
wxplot2d([sin(x), cos(x)], [x,0, 2*%pi], [style,[lines,1,2],[lines,3,4]], [gnuplot_preamble, "set size ratio 1; "], [xlabel, "X"], [ylabel, "Y"] );
If the functions grows too fast, it might be necessary to limit the values in the vertical axis using the y option. Compare the following two examples:
wxplot2d (sec(x), [x, -2, 2]);
wxplot2d (sec(x), [x, -2, 2], [y, -20, 20]);
As above, one might want to control the y axis as well as the x axis. Consider the following function, which draws a circle using two explicit functions. The figure below raises two issues regarding the presentation of the functions, the question of scale and the definition of a legend to identify individual functions.
wxplot2d([sqrt(4-x^2),-sqrt(4-x^2)], [x,-2.5,2.5],[y,-2.5,2.5]);
Two aspects of this graph warrant concern. Most obviously, the "circle" looks decidedly non-spherical. Second, a legend has appeared, one that we might want to make more informative. A legend appears automatically whenever more than one function is being plotted. The first problem relates to the fact that Maxima does not assume that x and y axis have the same units, and it stretches the figure so that the a centimeter along the vertical axis accounts for more units that a centimeter does along the horizontal axis. To avoid this distortion, instruct wxplot2d to produce a square graph. Another option for removing the distortion appears below. To add content to the legend, add a legend option.
wxplot2d([sqrt(4-x^2),-sqrt(4-x^2)], [x,-2.5,2.5],[y,-2.5,2.5], [legend, "UpperSemiCircle", "LowerSemiCircle"] ), wxplot_size=[400,400];
Suppose we want a cleaner display. We could suppress the legend, as below. Also, it is possible to make both halves of the circle having the same color. Furthermore,we can remove the box around the circle and the information about units, as well as the axis labels (although this is not a good working style).
wxplot2d([sqrt(4-x^2),-sqrt(4-x^2)], [x,-2.5,2.5],[y,-2.5,2.5], [legend, false], [box,false], [xlabel, ""], [ylabel, ""]), wxplot_size=[400,400];
wxplot2d([sqrt(4-x^2),-sqrt(4-x^2)], [x,-2.5,2.5],[y,-2.5,2.5], [legend, false], [box,false], [xlabel, "X"], [ylabel, "Y"]), wxplot_size=[400,400];
wxplot2d([sqrt(4-x^2),-sqrt(4-x^2)], [x,-2.5,2.5],[y,-2.5,2.5], [legend, false], [xlabel, "X"], [ylabel, "Y"]), wxplot_size=[400,400];
"Squaring" a display, can also be done by using the gnuplot_preamble "set size ratio 1".
wxplot2d([sqrt(4-x^2),-sqrt(4-x^2)], [x,-2.5,2.5],[y,-2.5,2.5], [legend, false], [gnuplot_preamble, "set title 'Another way to make a circle appear spherical'; set size ratio 1;"] );
Using line styles, you can obtain the same colors for both semicircles:
wxplot2d([sqrt(4-x^2),-sqrt(4-x^2)], [x,-2.5,2.5],[y,-2.5,2.5], [style,[lines,4,1],[lines,4,1]], [legend, false], [xlabel, "X"], [ylabel, "Y"]),wxplot_size=[400,400];
Sometimes the plot does not show the horizontal axis:
wxplot2d([sin(x)+5], [x,0, 2*%pi]);
To resolve, use e.g. the y option:
wxplot2d([sin(x)+5], [x,0, 2*%pi],[y,0,6.5]);
wxplot2d([sin(x)+5], [x,0, 2*%pi],[y,0,6.5], [gnuplot_preamble, "set size ratio 1; "]);
wxplot3d( x*y, [x,-2,2],[y,-2,2]);
wxplot3d(x*y, [x,-2,2], [y,-2,2], [gnuplot_preamble, "set hidden3d"]);
If you want to insert a comment in an input cell, you can use /* */
/* This Maxima commands opens an external window. By keeping the left mouse button pressed, you can rotate the graph. */ plot3d( x*y, [x,-2,2],[y,-2,2]);
wxcontour_plot(x*y, [x,-2,2],[y,-2,2]);
wxcontour_plot(x*y, [x,-2,2],[y,-2,2], [legend,false], [gnuplot_preamble,"set cntrparam levels 9"] );
Maxima provides a basic set of core commands and offers a variety of add-on packages for special tasks. This makes it possible to extend the capabilities of the system. Such packages are either automatically loaded on demand or the packages have to be explicitly loaded. For the latter we have to load the corresponding files by using "load(package)". The loaded functions are added to the list of user-defined functions and can be displayed and removed using "functions" and "kill(all)", respectively. To see a list of the packages available in Maxima, launch the Maxima Manual by using the menu item "Help > Maxima Help", and click on the Contents tab. Then, scroll down until you pass all the chapters that start with an upper-case letter. The Maxima packages correspond to those chapters that start with a lower-case letter.
The abilities of Maxima’s plot command are restricted and do not satisfy all needs. Package 'draw' provides a more powerful and flexible plotting (and drawing) tool. However, it only supports the Gnuplot plotting routine, and as such draw is a Maxima–Gnuplot interface. Before you can use the package in Maxima it must be loaded by using "load(draw)" as described above. When you use the corresponding wxMaxima command, the package is automatically loaded. See the Maxima manual: 12. Plotting 48.1 Introduction to draw.
Figure 9: The Help menu to view the Maxima manual
Figure 10: Information about the draw package in the Maxima manual
Remark: if you want to insert a comment in an input cell, you can use /* */
/* The following command must be given when using e.g. the draw command in Maxima. It is not needed when only using wxMaxima commands, in which case the command is automatically loaded. */ load(draw);
The Maxima command "draw()" plots a series of scenes; its arguments are gr2d and/or gr3d objects, which are 2- or 3-dimensional scenes, together with some options, or lists of scenes and options. If more than one scene is described, a multiplot will be generated. If only one scene is build, then draw2d(...) and draw3d(...) can be used as these are equivalent to draw(gr2d(...)) and draw(gr3d(...)), respectively. Options for these functions (graphics options) are given as key=value pairs, e.g. xaxis=true or xlabel="X". Scenes in the gr2d and gr3d constructor are interpreted sequentially: graphic options affect those graphic objects placed on its right. Some graphic options affect the global appearance of the scene and may be located at any position or given to the draw command (global options).
Two dimensional scenes can be build by means of the gr2d scene constructor. For plotting graphs of functions the following options are available: • explicit: the function is given in terms of the input values, e.g. f(x):=xˆ2. • implicit: the function is implicitly given by the solution of an equation of the form F(x, y) = 0, e.g, xˆ2+yˆ2-1=0. • parametric: the plotted curve is given as a path in a two dimensional space, e.g. [cos(t),sin(t)]. Besides these there are some other graphic objects for adding lines or annotating graphs. explicit(fcn,var,minval,maxval) plots an explicit function fcn, with variable var taking values from minval to maxval:
wxdraw( gr2d ( explicit(x^2,x,-1,3) ) );
draw2d is the same as draw(gr2d). In wxMaxima the corresponding is true for wxdraw2d:
wxdraw2d( explicit(x^2,x,-1,3) );
You can use lots of options: xrange=[-1,3], yrange=[-1,10] are global options; color=green, line_width = 5 are local options.
wxdraw2d( xlabel="X", ylabel="Y", xrange=[-1,3], yrange=[-1,10], color=green, line_width = 5, explicit(x^2,x,-1,3) );
Options are applied to the graphic objects to the right of the option:
wxdraw2d( xlabel="X", ylabel="Y", xrange=[-1,3], yrange=[-1,10], xaxis=true, yaxis=true, color=green, line_width = 5, explicit(x^2,x,-1,4), color=blue, line_width = 3, explicit(4-2*x,x,0,2) );
If you use more than one gr2d, the plots are placed in one column by default:
wxdraw( gr2d(color=green, line_width = 5, explicit(x^2,x,-1,4)) , gr2d(color=blue, line_width = 3, explicit(4-2*x,x,0,2)) );
wxdraw( gr2d(color=green, line_width = 5, xlabel="X",ylabel="Y", explicit(x^2,x,-1,4)) , gr2d(color=blue, line_width = 3, explicit(4-2*x,x,0,2)), columns=2 );
This package also facilitates contour plotting in 3-D:
wxdraw3d( enhanced3d = true, explicit(x*y, x,-2,2, y,-2,2), contour=both, contour_levels=9 );
wxdraw3d( enhanced3d = true, xlabel="X",ylabel="Y",zlabel="Z", xtics=1,ytics=1,ztics=2, explicit(x*y,x,-2,2,y,-2,2), contour = both, contour_levels = 9, surface_hide = true, colorbox=false ) ;
wxdraw3d(enhanced3d = true, xlabel="X",ylabel="Y",zlabel="Z", xtics=1,ytics=1,ztics=2, explicit(x*y,x,-2,2,y,-2,2), contour = both, contour_levels = {-3, -2, -1, 0, 1, 2,3}, surface_hide = true, colorbox=false) $
wxdraw3d(enhanced3d = true, xlabel="X",ylabel="Y",zlabel="Z", xtics=1,ytics=1,ztics=2, explicit(x*y,x,-2,2,y,-2,2), contour = both, contour_levels = [-3, 1, 3], surface_hide = true, colorbox=false) $
wxdraw3d( user_preamble="unset key", enhanced3d = true, xlabel="X",ylabel="Y",zlabel="Z", xtics=1,ytics=1,ztics=2, explicit(x*y,x,-2,2,y,-2,2), contour = both, contour_levels = [-3, 1, 3], surface_hide = true, colorbox=false) $
wxdraw3d( user_preamble="unset key", enhanced3d = true, xlabel="X",ylabel="Y",zlabel="Z", xtics=1,ytics=1,ztics=2, explicit(x*y,x,-2,2,y,-2,2), contour = both, contour_levels = [-3, 1, 3], surface_hide = true, colorbox=false, xyplane=0 ) $
Some common (wx)Maxima commands are available through Maxima, Equations, Algebra, Calculus, Simplify, Plot and Numeric menus. All menu entries ending with '...' will open a dialog, to help you formulate the command. The resulting command will be inserted at horizontal cursor's position or below the currently active cell. The command will also be evaluated.
Figure 11: The wxMaxima menu options
An optional button panel can be shown in the wxMaxima window using Maxima > Panes. It works in a similar manner as the menus.
Figure 12: Show or hide Button Pannels
Figure 13: The Statistics and General Math panes
Note also that if you have a selection before you use a button panel command or a menu command, that selection will be used as the main (or only) argument to the command. Selection of a previous output or part of an input will work in a similar manner.
The common arithmetic operations are + addition - subtraction * scalar multiplication / division ^ or ** exponentiation . matrix multiplication and some functions are sqrt square root sin sine cos cosine tan tangent cot cotangent sec secant csc cosecant asin inverse sine acos inverse cosine atan inverse tangent acot inverse cotangent asec inverse secant acsc inverse cosecant exp exponential log natural logarithm sinh hyperbolic sine cosh hyperbolic cosine tanh hyperbolic tangent asinh hyperbolic asin acosh hyperbolic acos atanh hyperbolic atan floor integer below ceiling integer above fix integer part float convert to floating point abs absolute value
Maxima's output is characterized by exact (rational) arithmetic. If irrational numbers are involved in a computation, they are kept in symbolic form. However, it is often useful to express a result in decimal notation. This may be accomplished by following the expression you want expanded by ",numer". You can also use "float". Both give by default 16 significant figures, of which the last is often unreliable. However, Maxima can offer arbitrarily high precision by using the bfloat function.
5*sqrt(2) + 41;
5*sqrt(2) + 41 ,numer;
float(5*sqrt(2) + 41);
bfloat(5*sqrt(2) + 41);
Remember: %pi; (this is how to identify the number "pi" to Maxima, this will appear as a Greek letter only if a Greek font has been installed) float(%pi); (means "give me the numerical value") bfloat(): converts all numbers and functions of numbers in expr to bigfloat numbers. The number of significant digits in the resulting bigfloats is specified by the global variable fpprec. fpprec:1000; (increase the "floating point precision" or "fpprec") fpprec is the number of significant digits for arithmetic on bigfloat numbers (default 16). fpprec does not affect computations on ordinary floating point numbers. set_display(ascii); (this is a special wxMaxima setting that forces all the digits to be printed out) set_display(xml); (return to the default way of displaying things) The "fpprec" and "set_display(ascii)" settings only affect floating-point numbers, integers are always printed out fully.
%pi;
float(%pi);
bfloat(%pi);
fpprec:1000;
set_display(ascii);
set_display(xml);
Remember: If you want to list all the digits of a floating-point value, use "set_display(ascii);". If you want wxMaxima to render equations and functions in a pretty way, use "set_display(xml);". Use fpprec to set 'big float precision'.
fpprec:16;
Maxima only offers the natural logarithm function "log". So do not use "ln".
log(10);
float(log(10));
log(%e);
ln(%e);
float(ln(%e));
log(%e^2)/log(%e);
log10 is not available by default but you can define it yourself as shown below, although some results like log10(100) can be simplified.
log10(x):= log(x)/log(10);
log10(10);
log10(100);
ratsimp(log10(100));
Reserved Words ============== The following are reserved words in Maxima and cannot be used as variable names: integrate next from diff in at limit sum for and else if then else do or if unless product while thru step
The menu has an option 'Help'.
To get help on any function, just click on the function name and press F1. Try it for the following examples.
log(2);
fpprec;
ln(2);
To get help with a name used by Maxima, just type "? name" or "describe(name)".Do not forget the space between ? and solve !!!!!
? solve;
If you only know part of the name, just type "?? name". Maxima gives you a choice list: you need to make a selection.
?? solve;
If you turn the part of the name you know into a string , and use apropos(), you get a list of Maxima names which have appearing anywhere within them.
apropos("solve");
? apropos;
Some examples can be obtained using 'example': 'example (<topic>)' displays some examples of <topic>, which is a symbol or a string. To get examples for operators like 'if', 'do', or 'lambda' the argument must be a string, e.g. 'example ("do")'. 'example' is not case sensitive. Most topics are function names. 'example()' returns the list of all recognized topics.
example(solve);
example();
The menu 'Edit > Configure' leads to a dialog box in which you can change some options and styles.
Figure 14: Edit > Configure
In particular, the following options can be changed: if you want to change the behaviour of 'Shift+Enter' to evaluate a cell in wxMaxima to 'Enter', check 'Enter evaluates cells'. This switches the roles of these two key commands, if you do not like the default behaviour where matching parentheses are automatically inserted, uncheck 'Match parenthesis in text controls'.
Figure 15: Configuration Options
At http://statmath.wu.ac.at/~leydold/maxima/ you should download and study the tutorial by Josef Leydold and Martin Petry. See the links at this page for: a pdf file MaximaSkript.pdf using the link Introduction to Maxima for Economics (http://statmath.wu.ac.at/~leydold/maxima/MaximaSkript.pdf), a wxMaxima notebook with all examples from the Introduction to Maxima for Economics (http://statmath.wu.ac.at/~leydold/maxima/MaximaSkript.wxm) and the Maxima code for answers to the exercises (http://statmath.wu.ac.at/~leydold/maxima/MaximaSkript-sol.wxm). See also the links to examples on: http://math.hawaii.edu/wxmaxima/ and the Maxima book by Gilberto E. Urroz (a comprehensive overview, each chapter organized by mathematical area): http://www.neng.usu.edu/cee/faculty/gurro/Maxima.html For more information on plotting and graphics, see http://www.austromath.at/daten/maxima/zusatz/Graphics_with_Maxima.pdf and Mario Rodríguez Riotorto's site: http://riotorto.users.sourceforge.net/index.html , http://riotorto.users.sourceforge.net/gnuplot/func2d/index.html . A somewhat older but very good description of Maxima’s capabilities can be found at the site of Edwin Woollet: http://www.csulb.edu/~woollett/ and in the Maxima book by P. de Souza, R. Fateman, J. Moses, C. Yapp http://maxima.sourceforge.net/docs/maximabook/maximabook-19-Sept-2004.pdf .
Created with wxMaxima.