Subcribe

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):

8/2;
=> 4
8/2.0;
=> 4.0
2/6;
=> \displaystyle \frac{1}{3}
float(1/3);
=> 0.33333333333333
1/3.0;
=> 0.33333333333333
26/4;
=> \displaystyle \frac{13}{2}
float(26/4);
=> 6.5

As mentioned above, big numbers are not an issue:

13^26;
=> 91733330193268616658399616009
13.0^26
=> \displaystyle 9.1733330193268623\text{ }10^_{+28}
30!;
=> 265252859812191058636308480000000
float((7/3)^35);
=> \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
sqrt(81);
=> 9
log(%e);
=> 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(a^2+b^2);
=> \sqrt{113}
f(x):= x^2 -x + 1;
=> x^2 -x + 1
f(3);
=> 7
f(a);
=> 43
f(b);
=> 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)};
log10(10)
=> 1

Symbolic Calculations

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

factor(30!);
=> \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:

expand((x+3)^4);
=> \displaystyle x^4+12\,x^3+54\,x^2+108\,x+81

Simplify rational expressions:

ratsimp((x^2-1)/(x+1));
=> x-1

And simplify trigonometric expressions:

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

Similarly, we can expand trigonometric expressions:

trigexpand(sin(2*x)+cos(2*x));
=> \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:

tex(%);
=> $$-\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:

solve(x^2-4,x);
=> \displaystyle \left[ x=-2 , x=2 \right]
%[2]
=> x=2
solve(x^3=1,x);
=> \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,-10,10]);

2dplot.png

plot2d([x^2, x^3, x^4 -x +1] ,[x,-10,10]);

many_2dplot.png

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

3dplot.png

Limits

limit((1+1/x)^x,x,inf);
=> %e
limit(sin(x)/x,x,0);
=> 1
limit(2*(x^2-4)/(x-2),x,2);
=> 8
limit(log(x),x,0,plus);
=> -\infty
limit(sqrt(-x)/x,x,0,minus);
=> -\infty

Differentiation

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

Integration

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}}
integrate(%e^(-x^2),x,minf,inf);
=> \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)
fact(10);
=>  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]);

taylor.png

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.

Possibly related articles:

  1. 3 awesome free Math programs
  2. What kind of Math did they teach you?
  3. Refresh your High School Math skills

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


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

  1. [...] Essendo studente di ingegneria, mi trovo spesso nella necessità di utilizzare un CAS (Computer Algebra System) ovvero un programma in grado di eseguire calcoli numerici, simbolici, grafici e altre operazioni correlate. Il software più diffuso per effettuare questo tipo di operazioni è Mathematica il quale però è un software commerciale, così mi sono messo alla ricerca di un programma open source con funzionalità simili. Tale programma esiste e si chiama Maxima. Con esso è possibile svolgere tutta una serie di operazioni come derivazione, integrazione, risoluzione di sistemi di equazioni, grafici di funzioni in 2 e 3 dimensioni e molto altro ancora. Per facilitare l’utilizzo del programma è disponibile wxMaxima un comodo front-end grafico, che permette rapido accesso alle principali funzioni del programma. Di seguito trovate alcuni screenshots con qualche esempio. Il testo degli esempi è tratto dall’ottima guida: A 10 minute tutorial for solving math problems with Maxima. [...]

  2. Javed Alam says:

    I like the way you are presenting this material. I have used Maxima and Scilab in teaching a course on Computation. I am a big fan of Maxima. Scilab is OK but crashes a lot. ON the other hand Maxima is extremely solid with many options for the user interface. It is promoted as a symbolic math program but it can do most of the run of the mill numerical math. Here is the link to the course material I taught.

    http://www.eng.ysu.edu/~jalam/engr6924s07/

    Feel free to take any part of the material if you want to write more articles about math calculation using Maxima.Also any feed back from is highly welcomed.

  3. Dotan Cohen says:

    Very nice tutorial, Antonio. I’m signing up for your RSS feed.

    Tell me, is there a way to zoom and rotate the 3d graphs? Also, my graphs are not solid planes like your screenshots but rather grids. How does one make the planes solid? Thanks.

  4. zorzal says:

    Richard,
    Use assume(a>0);

  5. Jon says:

    Dotan,

    To make the graphs coloured and solid you could add [gnuplot_pm3d,true] to the end of the statement eg:

    plot3d(f(x,y), [x,-5,5], [y,-5,5],[gnuplot_pm3d,true]);

  6. BWB says:

    Re: Jacobus

    Better late than never?

    (%i1) find_root(subst( [h=d^2/(16*f),d=2000,s=2400], s=d/2*(sqrt((4*h/d)^2+1))+2*f*log((4*h/d)+sqrt((4*h/d)^2+1))),f,1,2400);
    (%o1) 421.811063853618

  7. J.C.Pizarro says:

    I’ve 2 issues here:

    FIRST: Halting problem in TM
    ——
    The below symbolic example doesn’t terminate after many minutes in maxima-5.14.0 although the human solution is f(x)-g(x)-h(x):

    factor(expand((f(x)-g(x)-h(x))^500));

    To fix this problem in the future: better
    artificial sustitution in the solving of
    factor or intelligent lazy computation as
    factor(expand(Alpha)) => Alpha.

    SECOND: Non-deterministic Memoization
    ——-
    With

    factor(expand((sqrt(x+a)+b)^10));

    i got once the imprecise solution

    10 b x^4 sqrt(x+a) + 120 b^3 x^3 sqrt(x+a) + … + 45 a^4 b^2 + a^5

    but i got many times sqrt(x+a)+b)^10 .

    I think that the maxima system
    uses memoization that remember some
    internal answers of previous computations
    but it’s non-deterministic.

  8. J.C.Pizarro says:

    axima 5.14.0 (with CLISP 2.41) has 2 symbolic bugs:
    * First bug: it doesn’t factor when it uses sqrt instead sqrt2 :
    (%i1) factor(expand((sqrt(x)+y)^2));
    2
    (%o1) y + 2 sqrt(x) y + x
    (%i2) factor(expand((sqrt2(x)+y)^2));
    2
    (%o2) (y + sqrt2(x))
    * Second bug: wrong result due to the sign: (y-x)^1000 instead of (x-y)^1000 :
    (%i3) factor(expand((x-y)^1000));
    1000
    (%o3) (y – x)

  9. magnus says:

    Is there any way to get nice looking latex fonts in the EuMathT notebook? For example, if one calculates >:integrate(x,x) one gets
    x^2
    —–
    2

    and this in not nice looking. How to get LaTeX fonts?

  10. Lim Ee Hai says:

    Seem like a good maths tool. Students of maths should welcome this tool. Nowadays, learners go for effective learning tools. This is a good target.

  11. Sylvia says:

    WOuld you know how to do this problem? I am extremely stuck!!! And confused!! The problem is Convert 400 ft/sec to mi/hr. I get how to convert the ft to mi but I am completely stuck on the sec to hr. I would really appreciate some help. :)

  12. Sylvia, try to replace ft with the amount of miles in a foot, and sec with the amount of hours in a second.

    1 ft = 1/5280 mi (a mile has 5280 feet)

    1 sec = 1/3600 hr (an hour has 3600 seconds)

    400 ft/sec = 400 * (1/5280 mi) / (1/3600 hr) = (400 * 3600)/5280 mi/hr = 272.72… mi/hr

  13. [...] the open source computer algebra system Axiom. Maxima has already been extremely well described on math-blog. I hope to do something similar for Axiom, but over several [...]

  14. [...] 又在linked的跳转中找到这个BLOG: A 10 minute tutorial for solving Math problems with Maxima [...]

  15. Bilge Tutak says:

    As far as I remember, if you change the fonts in the main screen to Greek, you can also see the symbols like %pi displayed.

    Great tutorial,

    Thanks.

  16. alfahd says:

    hi
    can any one help me to solve this question
    Given that U = {x : x is real numbers}, A = {x : x is positive integer}, B = {x : x is negative integers}, C = {x : x = , where a and b are integers with b 0}. Draw separate Venn diagrams for each of the following sets, shading those areas that represent the set.

    (a) M = {1, 3, 5 ,7 ,9 …..}

    (b) P = {x : x2 = 2}

    (c) Q = {x : (2 – x) > 3, x is integers}

    (d) R = {x : 2x = 0}

    (e) T = {x : x = 2πr, r is a positive integers, π is Pi}

  17. [...] 又在linked的跳转中找到这个BLOG: A 10 minute tutorial for solving Math problems with Maxima [...]

  18. yeswanth says:

    Sir,

    Would you please give the format or code for solving the Fredholm Integral eqn.

    g(r)= lambda*integral from 0 to infinity of
    f(x)*K(x,r)dx
    g(r) and K(x,r) being known.
    I tried the function ieqn(ie, unk, tech, n, guess), but I am unable to supply the required parameters seperately. It will be helpfull if you could illustrate it with an example.
    Thanks in advance
    yeswanthl@sify.com

  19. Malte says:

    A very awesome tutorial,
    make a lot of fun!

    Thank You.

  20. Giorgio says:

    This guide is exactly what a beginner need to have a look to Maxima in 10 minutes. I would be happy to find it for any software.
    I suggest you to add few lines in guide about GNU TeX macs and SAGE. It’s an important feature in my opinion, mainly for beginners, and I saw it only browsing the messages.
    Thank you very much.

  21. Gerry says:

    As the last comment was from ’07, just wanted to let you know your effort is still appreciated. About 2 days into this, and the main manual is terrible to learn from, even for syntax. Helped a little that I knew Lisp. Picked up a few new items from your examples.
    Thanks.

  22. Joseph says:

    Thanks for this great tutorial. I picked up enough in 10 minutes to know that Maxima is pretty awesome and worth learning well.

  23. [...] equations and integrals. It can also plot functions by enabling gnuplot from the command line. Anthony Cangiano has written a very useful [...]

  24. Martin Ettl says:

    Great tutorial!! Thanks for your effort!!!

  25. required says:

    Now if there only were a proper commenting and (gnu)plot-export functionality like in Maple and Mathematica..it’d be also usable.

  26. [...] Maxima Cheat Sheet (HTML web page) [...]

  27. Angelo says:

    Nice idea ! Wonderful program ! Bye angelo

  28. jane says:

    skeeeeen man

  29. Abdurrahman says:

    I am amazed with the use of Maxima software. I am becoming familiar with it. It solves many problems.
    It is difficult for me to understand many of the commands. I would like someone to help me in converting decimal numbers to binary numbers by using Maxima. Give me the commands used only.

    Thank you.

  30. noname says:

    Wow Man , Thank you for promoting open source software !

  31. This is a great alternative to expensive commercial CAS, like Mathematica. In fact, I wish there were more tutorials of this sort, thanks!

  32. Zxoch.m says:

    It’s so useful, thank you so much. I going to check paciently¡

    Best, Zxoch.m

  33. [...] pratik olarak nasıl kullanabileceğinizi görmek isterseniz ‘A 10 minute tutorial for solving Math problems with Maxima‘, ‘Maxima by Example’, ‘Symbolic Mathematics using Maxima‘ ve [...]

  34. Uriel Avalos says:

    Yeah, this tutorial is pretty awesome. As much as I like Maxima, it’s documentation sucks for high school and bachelor-level students… This is really great and needed… Maybe you should post a tutorial on how to program in Maxima — this will show it’s on par with mathematica…

  35. Gijs says:

    Hi Antonio,

    Many thanks for posting this, it saved me a lot of work (and in this case euros, because I didn’t need to buy a program :) )!

    Keep up the work and all the best,

    Gijs

  36. zslevi says:

    Nice summary.

  37. Francesc says:

    Hi
    i’m just wondering if maxima could solve numerical diferencial systems?
    i’m looking for a tutorial, anyone can help me?

  38. Lucas Gallindo says:

    Very good.

    Do you happen to know about any tutorial on optimization in maxima? (using numerical algorithms)

  39. phil says:

    excellent maxima intro!

  40. Mira says:

    ny suggestions on how to get Maxima to generate a surface of revolution; e.g., the surface formed between y=x^2, y=0 and x=6 is revolved about either axis?

    Thanks.

  41. abhijit says:

    What ever I did with pricy mathematica, I can do with maxima+TeXmacs. Goodbye mathematica, hello maxima. Thanks Antonio

  42. Rudolf Repges says:

    It is possible to generate plots of 3d vector fields with maxima?

  43. Hmm says:

    Maxima may be powerful, and very useful to career mathematicians, but the interface is pretty poor. It’s not intuitive and not easy to discover how to use things. At the least, you should use WxMaxima as a front-end, which gives it a decent graphical interface with common functions in menus. Even this needs a lot more polish, though.

  44. Kyle Thomas says:

    Noice! I love the free programs AND math

  45. John Simmonds says:

    Maxima is a very good option for someone who doesn’t have the amount of money required to buy a commercial CAS such as mathematica or maple

  46. Chris says:

    Many thanks for this. I’ve used Maple for a couple of years now, but am glad to see there’s a free option available!

  47. Mike says:

    Thanks for a most useful introduction to Maxima. The comments following it are overwhelmingly supportive, which encourages me to ‘test the water’ with a good chance of surviving a dense manual.

Leave a Reply