Getting started with Maxima in Fedora Linux

Photo by Roman Mager on Unsplash

Maxima is an open source computer algebra system (CAS) with powerful symbolic, numerical, and graphical capabilities. You can perform matrix operations, differentiation, integration, solve ordinary differential equations as well as plot functions and data in two and three dimensions. As such, it is helpful for anyone interested in science and math. This article goes through installing and using Maxima in Fedora Linux.

Installing Maxima

Maxima is a command line system. You can install Maxima from the official Fedora repository using the following command:

sudo dnf install maxima

You can then use Maxima from the terminal by invoking the command maxima.

Maxima session in gnome terminal in Fedora Linux
Maxima session in gnome terminal in Fedora Linux 34

Installing wxMaxima

wxMaxima is a document based interface for Maxima. To install it in Fedora Linux, use the following command:

sudo dnf install wxmaxima

You can launch wxMaxima either by invoking the command wxmaxima in the terminal or clicking its application icon from the app grid or menu.

wxMaxima session in Fedora Linux
wxMaxima session in Fedora Linux 34

Basic Commands

After calling maxima, you should see terminal output as in the figure above.

The (%i1) is the input label where you enter the commands. Command in Maxima is an expression that can span over many lines and is closed with a semicolon (;). The o labels denote the outputs. Comments are enclosed between /* and */. You can use the special symbol percent (%) to refer to the immediately preceding result computed by Maxima. If you don’t want to print a result, you can finish your command with $ instead of ;. Here are basic arithmetic commands in Maxima:

 (%i1) (19 + 7)/(52 - 2 * 13);
 (%o1)                                  1
 (%i2) 127 / 5;
                                       127
 (%o2)                                 ---
                                        5
 (%i3) float (127 / 5); 
 (%o3)                                25.4
 (%i4) 127.0 / 5;     
 (%o4)                                25.4
 (%i5) sqrt(2.0);
 (%o5)                          1.414213562373095
 (%i6) sin(%pi/2);
 (%o6)                                 1
 (%i7) abs(-12);
 (%o7)                                12
 (%i8) 2+3*%i + 5 - 4*%i;             /*complex arithmetic*/
 (%o8)                              7 - %i

To end the Maxima session, type the command:

quit();

Algebra

Maxima can expand and factor polynomials:

(%i1) (x+y)^3 + (x+y)^2 + (x+y);
                                3          2
(%o1)                    (y + x)  + (y + x)  + y + x
(%i2) expand(%);
          3        2    2      2                  3    2
(%o2)    y  + 3 x y  + y  + 3 x  y + 2 x y + y + x  + x  + x
(%i3) factor(%);
                          2                2
(%o3)           (y + x) (y  + 2 x y + y + x  + x + 1)

To substitute y with z and x with 5, refer the output label above and use the following command:

(%i4) %o3, y=z, x=5;
                                    2
(%o4)                     (z + 5) (z  + 11 z + 31)

You can easily manipulate trigonometric identities:

(%i1) sin(x) * cos(x+y)^2;
                                       2
(%o1)                        sin(x) cos (y + x)
(%i2) trigexpand(%);
                                                         2
(%o2)              sin(x) (cos(x) cos(y) - sin(x) sin(y))
(%i3) trigreduce(%o1);
                   sin(2 y + 3 x) - sin(2 y + x)   sin(x)
(%o3)              ----------------------------- + ------
                                 4                   2

You can also solve algebraic equations in one or more variables:

(%i1) solve(x^2+5*x+6);
 (%o1)                         [x = - 3, x = - 2]
(%i2) solve(x^3 + 1);
                  sqrt(3) %i - 1      sqrt(3) %i + 1
 (%o2)     [x = - --------------, x = --------------, x = - 1]
                        2                   2
(%i3) eqns: [x^2 + y^2 = 9, x + y = 3];
                              2    2
 (%o3)                      [y  + x  = 9, y + x = 3]
 (%i4) solve(eqns, [x,y]);
 (%o4)                 [[x = 3, y = 0], [x = 0, y = 3]]

Calculus

Define f to be a function of x. You can then find the limit, derivative and integral of the function:

(%i1) f: x^2;
                                       2
 (%o1)                                x
 (%i2) limit(f,x,0);
 (%o2)                                  0
 (%i3) limit(1/f,x,0);
 (%o3)                                 inf
 (%i4) diff(f, x);
 (%o4)                                2 x
 (%i5) integrate(f, x);
                                       3
                                      x
 (%o5)                                --
                                      3

To find definite integrals, slightly modify the syntax above.

 (%i6) integrate(f, x, 1, inf);
 defint: integral is divergent.
  -- an error. To debug this try: debugmode(true);
 (%i7) integrate(1/f, x, 1, inf);
 (%o7)                                 1

Maxima can perform Taylor expansion. Here’s the Taylor expansion of sin(x) up to order 5 terms.

(%i1) taylor(sin(x), x, 0, 5);
                                   3    5
                                  x    x
 (%o1)/T/                     x - -- + --- + . . .
                                  6    120

To represent derivatives in unevaluated form, use the following syntax.

(%i2) 'diff(y,x);
                                       dy
 (%o2)                                 --
                                       dx

The ode2 function can solve first and second order ordinary differential equations (ODEs).

(%i1) 'diff(y,x,2) + y = 0;
                                    2
                                   d y
 (%o1)                             --- + y = 0
                                     2
                                   dx
 (%i2) ode2(%o1,y,x);
 (%o2)                     y = %k1 sin(x) + %k2 cos(x)

Matrix Operations

To enter a matrix, use the entermatrix function. Here’s an example of a general 2×2 matrix.

(%i1) A: entermatrix(2,2);
 Is the matrix  1. Diagonal  2. Symmetric  3. Antisymmetric  4. General
 Answer 1, 2, 3 or 4 : 
 4;
 Row 1 Column 1: 
 1;
 Row 1 Column 2: 
 2;
 Row 2 Column 1: 
 3;
 Row 2 Column 2: 
 4;
 Matrix entered.
                                    [ 1  2 ]
 (%o1)                              [      ]
                                    [ 3  4 ]

You can then find the determinant, transpose, inverse, eigenvalues and eigenvectors of the matrix.

(%i2) determinant(A);
 (%o2)                                 - 2
 (%i3) transpose(A);
                                    [ 1  3 ]
 (%o3)                              [      ]
                                    [ 2  4 ]
(%i4) invert(A);
                                  [ - 2   1  ]
                                  [          ]
 (%o4)                            [  3     1 ]
                                  [  -   - - ]
                                  [  2     2 ]
(%i5) eigenvectors(A);
            sqrt(33) - 5  sqrt(33) + 5
 (%o5) [[[- ------------, ------------], [1, 1]], 
                 2             2
               sqrt(33) - 3         sqrt(33) + 3
       [[[1, - ------------]], [[1, ------------]]]]
                    4                    4

In the output label (%o5) the first array gives the eigenvalues, the second array gives the multiplicity of the respective eigenvalues, and the next two arrays give the corresponding eigenvectors of the matrix A.

Plotting

Maxima can use either Gnuplot, Xmaxima or Geomview as graphics program. Maxima package in Fedora Linux comes with gnuplot as a dependency, so Maxima uses gnuplot_pipes as the plotting format. To check the plotting format, use the following command inside Maxima.

get_plot_option(plot_format);

Below are some plotting examples.

(%i1) plot2d([sin(x), cos(x)], [x, -2*%pi, 2*%pi]);
Two dimensional plot of sin and cos functions.
2d plot using Maxima
(%i2) plot3d(sin(sqrt(x^2+y^2)), [x, -7, 7], [y, -7, 7]);
Three dimensional plot using maxima.
3d plot using Maxima
(%i3) mandelbrot ([iterations, 30], [x, -2, 1], [y, -1.2, 1.2],
             [grid,400,400]);
Plot of the Mandelbrot set.
The Mandelbrot Set

You can read more about Maxima and its capabilities in its official website and documentation.

Fedora Linux has plethora of tools for scientific use. You can find the widely used ones in the Fedora Scientific Guide.

Fedora Project community

17 Comments

  1. edier88

    A matlab clone?

    • Maxima is significantly older than Matlab and is more focused on symbolic mathematics (hence the name computer algebra system) than matrix manipulation (matlab’s original focus). You can read about its origins here https://en.wikipedia.org/wiki/Macsyma

      Maxima is more similar to Maple and Mathematica in the type of work it excels at than Matlab though I understand Matlab has added support for symbolic mathematics over time.

      • You Really Don't Want to Know

        Thanks for the notes on Macsyma and Octave. I was not sure whether Maxima was related nor exactly what niche Octave filled. I looked into Maple a couple of years ago. Too expensive. They have cheap versions for students and professors but not for alumni.

    • Cuvtixo D

      I’m not sure if this should be a response to your question or separate, but: Macsyma came out of MIT soon before Symbolics Inc. (the first dot-con) developed their LISP machines -computers that had LISP as the basis for the CPU. This is one of the projects that Richard Stallman was angry about, that founders stole from academics at MIT. MIT actually sold a license for this math software to the US Dept of Energy, which became Maxima. It’s not only older than Matlab and all the other math packages, it’s older than the IBM PC platform. Well, Stallman first tried coding for a LISP machine competitor (LMI), than gave up and started Free Software Foundation, GNU and all that. Symbolics went on to spin off “Macsyma”, which ultimately died around ’98,, and whose IP became part of a brief-lived effort to revive Symbolics, after they ceased making hardware and ported to the first 64-bit Alpha hardware. There was an effort made to make Macsyma a non-profit educational org, but the sole sponsor was not only not very mathematically literate at all, he was openly hostile to the concept of “Open Source”, and ended up donating millions to Harvard Math Dept instead. It was a sad death and the end of several careers.
      In the wake of this drama, the DOE made their version Open Source, I’m not sure if anyone appreciated the irony of this at the time. I haven’t checked up on the Wikipedia article, but I doubt it has a fraction of the drama behind the founding and death of Symbolics in which it played a role, and indirectly FOSS movements. It’s a little hard to hear someone asking if it’s a Matlab clone, when it’s a huge part of the story of the beginnings of modern software. Sort of like asking if a re-enactment of the Boston Tea Party was a Starbucks promotional event.

    • Cuvtixo D

      oops, I can’t edit my previous comment, but “dot-con” is a typo, not a commentary. Symbolics dot com was the first site of all the top-level domains ending in dot-com. The site itself has changed hands and is still around and has some interesting history explained. But again I don’t think the significance in computing history really comes through. It is the goliath against which Stallman flung his stone at the infancy of FOSS. The story of Symbolics was also studied as a business case at Harvard Business school for years. And (excuse the pun) symbolic of all businesses which put elegant technical solutions over customer relations and above meeting demand in the marketplace.

  2. egcp

    More of Mathematica clone. Octave would be a Matlab clone.

    • They are similar in functionality. However, I would not call it a clone as it is older than Mathematica.

  3. David

    There are typos in some of the command examples, when using Complex numbers. For example, “2+3%i + 5 – 4%i;” should be
    “2+3%i + 5 – 4%i;”. Otherwise this a great basic introduction, thank you very much for writing it up.

    • Thanks a lot. Yeah, looks like I missed the auto-correct done by WordPress. Anyway, I can see it’s been fixed now πŸ˜€. Glad you liked it.

  4. David

    Sorry, for some reason the asterisk for the multiply operation got dropped.

    • Yeah. WordPress likes to auto(in)correct things once in a while. I think I’ve fixed it. Thanks for spotting that. πŸ™‚

  5. laboratoire vulcain

    The Maxima version in Fedora 34 is the outdated 3.43.2 versus the new/official 3.45.1

    For Fedora, it should be better, as there are some issues/bugs with Gnuplot on Windows 10, issues not impacting the Linux world…

    see for example the Note on https://sourceforge.net/projects/gnuplot/files/gnuplot/5.4.2/

    Maxima is easy to learn, addressing many topics in math. I use Maxima for symbolic math and doing some programming/scripts for complicated problems.

    If I do not make a mistake, the outputs of the article are from Xmaxima and not wxMaxima, where you have LaTeX like displays.

    Very nice software!

    • So far, I haven’t come across a bug when using Maxima in Fedora 34. The outputs in this article are what they look like when we run the commands in the terminal. wxMaxima has a formatted display as well as menu options to run the commands, and I find it helpful when creating documents. Yeah, overall a really helpful software.

  6. Newton symbol?

Comments are Closed

The opinions expressed on this website are those of each author, not of the author's employer or of Red Hat. Fedora Magazine aspires to publish all content under a Creative Commons license but may not be able to do so in all cases. You are responsible for ensuring that you have the necessary permission to reuse any work on this site. The Fedora logo is a trademark of Red Hat, Inc. Terms and Conditions