Version 23 of Maxima

Updated 2004-08-18 15:58:45 by TV

Maxima [L1 ] is an open-source work-(much-)alike to Mathematica [L2 ]. It descends from Macsyma [L3 ]. Its default interface is constructed with Tk.

It's also: 1) a car, 2) a princess, 3) the plural of the Latin & Dutch "maximum"

and the name of an ancient place, e.g. Cloaca Maxima [L4 ]


TV I'm looking into maxima for reasons of lack of mathematica license, and because there are at leasthalf a dozen applications I find interesting for mathematical symbolic manipulation, including a tcl formula manipulator, physics problems, maybe my string simulator, (electronic) network analysis, maybe drawing certain graphs, etc, and a bit of mathematical recreation of course.

I've downloaded the windows version, (see above) june 2004, which works fine, and shows for isntance these pictures by just a few clicks:

http://82.168.209.239/wiki/maxima1.jpg

The welcome screen

http://82.168.209.239/wiki/maxima2.jpg

A Riemann surface 3D plot from the examples

In the bottom window, double click on the blue links to make them work.

The 3D plot is not a perspective projection with fixed aspect ratio, it is not in that way correct, but it works interactive (clicking the mouse on it and translating makes it sort of rotate. Use a menu option to chose a seperate plot window.

There might be a version with a nicer special fonts prettyprinter, maybe on linux, I didn't try (yet).

I'm making a page on Bwise combined with Maxima, which should be a very interesting combination. Sampled Signal Reconstruction in Tcl driven Maxima is a start to do decent sampling with a combined mathematical and tcl approach.

Also, I'm making a page on Calling Maxima from Tcl, which isn't trivial in general form, but quite possible it seems.


Tcl/Tk and Maxima

The latest version I tried has it's user interface based on Tk, and can open a normal tcl console window reporting

 info pa
 8.4.1

and allows normal things, including inspecting the maxima window widget hierarchy (5 packed widgets with reasonable names) opening new toplevels and opening files/sockets, and it appears to be so that there are a lot of maxima related tcl functions.

I'm looking into how that is.

Lars H: Can you perhaps report some more about what the programmatic Tcl interfaces to Maxima look like? (What is below mostly reports on the user interfaces to Maxima.) Is it merely that there is some "Maxima evaluate" command (argument is a Maxima command, which is sent to the Maxima engine and evaluated there), or is there a larger integration between the two? It would be really cool if the result of a Maxima command could be returned to Tcl and then used as an argument of the next Maxima command.

TV (7-21-'04) As an at least 'in principle' answer, maxima has a text interface for normal user interaction, which can be used like this from the tcl console:

 .maxima.text insert insert "DISPLAY2D:false;"
 CMeval .maxima.text

This will tell maxima to return the subsequent results in 1 dimensional (non-prettyprinted) form, which can at least be plucked from the text widget where it appears after calling CMeval.

Lars H: That is even slightly worse than I had feared. The CMeval (my "Maxima evaluate" above) doesn't even take the code to evaluate as an argument, but instead accesses a text widget directly. Pity. Tcl is in many ways very suitable for associative algebra, but one usually wants to have a commutative algebra package available to build upon. To my knowledge there is no such package for Tcl, but had there been a good interface to Maxima then that could have been it.

(Later.) I notice from what TV has written on Calling Maxima from Tcl that the communication between the Tcl interpreter and Maxima engine is really going over a socket, and that the format can be explicit Maxima commands/values. That is better, and probably about as good as one can hope for.


A bit of a tutorial

Lets say as excercise we want to find the roots to the equation

 [expr {$x*$x-1}]

I typed the stuff after the CX cursor (where X is the number of the line in the history), and pressed return, to define the function f of x:

 (C5) f(x):=x^2-1;
                                   2
 (D5)                          f(x) := x  - 1

The := defines the function, and it is printed in more or less normal mathematical form as a return value.

The semicolumn ';' at the end is obligatory, otherwise the parser will not recognize 'end of input', so one can enter more than one line as one command, ended by a ; and <Return>.

Now lets check for zeros in our function, by using the 'solve()' function, equating our function to zero, and solving that equation ofr 'x', type the stuff after the (C^), and Maxima returns the answer:

 (C6) solve(f(x)=0,x);
 (D6)                         [x = - 1, x = 1]

Some special keys:

   ^G      break the maxima interpreter, resume with :q to get back the normal prompt
           that also holds for resuming after an error
   alt-p   scroll up to previous command.
   %pi     short for PI in computations.

Maybe more interesting, we can solve the equations inverse symbolically:

 (C8) solve(f(x)=y,x);
 (D8)               [x = - SQRT(y + 1), x = SQRT(y + 1)]

Symbolic integration of our function:

 (C13) integrate(f(x),x);
                                              3
                                             x
 (D13)                                              -- - x
                                             3

The second argument of the function is the integration variable. The same for differentiation:

 (C14) diff(f(x),x);
 (D14)                                                2 x

lets see how invertable this is:

 (C15) integrate(diff(f(x),x),x);
                                                 2
 (D15)                                                x
 (C16) diff(integrate(f(x),x),x);
                                               2
 (D16)                                              x  - 1

When differentiating first, we lose the constant!

Fractions are handy:

 (C10) 1/6+1/4;
                                                5
 (D10)                                                --
                                               12

as are 'infinite' or arbitrary precision numbers:

 (C19) block([FPPREC:30],bfloat(10/6));
 (D19)                                 1.66666666666666666666666666667B0

30 is the number of computation digits, 10/6 is what we are computing, and the B0 inthe result appears to be the exponent, so pow(10,0) in this case.

For entering formulas, normal rules apply, mind the ordering of operators, or use braces:

 (C29)log(3*(%e^x))^2;
                                               2            x
 (D29)                                            LOG (3 %E )
 (C30) log((3*(%e^x))^2);
                                                   2 x
 (D30)                                           LOG(9 %E   )

Maxima automatically simplified the formula, which we can switch off (and back on, it's handy) by:

 (C39) SIMP:FALSE$
 (C40) log((3*(%e^x))^2);
                                                    x 2
 (D40)                                           LOG((3 %E ) )
 (C42) SIMP:TRUE$

Matrices can be entered row-wise, and symbolicaly, such as this 2 dimensional rotation matrix, with variable p as rotation angle:

 (C21) A:matrix([cos(p),-sin(p)],[sin(p),cos(p)]);
                                       [ COS(p)  - SIN(p) ]
 (D21)                                       [                  ]
                                       [ SIN(p)         COS(p)         ]

Multiplying the result with the orthonomal 2D basis vectors X1 and X2:

 (C58) A . matrix([1],[0]);
                                      [ COS(p) ]
 (D58)                                      [               ]
                                      [ SIN(p) ]
 (C59) A . matrix([0],[1]);
                                     [ - SIN(p) ]
 (D59)                                     [                ]
                                     [  COS(p)  ]

Automatic inverse (which could be simplified..):

 (C55) invert(A);
                      [             COS(p)                 SIN(p)              ]
                      [  -----------------   ----------------- ]
                      [           2             2               2         2    ]
                      [  SIN (p) + COS (p)   SIN (p) + COS (p) ]
 (D55)                      [                                               ]
                      [              SIN(p)                 COS(p)              ]
                      [ - -----------------  ----------------- ]
                      [            2              2               2         2    ]
                      [         SIN (p) + COS (p)  SIN (p) + COS (p) ]

A variable is set by:

 variable:value;

a function like:

 function(variable):=sin(x)^2+cos(x)^2;

unsetting is called kill, while stating the name of a stored entity prints it's content:

 (C18) c:255;
 (D18)                                       255
 (C19) c;
 (D19)                                       255
 (C20) kill(c);
 (D20)                                      DONE
 (C21) c;
 (D21)                                        C



Some more advanced / esoterical examples:

A tailor series expansion of the sinc function until degree 6:

 (C53) TAYLOR(sin(x)/x,x,0,6);
                                         2    4            6
                                        x    x           x
 (D53)/T/                            1 - -- + --- - ---- + . . .
                                       6    120          5040

Maxima can produce (la)tex formatted output for equations, such as:

  tex(integrate(1/(1+x^3),x));

produces this tex:

 $$-{{\log \left(x^2-x+1\right)}\over{6}}+{{\arctan \left({{2\,x-1
  }\over{\sqrt{3}}}\right)}\over{\sqrt{3}}}+{{\log \left(x+1\right)
  }\over{3}}$$

and this after cygwin provided pdflatex rendering of that result after prepending

 \documentclass{article}
 \begin{document}

and postpending:

 \end{document}

to it, the adobe captured page looks like decent scientific text formulas:

http://82.168.209.239/wiki/equa1.jpg

It should be possible to automate this, maybe even with a bwise automation graph.


[ Category Mathematics | Category Application ]