XMaxima is a full featured CAS (Computer Algebra System) that is available for Windows, Mac OS X, and Linux. Since it's Free and Open Source software, you can install it on as many computers as you like. Your students can even download it and load it on their home computers.

10 Minute Tutorial

If you are not acquainted with CAS software, Maxima may appear very complicated and difficult to use, even for the resolution of simple high school or calculus problems. This doesn’t have to be the case though, Maxima is very friendly and this 10 minute tutorial will get you started right away. Once you’ve got the first steps down, you can always look up the specific function that you need, or learn more from Maxima’s official manual available at Alternatively, you can use the question mark followed by a string to obtain in-line documentation (e.g. ? integrate). Finally, maxima can show you some usage examples. For instance, to see examples of how to use the integrate function, simply type 'example(integrate);'

This tutorial takes a practical approach, where simple examples are given to show you how to compute common tasks.

To do basic operations, a line is typed, followed by a semicolon, and then entered. This can be done in the window above. Let's try something simple, like addition. Start by typing "7 + 9;" in the XMaxima evaluation window above. The result should look something like this:

(%i16) 7 + 9; (%o16) 16

Alternately you may edit the blue portions in this window, and click on them, to see the result evaluated above and/or inserted in this window, depending on what was specified in the html source for this file. For example, double clicking the blue "7 + 9" below will result in the formula being inserted into the Maxima evaluation window and being evaluated. Try it now.

  • 9+7; returns result

By the way, it's easy to create your own canned XMaxima lecture, just like this one. The XMaxima browser (this window) can be used to create and edit xmaxima documents. Dynamic formulas can be created by selecting the relevant text with the mouse and then using the "mark for mval" option under the "Edit" tab.

Maxima as a calculator

You can use Maxima as a fast and reliable calculator whose precision is arbitrary within the limits of your PC’s hardware. Maxima expects you to enter one or more commands and expressions separated by a semicolon character (;), just like you would do in many programming languages.

  • 9+7; returns result
  • -17*19; returns result
  • 10/2; returns result

Maxima allows you to refer to the latest result through the % character, and to any previous input or output by its respective prompted %i (input) or %o (output). For example:

(%i1) 10 + 2; (%o1) 12 (%i2) %o1 + 2; (%o2) 14 (%i3)

Remember that maxima is a symbolic algebra program, so it doesn't approach arithmetic in the same way that a calculator would. For instance, when the numerator and denominator are both integers, a reduced fraction or an integer value is returned:

  • 5/6; returns result
  • 6/12; returns result
  • 10/3; returns result

If you insist on calculator-like imprecision. These can be evaluated in floating point by using the float function (or bfloat for big floating point numbers):

  • float(5/6); returns result
  • float(6/12); returns result
  • bfloat(10/3); returns result

As mentioned above, big numbers are not an issue:

  • 13^26; returns result
  • 13^260; returns result
  • float((7/3)^35); returns result
  • bfloat((7/3)^35); returns result

For bfloat calculations, you can increase the number of significant digits by setting the global variable fpprec

  • fpprec:50; returns result
  • bfloat((7/3)^35); returns result

Constants and common functions

Here is a list of common constants in Maxima, which you should be aware of:

  • %e - Euler’s Number: bfloat(%e); returns result
  • %pi : bfloat(%pi); returns result
  • %phi - the golden mean ( 1 + sqrt(5) )/2 ): bfloat(%phi); returns result
  • %i - the imaginary unit (sqrt(-1))
  • inf - real positive infinity
  • minf - real minus infinity
  • infinity - complex infinity

We can use some of these along with common functions:

  • sin(%pi/2) + cos(%pi/3); returns result
  • tan(%pi/3) * cot(%pi/3); returns result
  • float(sec(%pi/3) + csc(%pi/3)); returns result
  • log(%e); returns result

Defining functions and variables

Variables can be assigned through a colon ‘:’ and functions through ‘:=’. The following code shows how to use them:

(%i1) a:7; b:8; (%o1) 7 (%o2) 8 (%i3) a; (%o3) 7 (%i4) b; (%o4) 8 (%i5) sqrt(a2 + b2); (%o5) sqrt(113) (%i6) float(%o5); (%o6) 10.63014581273465

Please note that Maxima only offers the natural logarithm function log. log10 is not available by default but you can define it yourself as shown below: log10(x):= log(x)/log(10); Now that the function has been defined, we can use it: log10(10); returns result float(log10(100)); returns result Symbolic Calculations

factor enables us to find the prime factorization of a number:

factor(30!); returns result

We can also factor polynomials:

factor(x^2 + x -6); returns result

And expand them:

expand((x+3)^4); returns result

Simplify rational expressions:

ratsimp((x^2-1)/(x+1)); returns result

And simplify trigonometric expressions:

trigsimp(2*cos(x)2 + sin(x)2); returns result

Similarly, we can expand trigonometric expressions:

trigexpand(sin(2*x)+cos(2*x)); returns result

Please note that Maxima won’t accept 2x as a product, it requires you to explicitly specify 2*x. Solving Equations and Systems

We can easily solve equations and systems of equations through the functions solve and trigsimp:

solve(x^2-4,x); returns result solve(x^3=1,x); returns result solve([x - 2*y = 14, x + 3*y = 9],[x,y]); returns result trigsimp(solve([cos(x)2-x=2-sin(x)2], [x])); returns result 2D and 3D Plotting

Maxima enables us to plot 2D and 3D graphics, and even multiple functions in the same chart. The functions plot2d and plot3d are quite straightforward as you can see below. The second (and in the case of plot3d, the third) parameter, is just the range of values for x (and y) that define what portion of the chart gets plotted. plot2d(x^2-x+3,[x,-10,10]); plot2d([x2, x3, x^4 -x +1] ,[x,-10,10]); plot3d(sin(x)+ sin(y), [x,-5,5], [y,-5,5]); plot3d(sin(x)+ sin(y), [x,-5,5], [y,-5,5],[plot_format,mgnuplot]); plot3d(sin(x)+ sin(y), [x,-5,5], [y,-5,5],[plot_format,openmath]); plot3d(sin(x)+ sin(y), [x,-5,5], [y,-5,5],[gnuplot_pm3d,true]); Limits limit((1+1/x)^x,x,inf); returns result limit(sin(x)/x,x,0); returns result limit(2*(x^2-4)/(x-2),x,2); returns result limit(log(x),x,0,plus); returns result limit(sqrt(-x)/x,x,0,minus); returns result Differentiation

diff(sin(x), x); returns result diff(x^x, x); returns result

We can calculate higher order derivatives by passing the order as an optional number to the diff function:

diff(tan(x), x, 4); returns result Integration

Maxima offers several types of integration. To symbolically solve indefinite integrals use integrate:

integrate(1/x, x); returns result

For definite integration, just specify the limits of integrations as the two last parameters: integrate(x+2/(x -3), x, 0,1); returns result integrate(%e(-x2),x,minf,inf); returns result

If the function integrate is unable to calculate an integral, you can do a numerical approximation through one of the methods available (e.g. romberg):

romberg(cos(sin(x+1)), x, 0, 1); returns result Sums and Products

sum and product are two functions for summation and product calculation. The simpsum option simplifies the sum whenever possible. Notice how the product can be use to define your own version of the factorial function as well. sum(k, k, 1, n); returns result Now set n = 50: sum(k, k, 1, 50); returns result sum(k, k, 1, n), simpsum; returns result sum(1/k^4, k, 1, inf), simpsum; returns result fact(n):=product(k, k, 1, n); returns result fact(10); returns result Series Expansions

Series expansions can be calculated through the taylor method (the last parameter specifies the depth), or through the method powerseries: niceindices(powerseries(%e^x, x, 0)); returns result taylor(%e^x, x, 0, 5); returns result

The trunc method along with plot2d is used when taylor’s output needs to be plotted (to deal with the + ... in taylor’s output): plot2d([trunc(taylor(%ex, x, 0, 5)), %ex], [x,-5,5]); Trigonometric Equation or Expression First we need to set some global variables to make things easier: [fpprintprec:8,display2d:false]; fpprintprec is the number of digits to print when printing an ordinary float or bigfloat number. When display2d is false, the console display is a string (1-dimensional) form rather than a display (2-dimensional) form. ex : sin(x)^2-2*sin(x) -3; returns result sol : solve(ex); returns result define( f(x), ex ); returns result expand ( map(f, map(rhs, sol) ) ); returns result numroots : float( map(rhs, sol) ); returns result The first solution returned is the angle (in radians) whose sin is 3. For real x, sin(x) lies in the range -1 <= sin(x) <= 1. Thus we have found one real root. But we have been warned that some solutions will be lost. Because the given expression is a polynomial in sin(x), we can use realroots: rr : realroots(ex); returns result However, by "realroots", realroots means that the numbers [ -1,3] are real!

We can of course take the output of realroots and let solve go to work. map(solve, rr); returns result We know that the numerical value of the expression ex repeats when x is replaced by x + 2*%pi, so there are an infinite number of real roots, related to −%pi/2 by adding or subtracting 2n*%pi, where n is an integer.

We can make a simple plot of our expression to see the periodic behavior and the approximate location of the real roots. plot2d([0,sin(x)^2-2*sin(x)-3],[x,-2*%pi,2*%pi],[y,-5,5]);

Lessons/Maxima (last edited 2008-08-06 16:29:10 by localhost)