A 10 minute tutorial for solving Math problems with Maxima

About 50,000 people read my article 3 awesome free Math programs. Chances are that at least some of them downloaded and installed Maxima. If you are one of them but are not acquainted with CAS (Computer Algebra System) 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, whether you are looking for more math resources to use in your career or a student in an online bachelor’s degree in math looking for homework help, 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. Alternatively, you can use the question mark followed by a string to obtain in-line documentation (e.g. ? integrate). This tutorial takes a practical approach, where simple examples are given to show you how to compute common tasks. Of course this is just the tip of the iceberg. Maxima is so much more than this, but scratching even just the surface should be enough to get you going. In the end you are only investing 10 minutes.

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.

(%i1) 9+7;
(%o1) 16
(%i2) -17*19;
(%o2) -323
(%i3) 10/2;
(%o3) 5

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:

(%i4) % - 10;
(%o4) -5
(%i5) %o1 * 3;
(%o5) 48

For the sake of simplicity, from now on we will omit the numbered input and output prompts produced by Maxima’s console, and indicate the output with a => sign. When the numerator and denominator are both integers, a reduced fraction or an integer value is returned. These can be evaluated in floating point by using the float function (or bfloat for big floating point numbers):

=> 4
=> 4.0
=> \displaystyle \frac{1}{3}
=> 0.33333333333333
=> 0.33333333333333
=> \displaystyle \frac{13}{2}
=> 6.5

As mentioned above, big numbers are not an issue:

=> 91733330193268616658399616009
=> \displaystyle 9.1733330193268623\text{ }10^_{+28}
=> 265252859812191058636308480000000
=> \displaystyle 7.5715969098311943\text{ }10^_{+12}

Constants and common functions

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

  • %e – Euler’s Number
  • %pi – \displaystyle \pi
  • %phi – the golden mean (\displaystyle \frac{1+\sqrt{5}}{2})
  • %i – the imaginary unit (\displaystyle \sqrt{-1})
  • inf – real positive infinity (\infty)
  • minf – real minus infinity (-\infty)
  • infinity – complex infinity

We can use some of these along with common functions:

sin(%pi/2) + cos(%pi/3);
=> \displaystyle \frac{3}{2}
tan(%pi/3) * cot(%pi/3);
=> 1
float(sec(%pi/3) + csc(%pi/3));
=> 3.154700538379252
=> 9
=> 1

Defining functions and variables

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

a:7; b:8;
=> 7
=> 8
=> \sqrt{113}
f(x):= x^2 -x + 1;
=> x^2 -x + 1
=> 7
=> 43
=> 57

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);
=> \displaystyle log10(x):=\frac{log(x)}{log(10)};
=> 1

Symbolic Calculations

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

=> \displaystyle 2^{26}\,3^{14}\,5^7\,7^4\,11^2\,13^2\,17\,19\,23\,29

We can also factor polynomials:

factor(x^2 + x -6);
=> (x-2)(x+3)

And expand them:

=> \displaystyle x^4+12\,x^3+54\,x^2+108\,x+81

Simplify rational expressions:

=> x-1

And simplify trigonometric expressions:

trigsimp(2*cos(x)^2 + sin(x)^2);
=> \displaystyle \cos ^2x+1

Similarly, we can expand trigonometric expressions:

=> \displaystyle -\sin ^2x+2\,\cos x\,\sin x+\cos ^2x

Please note that Maxima won’t accept 2x as a product, it requires you to explicitly specify 2*x. If you wish to obtain the TeX representation of a given expression, you can use the tex function:

=> $$-\sin ^2x+2\,\cos x\,\sin x+\cos ^2x$$

Solving Equations and Systems

We can easily solve equations and systems of equations through the function solve:

=> \displaystyle \left[ x=-2 , x=2 \right]
=> x=2
=> \displaystyle \left[ x={{\sqrt{3}\,i-1}\over{2}} , x=-{{\sqrt{3}\,i+1}\over{2}}  , x=1 \right]
trigsimp(solve([cos(x)^2-x=2-sin(x)^2], [x]));
=> \displaystyle \left[ x=-1 \right]
solve([x - 2*y = 14,  x + 3*y = 9],[x,y]);
=> \left[ \left[ x=12 , y=-1 \right]  \right]

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^4 -x +1] ,[x,-10,10]);


f(x,y):= sin(x) + cos(y);
plot3d(f(x,y), [x,-5,5], [y,-5,5]);



=> %e
=> 1
=> 8
=> -\infty
=> -\infty


diff(sin(x), x);
=> \displaystyle cos(x)
diff(x^x, x);
=> \displaystyle x^{x}\,\left(\log x+1\right)

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

diff(tan(x), x, 4);
=> \displaystyle 8\,\sec ^2x\,\tan ^3x+16\,\sec ^4x\,\tan x


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

integrate(1/x, x);
=> \displaystyle log(x)

For definite integration, just specify the limits of integrations as the two last parameters:

integrate(x+2/(x -3), x, 0,1);
=> \displaystyle -2\,\log 3+2\,\log 2+{{1}\over{2}}
=> \sqrt{\% pi}

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);
=> 0.57591750059682

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);
=> \displaystyle \sum_{k=1}^{n}{k}
sum(k, k, 1, n), simpsum;
=> \displaystyle {{n^2+n}\over{2}}
sum(1/k^4, k, 1, inf), simpsum;
=> \displaystyle {{\%pi^{4}}\over{90}}
fact(n):=product(k, k, 1, n);
=> fact(n):=product(k,k,1,n)
=>  3628800

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));
=> \displaystyle \sum_{i=0}^{\infty }{{{x^{i}}\over{i!}}}
taylor(%e^x, x, 0, 5);
=> \displaystyle 1+x+{{x^2}\over{2}}+{{x^3}\over{6}}+{{x^4}\over{24}}+{{x^5}\over{120 }}+\cdots

The trunc method along with plot2d is used when taylor’s output needs to be plotted (to deal with the +\cdots in taylor’s output):

plot2d([trunc(%), %e^x], [x,-5,5]);


I hope you’ll find this useful and that it will help you get started with Maxima. CAS can be powerful tools and if you are willing to learn how to use them properly, you will soon discover that it was time well invested.

Sponsor’s message: Math Better Explained is an insightful ebook and screencast series that will help you deeply understand fundamental mathematical concepts, and see math in a new light. Get it here.

If you enjoyed this post, then make sure you subscribe
to our Newsletter and/or RSS Feed.

135 Responses to “A 10 minute tutorial for solving Math problems with Maxima”

  1. Alex says:

    I’m alex..I write because I knew Maxima last year and using there in linux, it’s amazing!!!..But now I want install Maxima in WinXP (for work) and I fail the configuration because there is a problem with a socket!!!
    How Can I do?
    thanks (Sorry for my English)!!!

  2. Hank says:

    Hi —

    Don’t forget to check out the best Maxima tutorial IMHO:


  3. Larry Dickson says:

    How do you gracefully exit the maxima program? exit; and quit; don’t work. I tried ? quit and did get out via a stack overflow :-) but surely there is some way out other than crashing???

  4. Larry, quit(); will exit maxima. :)

  5. Alexandros says:

    I exit maxima with Ctrl-D.

  6. samuel measho says:

    HI ,I just want to ask how can i use maxima to compute and draw the graph of complex numbers.

  7. I’m trying Maxima now, after closing my sage session. I ran into trouble using sage to define a symbolic sum e.g. you want to define a function like:

    f(x) = sum(i, i, 1, x);

    apparently sage cannot do that at this point in the development. It was disappointing that sage couldn’t do this (or if it is possible to do this I couldn’t figure it out after an hour of trying).

    sage is actually the first hit after a google search for “sage”, so it is still popular, and maybe it’ll improve by leaps and bounds, but at least after the first ten minutes I have a better feeling about Maxima.

    when I was searching for a way to solve my problem I found this thread, which indicates
    that this functionality is on the way for the sage:

    it seems to me that sage is more of an interface to or a concatenation of a lot of other programs (latex, r, maxima, python etc., and also commercial programs like mathematica, matlab). I guess one has to ask whether when doing a task it is better to use sage as a single command center, or to just use that program directly.

  8. Rob says:

    When I try your example:

    trigsimp(2*cos(x)^2 + sin(x)^2);

    I get
    => \displaystyle \cos(x)^2+1
    instead of
    => \displaystyle \cos ^2x+1

    • jerzy says:

      Maxima gives correct result, because:
      2*cos(x)^2 + sin(x)^2=
      cos(x)^2+cos(x)^2 + sin(x)^2=

      cos(x)^2 + sin(x)^2=1

  9. Ivan Belash says:

    You forget one, but very important thing: how to run – Ctrl+R
    It really easy, but it was a problem for me.

  10. AKE says:

    Very nice tutorial introduction! Highly recommended first intro to Maxima.

    I’ve put together a selection of the Maxima resources that I’ve found most useful over the years, including a succinct instruction cheatsheet, a guide to programming subroutines/scripts, and a Mathematica-Maxima syntax conversion chart.

    They’re available here:


  11. A Rubens de Castro says:

    I am using wxMaxima on Ubuntu9.10.
    I understand that wxMaxima is just a front-end, the Maxima Kernel does not exist in my computer, it resides somewhere else.
    All the examples you give are very easy, however
    I have a problem not covered on your tutorial: after a given number of operations (computations, writes to disk, etc) my connection with Maxima is terminated, it is like a time-out. Then I have to click on “Restart Maxima” to go on with my calculations for some other value of the parameters.
    Anything obvious which I should but am not doing ??? My colleagues say Maxima works better than Mathematica !

    A Rubens

  12. Alexander says:

    I am recently retired and cut my math curious teeth with “Mathematica for students” circa fall 2000. The past ten years i have developed computer parametric geometry to explor gravity curves and have a written manuscript that would work best with a “symbolic logic program” such as Derive or Mathematica in the back cover. TI did’t want to look at it (Derive had more then enough power to study simple curvature relations) and Mathematica never replied. I know it would push education of math beyond expectations simply because I had so much fun doing it. Can any one out there help get this project “air borne”. Not in “education” I had no idea Maxima or others existed and there is little difference betwixt utility gained! Thanks for the tutorial and I will attempt the download and application.

  13. Ricardo M says:

    Men necesito un gran favor! necesito saber si sabes resolver problemas de optimizacion lineal con este programa, se lo agradeceria mucho!

  14. synhedionn says:

    In Maxima: sum(i,i,1,n); gives sum(i,i,1,n);
    Can’t it give n(n+1)/2?

  15. Ragbir Chana says:

    Great tutorial. I like tutorials doing by example.

  16. Derek Pilous says:

    Fantastic tutorial, thank you very much. If you’re not a teacher, you should be (well, if you’re scientist, you’re excused ;)). I am teacher myself and I can say, there are few people capable of writing so comprehensible and yet inspiring introduction to topic. Sorry for my English :)

  17. jerzy says:

    Clear, simple, useffull, beautiful work. Thanks.

  18. RockyRoad says:

    Great work Antonio, thank you very much :)

    Inspiring ? Yes !

    I’m nearly new to CAS programs (played a bit with gnuplot though), my last math classes are over 25 years old now … not easy !

    I’m delighted to discover what Maxima can do for me and feel eager to refresh and
    and expand my math notions and practice.

    Your tutorial could do that !

  19. Dear Antonio Cangiano,

    Excellent and Nice tutorial. Kindly proceed for higher computations , tensors, numerical simulations etc., if possible. It can be beneficial for researchers and students.
    Dr M Kanagasabapathy

  20. phobos says:

    How to use if condition inside for loop.
    I am using the following:

    for i from 1 thru 10 do (
    (if(imagpart(xvals[i]) = 0) then ab:makelist(xvals[i]),new:append(new,ab),k:k+1)

    But, the if condition also gets executed 10 times.. though clearly it is not the case in my program.

  21. KSO says:

    I’m trying to add random noise to a function, but the random() function only generates a single number, giving me an offset. I want my function to plot a Lorentzian curve, for example, but I want random white noise added to every point, not just one. I used the following function definition:


    and tried another


    All I get is a smooth Lorentzian curve with a random offset when I plot using plot2d, not random noise at every point.

    Does anyone know how to do this?

    • Kevin Gregson says:

      If anyone’s still interested in plotting random noise, this works:

  22. albert says:

    I think your introductory page is brilliant.
    There is however one aspect that might be improved. You could draw slightly more attention to the variables and the fact that they can contain any result. It took me a whole day 1) to realise one can do:

    a:1 ;
    b:2 ;
    a+b ;
    Or for that matter:
    I don’t propose to make your page longer! It is the careful selection of what is presented that makes it so good. It would suffice to make variables slightly more prominent in the examples.
    groetjes Albert

    1) Admittedly before I knew your introduction.

  23. Dante says:

    I don’t know why wxMaxima doesn’t solve my limit. I input the limit and it returns the same limit written with LaTeX :S I don’t knwo what I’m doing wrong.

    This is the limit i’m trying to solve:


  24. Ahmed Fasih says:

    In case anybody wants to do vector (or matrix) math, here’s a quick example on how to make them:

    u : transpose(matrix([x, y, z]));
    v : transpose(matrix([a, b, c]));

    Matrix/vector multiplication is done by the dot, ‘.’, syntax:

    transpose(u) . v;

    And of course you can do the usual symbolic manipulations:

    diff(sqrt(transpose(u) . v), x);

  25. […] to re-derive this approximation formula for an Archimedean spiral rather than a circle. I read a tutorial on using wxMaxima, then created a worksheet to chug through the derivation. The spiral may be composed of an […]

  26. mahtab says:

    What is different between Maxima and other softwares such as Matlab and Scilab?

    what is benefits and features of my called softwares?

  27. I could not get Maxima to do the folling job:
    I want to assign a=1,b=2,c=3,d=4,e=5
    it does not work
    Could someone show me how to do this?

  28. Robert Dodier says:

    Hi, thanks for the great tutorial. By the way, what tools did you use to compose this article? The fonts and coloring are very nice.

  29. Jim Mooney says:

    I tried some other popular packages, and they didn’t work properly for various reasons. (One looked good but wouldn’t paste, amd I don’t need to do All that retyping. Another threw errors. Others were horrible to install, especially for Windows.)

    This worked great, and easily, to include graphing, out of the box.

Leave a Reply