Maxima Overview

Burkhard Bunk
30.11.2022
Maxima version: 5.42post
wxMaxima version: 19.11.0

Contents

Documentation
Invocation, Help
Commands and Expressions
Names
Assignment
Lists
Evaluation
Substitution
Functions
Simplification
- Polynomials
- Rational functions
- Roots
- Logarithms
- Trigonometric functions
- Factorials, Binomials, Gamma functions etc
Complex Numbers
Number Theory
Limit
Differentiation
Integration
Sums and Products
Series Expansion
Equations
Ordinary Differential Equations
Special Functions
Vectors and Matrices
Properties
Graphics
I/O
Control Structures
Scripts
wxMaxima
Documentation and Publications
Appendices
- Startup Scripts
- Command display and session log
- Checking the installation
- Experimental solver to_poly_solve()
- More plot details
- GCL
TO DO

top

Documentation

/usr/share/doc/maxima-doc/html/intromax.html    introduction
/usr/share/doc/maxima-doc/html/maxima_toc.html  full help
top

Invocation, Help

Text mode:
      unix> maxima
      interrupt a maxima calculation with
            <CTRL>-G
      terminate maxima with
            quit();

GUI:
      unix> xmaxima
      unix> wxmaxima

Help:
      GUI ->Help
      descripe(string);
      ? string;               /* note the space after "?" */
A perfect way to restart maxima does not exist (see mailing list), use
      reset();
      kill(all);
top

Commands and Expressions

Terminate commands with ";" or "$" (quiet mode).

command prompts:  (%i1)  (%i2)  ..
output labels:    (%o1)  (%o2)  ..

Previous result:              %
Former output, e.g. (%o5):    %o5
Redo command, e.g. (%i5) :    ''%i5;

Operators:              + - * / ^ **  ( )  ! !!
Comparison:             = # > < >= <=           /* "#" is "not equal" */
Logical:                and or not

Text strings are written as "text".
top

Names

Names consist of letters, digits, % (percent) and _ (underscore). Letters are case sensitive, but predefined names are mapped to upper case. Special characters (other than "%" and "_") are allowed after declaring them alphabetic as in
      declare("$", alphabetic);
Pre-defined constants:
      %i %pi %e true false
      %gamma      Euler's constant
      %phi        (1 + sqrt(5))/2
      inf         real infinity
      minf        real (-infinity)
      infinity    complex infinity
Pre-defined functions:
      sqrt  log  exp
      sin ..  asin ..
      sinh ..  asinh ..
      gamma beta
      zeta
      binomial factorial
      mod  floor
      ..
Reserved names:
      integrate   next        from        diff            
      in          at          limit       sum             
      for         and         elseif      then            
      else        do          or          if
      unless      product     while       thru            
      step                                                                     
Manage user-defined variables:
      values                  list of all user defined variables
      remvalue(var);          delete the value of var
      remvalue(all);          delete the values of all variables
top

Assignment

Assignment: :     (without "="!)
            ::    ??
            :=    defines a function
            ::=   defines a macro

Unassign names:
      kill(name1, name2, ..);
      kill(all);

      xmaxima:    ->File ->Restart
      wxMaxima:   ->Maxima ->Restart maxima
top

Lists

      lst: [el1, el2, ...];         contruct list explicitly
      lst[2];                       reference to element by index
                                          (starting from 1)

      cons(expr, alist);            prepend expr to alist
      endcons(expr, alist);         append expr to alist
      append(list1, list2, ..);     merge lists
      makelist(expr, i, i1, i2);    create list with control variable i
      makelist(expr, x, xlist);     create list with x from another list     

      listp(expr);                  true if expr is a list, else false
      length(alist);                returns #elements

      map(fct, list);               evaluate a function of one argument
      map(fct, list1, list2);       evaluate a function of two arguments
top

Evaluation

- automatic

Many expressions are evaluated automatically: before they are processed, substitutions and obvious simplifications are performed.

- explicit

Sometimes, this should be prevented (e.g. when defining a differential equation), in other cases, an extra evaluation is required (e.g. after changing an item in an expression):
      'expr              don't evalute
      ''expr             do evaluate
e.g.
      a: b+c;
            c + b
      b:5$
      a;
            c + b
      ''a;
            c + 5
      'b + c;
            c + b
Evalutate variables, based on equations:
      at(expr, var=ex);
      at(expr, [var1=ex1, var2=ex2, ..]);

e.g.  at(diff(sin(x), x), x=%pi);
            -1      
Evaluate with additional settings/flags:
      ev(expr, arg1, arg2...);
      expr, arg1, arg2, ...;        same in short
            args: numer
                  float
                  bfloat
                  simpsum
                  eval
                  ...
Many of the evalutation switches (e.g. numer, simpsum) are actually flags, which are false by default, but can be enabled for subsequent use.

- numerical

Numerical evaluation is triggered by decimal numbers in expressions, but note that a dot alone doesn't make it: sqrt(2.) is not evaluated, but sqrt(2.0) is.
      float(expr);                  evaluate to floating point number
      expr, numer;                  return numerical result
      numer: true;                  numerical evaluation on (default: false)

      fpprec: digits;               precision of big floats (default: 16)
      fpprintprec: digits;          no. of printed digits
      bfloat(expr);                 evaluate to big float

example:
      fpprec: 30;
      sin(%pi);                     => 0
      sin(float(%pi));              => 1.2246063538223773E-16
      sin(bfloat(%pi));             => 1.69568553207377992879174029388B-31
Note: WxMaxima, with output format set to xml, diplays long numbers with a shortcut - compare the output of
      bfloat(%pi), fpprec:1000;
top

Substitution

Functions which perform substitution, with increasing level of sophistication:
      subst(..)         syntactic, symbols and complete sub-expressions only
      ratsubst(..)      similar, but employs some algebra
      at(..)            evaluation, based on equations
      ev(..)            evaluation, with equations, flags etc.
subst(..) and ratsubst(..) in more detail:
      subst(ex, var, expr);         substitute ex for var in expr
      subst(var=ex, expr);          same
      subst([var1=ex1, var2=ex2,..], expr);     multiple substitutions

      ratsubst(ex, var, expr);      substitute ex for var in expr

      subst(s, a+b, a+b+c);
            c + b + a
      ratsubst(s, a+b, a+b+c);
            s + c
      subst(1-cos(x)^2, sin(x)^2, sin(x)^4 - 5*sin(x)^2);  
               4                2
            sin (x) - 5 (1 - cos (x))
      ratsubst(1-cos(x)^2, sin(x)^2, sin(x)^4 - 5*sin(x)^2);  
               4           2
            cos (x) + 3 cos (x) - 4
top

Functions

Function definition, basic form:
      func(x) := sin(x)/x;
      radius(x,y) := sqrt(x^2 + y^2);
Alternative form:
      define(f(x), expr);           /* expr is always evaluated */
      define(f(x,y), expr);         /* etc */
More complicated function definitions can be formulated with the block(..) construct.

top

Simplification

top

Polynomials

      factor(expr);           factorise polynomials (over integers only)
      expand(expr);           expand polynomials
      ratexpand(expr);        same (more efficient algorithm)

      expandwrt(expr, x, ..); expand w.r.t. specified variables
      coeff(expr, x, n);      coefficient of x^n in expr
      ratcoef(expr, x, n);    same, but simplifies expr first

      divide(pol1, pol2);     polynomial devision (with remainder)
      quotient(pol1, pol2);   quotient of polynomial devision
      remainder(pol1, pol2);  remainder of polynomial division

      realroots(pol, tol);    numerical approx. to all real roots
      realroots(pol);         tol = rootsepsilon (default: 1e-7)
      allroots(pol);          numerical approx. to all complex roots
top

Rational functions

      ratsimp(expr);          put on common denominator,
                                    cancel factors,
                                    expand numerator and denominator
      fullratsimp(expr);      repeated application of `ratsimp'

      factor(expr);           same as `ratsimp', but returns numerator and
                                    denominator in factored form         

      expand(expr);           expand numerator and denominator, split numerator
                                    (no common denominator)
      ratexpand(expr);        put on common denominator,
                                    cancel factors,
                                    expand numerator and denominator,
                                    split numerator
      ratdenomdivide: false;  don't split numerator (same as ratsimp?)

      num(expr);              numerator of rational expression
      denom(expr);            denominator

      facsum(expr, var, ..)   expand w.r.t. specified variables
      facsum_combine: false;  split numerator

      partfrac(expr, var);    partial fraction decomposition

examples:
      ratsimp(a/b + c/d);
            a d + b c
            ---------
               b d

      (x-1)/(x+1)^2 - 1/(x-1);
             x - 1       1
            -------- - -----
                   2   x - 1
            (x + 1)
      ratexpand(%);
                    4 x
            - ---------------
               3    2
              x  + x  - x - 1
      factor(%);
                    4 x
            - ----------------
                             2
              (x - 1) (x + 1)


      r: (u+v)^2*u/((u^2-v^2)*v);
                           2
                  u (v + u)
                  -----------
                      2    2
                  v (u  - v )

      ratsimp(r);
                    u v + u
                  - --------
                     2
                    v  - u v

      factor(r);
                    u (v + u)
                  - ---------
                    v (v - u)

      ratexpand(r);
                        2
                       u         u
                  - -------- - -----
                     2         v - u
                    v  - u v

      s: a*b/(c*d+c*e) + f*b/(c*d+c*e);
                     b f         a b
                  --------- + ---------
                  c e + c d   c e + c d
      factor(s);
                  b (f + a)
                  ---------
                  c (e + d)
      ratsimp(s);
                  b f + a b
                  ---------
                  c e + c d
Notes:
the following appear to be equivalent:
      ratsimp(expr);          and   ratexpand(expr), ratdenomdivide: false;
      ratsimp(expr), factor;  and   factor(expr);
but factor(expr) does not understand algebraic!

Summary: simplify rational functions with ratsimp(expr), possibly combined with factor and/or algebraic. Use ratexpand(expr), possibly with algebraic, if you prefer to split the numerator.

In the complex case, try e.g.

      gfactor(expr);                      factorise over integers and %i
      partfrac(gfactor(expr)), var);      partial fractions with complex roots
top

Roots

      rootscontract(expr);                products of roots -> roots of products
      ratsimp(expr), algebraic;           rationalise denominators

      radcan(expr);                       canonical form, involving roots, logs,
      radcan(expr), algebraic;                   and exponentials
examples:
      ex: 1/(sqrt(a)+sqrt(b));
                    1
            -----------------
            sqrt(b) + sqrt(a)
      ratsimp(ex), algebraic;
            sqrt(b) - sqrt(a)
            -----------------
                  b - a

      sqrt(x^2);
            abs(x)
      sqrt(x^2), radexpand:all;
            x
      
In some cases, sqrtdenest can disentangle nested square roots:
      load(sqdnst);
      sqrtdenest(expr);
e.g.
      sqrt(sqrt(7)+ 4);
            sqrt(sqrt(7) + 4)
      sqrtdenest(%);
            sqrt(7)      1
            ------- + -------
            sqrt(2)   sqrt(2)
      factor(%);
            sqrt(7) + 1
            -----------
              sqrt(2)
top

Logarithms

      logexpand:all;                enables automatic expansion of products

      logcontract(expr);            contracts sums of logs to logs of products
                                          and _integer_ multiples of logs to
                                          logs of powers

      radcan(expr);                 canonical form, involving roots, logs,
      radcan(expr), algebraic;             and exponentials
examples:
      log(a^b);
            log(a) b

      log(a*b), logexpand:all;
            log(b) + log(a)

      logcontract(2*log(a) + 3*log(b));
                 2  3
            log(a  b )
top

Trigonometric functions

      trigsimp(expr);         use sin(x)^2 + cos(x)^2 = 1 etc
      trigexpand(expr);       use addition theorems etc
      trigreduce(expr);       powers -> multiple arguments
                              products -> sums
      trigrat(expr);          simplify rational expressions of trigonometric
                                    functions as well as linear arguments
                                    involving %pi/n
      halfangles:true;        replace half angles by roots

      exponentialize(expr);   trig/hyperb -> exponentials
      demoivre(expr);         complex exponentials -> trig (not hyperb)

      logarc(expr);           arc trig/hyperb -> logarithms
trigexpand is a flag as well (and an evflag), but the other trigX aren't!

trigsimp(..) in combination with roots is tricky:

      trigsimp(sqrt(sinh(x)^2 + 1));
            cosh(x)
      trigsimp(sqrt(cosh(x)^2 - 1));
            sqrt(cosh(x) - 1) sqrt(cosh(x) + 1)
instead of the expected abs(sinh(x)). It does not work for sin() and cos(x) either. Is this caused by abs(..)?
?HOW TO

There is no command to convert real exponentials to hyperbolic functions - use ratsubst(..) instead.

Examples:

      sin(x/2), halfangles;
            sqrt(1 - cos(x))
            ----------------
                sqrt(2)
?HOW TO:
      sin(x) + cos(x) = sqrt(2) * sin(x + %pi/4)
      try exponentialize(...)
?HOW TO
      ex1: cos(x) + cos(y);
      ex2: 2 * cos((x+y)/2) * cos((x-y)/2);
ex2 -> ex1:
      trigreduce(ex2), ratsimp;
or    trigrat(ex2);
ex1 -> ex2 ??
logarc examples:
      asinh(x), logarc;
                      2
            log(sqrt(x  + 1) + x)
      
      acosh(x), logarc;
                  sqrt(x + 1)   sqrt(x - 1)
            2 log(----------- + -----------)
                    sqrt(2)       sqrt(2)
      %, logcontract, expand, rootscontract;
                      2
            log(sqrt(x  - 1) + x)
top

Factorials, Binomials, Gamma functions etc

      minfactorial(expr)      combines factorials with integer offset
      factcomb(expr)          combines factorials with factors
      gamma_expand: true      expand gamma(z+n) and gamma(z-n)
      beta_expand: true       expand beta for arguments z+n and z-n
      makegamma(expr)         transforms binomial, factorial,
                              and beta functions into gamma functions
For products involving these functions with integer offsets, try makegamma(..) in combination with gamma_expand: true

top

Complex Numbers

      rectform(z)             a + %i*b
      conjugate(z)
      realpart(z) 
      imagpart(z) 
      polarform(z)            |z|*e^(%i*phi)
      cabs(z)                 |z|
      carg(z)                 polar angle phi in (-%pi, %pi] 
top

Number Theory

Compute the prime factorisation of a number:
      factor(n)               basic method
      ifactors(n)             more efficient algorithm
      ifactor_verbose: true   show details
top

Limit

      limit(f(x), x, a);
      limit(f(x), x, a, dir);       direction dir = plus, minus
top

Differentiation

      diff(expr, x);
      diff(expr, x, n);       /* n-th derivative */
      diff(expr, x, 1, y, 1); /* mixed partial derivative */
Convert the derivative to a function with define(..):
      f(x) := sin(x);               /* works */
      diff(f(x), x);
            cos(x)                  /* ok */
      g(x) := diff(f(x), x);        /* doesn't work */
      define(g(x), diff(f(x), x));
            g(x) := cos(x)          /* works */
Compute the derivative at a specific value with at(..):
      at(diff((x-a)^2, x, 2), x=a);
            2
top

Integration

      integrate(f(x), x);           indefinite integral
      integrate(f(x), x, a, b);     definite integral
      defint(f(x), x, a, b);        same
      ldefint(f(x), x, a, b);       same, but taking limits at the boundaries
Examples:
      assume(a>0)$
      declare(a, noninteger)$
      facts(a);
            [a > 0, kind(a, noninteger)]
      integrate(x^a * exp(-x), x, 0, inf);
            gamma(a + 1)
      kill(all)$
      facts();
            []
      integrate(1/(a - cos(x)), x, 0, %pi);

      Is  (a - 1) (a + 1)  positive, negative, or zero? pos;
                2
      Is  sqrt(a  - 1) - a  positive or negative? neg;
                2
      Is  sqrt(a  - 1) - a + 1  positive, negative, or zero? pos;
          !      2         !
      Is  !sqrt(a  - 1) + a! - 1  positive, negative, or zero? pos;

                          2
              2 %pi sqrt(a  - 1) - 2 %pi a
            - ----------------------------
                         2         2
              2 (a sqrt(a  - 1) - a  + 1)

      ratsimp(%), algebraic;

                %pi
            ------------
                  2
            sqrt(a  - 1)
top

Sums and Products

Sums are defined with sum(..) and evaluated (symbolically) with simpsum:
      sum(expr, n, n1, n2);
      ev(sum(...), simpsum);        sum and simplify
      sum(...), simpsum;            same in short
      simpsum: true;                enable summations
Example:
      sum(k^2, k, 1, n);
                                     n
                                    ====
                                    \      2
                                     >    k
                                    /
                                    ====
                                    k = 1
      %, simpsum;
                                   3      2
                                2 n  + 3 n  + n
                                ---------------
                                       6
The same is achieved with
      sum(k^2, k, 1, n), simpsum;
or
      simpsum: true;
      sum(k^2, k, 1, n);
Within a function definition, the ev(..) command is used to force the summation. The following example computes the partial sum of the harmonic series and returns the result as a floating point number:
      Harm(n) := ev(sum(1/k, k, 1, n), simpsum, numer);
In the same way, products are defined with product(..) and evaluated (symbolically) with simpproduct:
      product(expr, n, n1, n2);
      ev(product(expr, n, n1, n2), simpproduct);
top

Series Expansion

      powerseries(expr, var, point);      symbolic, possibly infinite
      taylor(expr, var, point, order);    truncated at given order

      niceindices(expr);                  rewrite symbolic sums
Expansion in several variables:
      taylor(expr, [x_1, x_2], a, n);           around x_i = a 
      taylor(expr, [x_1, x_2], [a_1, a_2], n);  around x_i = a_i
Extract coefficients with coeff(..), e.g.
      ser: taylor(exp(x), x, 0, 10);
      coeff(ser, x, 3);
            1
            -
            6
      makelist(coeff(ser, x, i), i, 0, 5);
                   1  1  1    1
            [1, 1, -, -, --, ---]
                   2  6  24  120
top

Equations

Equations (single or systems) are solved by solve.
      solve(eqn, var);
      solve([eqn1, eqn2, ..], [var1, var2, ..]);
It returns a list of solutions resp. solution vectors.
Examples:
      sol: solve(x^2 + p*x + q, x);
                   sqrt(p  - 4 q) + p      sqrt(p  - 4 q) - p
            [x = - ------------------, x = ------------------]
                           2                       2
      x1: x, sol[1];
              sqrt(p  - 4 q) + p
            - ------------------
                      2
      x2: x, sol[2];
              sqrt(p  - 4 q) - p
            - ------------------
                      2

      eqn1: x + y = 4;
            y + x = 4
      eqn2: x - y = 2;
            x - y = 2
      sol: solve([eqn1, eqn2], [x,y]);
            [[x = 3, y = 1]]
      x, sol;
            3
      y, sol;
            1
Check:
      map(is, ev([eqn1, eqn2], sol));
            [true, true]
Maybe ev(..) needs more flags (e.g. ratexpand).

Check multiple solutions (equation is formulated as f(x) = 0):

      f(x):= x^2 + 2*b*x + c;
                     2
            f(x) := x  + 2 b x + c
      sol: solve(f(x), x);
                         2                     2
            [x = - sqrt(b  - c) - b, x = sqrt(b  - c) - b]
      map(f, map(rhs, sol)), expand;
            [0, 0]
?HOW TO:
      solve(sin(x) + cos(x) = 1/2, x);

      eqn: sin(x) + cos(x) = 1/2;
      solve(eqn, x);                no success

      eqnx: exponentialize(eqn);
      sol: solve(eqnx, x);          solution in terms of complex logs

      ratsimp(sol);
      %, numer;

      rectform(sol);                imaginary parts are obsolete
      ratsimp(%);                   nicer formula
      %, numer;
?HOW TO:
      solve(s + sqrt(1-s^2) = 1/2, s);

      solveradcan: true;            doesn't help here
                                    (solve calls radcan)

      eq1: s + r = 1/2;             aux variable r = sqrt(1 - s^2) > 0
      eq2: r^2 = 1 - s^2;
      solve([eq1, eq2], [s, r]);
                    sqrt(7) - 1      sqrt(7) + 1
            [[s = - -----------, r = -----------], 
                         4                4
                  sqrt(7) + 1        sqrt(7) - 1
             [s = -----------, r = - -----------]]
                       4                  4
Solution is s = (1 - sqrt(7))/4 .

?HOW TO:

      solve([sqrt(x) + y = 0, sqrt(x) = 1], [x, y]);
            []
      eliminate([sqrt(x) + y = 0, sqrt(x) = 1], [x]);
            [1]                     ??? BUG ???
      eliminate([sqrt(x) + y = 0, sqrt(x) = 1], [y]);
            [ sqrt(x) - 1 ]         ok
Note that eliminate() uses resultant(), which is supposed to work with polynomials.
Eliminate variables from a set of (polynomial?) equations:
      eliminate([eqn1, eqn2, ..], [var1, var2, ..]);

to_poly_solve

This is a new solver package, see appendix.
      eqn: sin(x) + cos(x) = 1/2;

      to_poly_solve(eqn, x);        /* auto-loads the package */
            %union{...}
or
      load(to_poly_solve);          /* manual load */
      sol: %solve(eqn, x);          /* alias for to_poly_solve */
            %union{...}
      first(sol);                   /* extract solutions */
      second(sol);
The set of solutions is returned as a %union. Extract single solutions (explicit equations) with commands like first, second, .., tenth, last, rest.

Numerical solution

      find_root(expr, x, a, b)
For polynomials: see realroots(pol), allroots(pol).

top

Ordinary Differential Equations

ode2

Try to solve general ODEs of first or second order with ode2:
      ode2(eqn, y, x);

E.g. eqn of 2nd order:
      eqn: 'diff(x,t,2) + r*'diff(x,t)^2 = 0;
general solution, with constants of integration %k1, %k2:
      sol: ode2(eqn, x, t);
                      log(r t + %k1 r)
                  x = ---------------- + %k2
                             r
impose initial conditions:
      ic2(sol, t=0, x=x0, 'diff(x,t)=v0), logcontract, ratexpand;
                           log(r t v0 + 1)
                  x = x0 + ---------------
                                  r
convert solution equation to a function:
      define(x(t), rhs(%));
[TO DO: for the same deqn with exponent 2 -> 3, ic2() fails to solve for the initial conditions. This looks like a problem with solve...]
Boundary conditions are imposed with bc2(..).
For an equation of first order, the initial conditions are specified with ic1(..).

desolve

Solve a linear ODE with desolve (using Laplace transformation):
      eqn: 'diff(f(x), x) = 2*f(x);       /* linear ODE of 1st order */
      sol: desolve(eqn, f(x));
                          2 x
            f(x) = f(0) %e      
[Note the different format of derivatives in the equation.]
Initial values at x = 0 can be imposed with atvalue before calling desolve:
      eqn: 'diff(f(x), x) = 2*f(x);
      atvalue(f(x), x=0, k);              /* initial value at x=0 */
      sol: desolve(eqn, f(x));            /* solution as an equation */
                       2 x
            f(x) = k %e
      define(f(x), rhs(%));               /* solution function */
                        2 x
            f(x) := k %e
An example of second order:
      eqn: 'diff(f(t), t, 2) + r*'diff(f(t), t) + f(t) = sin(omega*t);
      atvalue(f(t), t=0, 1);
      atvalue('diff(f(t), t), t=0, 0);

      desolve(eqn, f(t));     /* omega nonzero, -2 < r < 2 */

      define(f(t), rhs(%));
      plot2d(ev(f(t), omega=1.1, r=0.1), [t, 0, 100]);
A linear system is solved with desolve as follows:
      eqn1: 'diff(f(x), x) = c*f(x) - g(x);
      eqn2: 'diff(g(x), x) = c*g(x) + f(x);
      atvalue(f(x), x=0, 1);
      atvalue(g(x), x=0, 0);

      sol: desolve([eqn1, eqn2], [f(x), g(x)]);

      define(f(x), rhs(sol[1]));
      define(g(x), rhs(sol[2]));
      c: 0.1;
      plot2d([parametric, f(x), g(x), [x, 0, 10]]);

desolve requires that the inverse Laplace transform (ilt) is applied to a rational function with a denominator of first or second order.

top

Special Functions

See section on "Special Functions" in the Maxima manual.

Gamma function

      gamma(z)             # Euler's gamma function
      log_gamma(z)
      psi(z)               # log. derivative
      %gamma               # Euler's constant (0.5772..)
      gamma_expand: true   # simplify gamma(z+n) and gamma(z-n)

      beta(x,y)            # Euler's beta function
      beta_expand: true    # simplify beta(x+n,y) etc

Zeta function

      zeta(n)              # Riemann's zeta function
It is implemented numerically.
Exact values are known for even integers ≥ 2 (if zeta%pi: true) and for integers ≤ 0 .

Error function

      erf(z)
      erfc(z)
top

Vectors and Matrices

Vectors are represented by lists.
Definition and operations:
      x: [x1, x2, x3];
      y: [y1, y2, y3];
      s * x + t * y;
      x . y;                  /* scalar product */
      load("vect");
      express(x ~ y);         /* 3d cross product */
Matrix construction:
      A: matrix([a, b, c], [d, e, f], [g, h, i]);     /* (3x3) matrix */
      u: matrix([x, y, z]);                           /* row matrix */
      v: transpose([r, s, t]);                        /* column matrix */

      ident(n);               /* (nxn) unit matrix */
      diagmatrix(n,x);        /* (nxn) diagonal matrix diag(x,..,x) */
      zeromatrix(m,n);        /* (mxn) zero matrix */
      ematrix(m,n,x,i,j);     /* (mxn) matrix with M[i,j]=x, 0 elsewhere */

      addrow(M, row, ..);     /* add row(s) (lists or vectors) */
      addcol(M, col, ..);     /* add column(s) (lists or vectors) */

      B: A;                   /* matrix assignment (new name/pointer) */
      B: copymatrix(A);       /* copy matrix (new storage) */
Reference to matrix elements etc:
      u[1,2];                 /* second element of u */
      v[2,1];                 /* second element of v */
      A[2,3];   or  A[2][3];  /* (2,3) element */
      A[2];                   /* second row of A */
      row(A,i);               /* i'th row of A */
      col(A,i);               /* i'th column of A */
Element by element operations:
      A + B;      A - B;
      A * B;      A / B;
      A ^ s;      s ^ A;
Matrix operations:
      A . B;                  /* matrix multiplication */
      A ^^ s;                 /* matrix exponentiation (including inverse) */

      transpose(A);
      determinant(A);
      invert(A);
      mat_trace(A);           /* trace of square matrix */

      eigenvalues(A);   or eivals(A);
      eigenvectors(A);  or eivects(A);      
top

Properties

      assume(pred);           predicate `pred' e.g. a > 0, equal(b,3), notequal(c,0)
      is(expr);               check whether expr is true, based on assumptions
      forget(pred);           remove `pred' from assume database

      features                list of mathematical properties
      declare(var, prop);
      remove(var, prop);

      facts(item);            list properties associated with item
      facts();                list all properties

      domain:real             default
      domain:complex
Examples:
      facts(a);               list of properties involving a
      forget(facts());        remove all properties (but not the features?)
      forget(facts(a));       remove all properties (not features?) involving a
kill(all) clears the facts database (among other things).

top

Graphics

      plot2d(expr, range);                /* one curve */
      plot2d([expr1, expr2], range);      /* two curves */
      plot2d([parametric, expr1, expr2, range]);         /* parametric */
      plot2d([discrete, xlist, ylist]);                  /* polygon */
      plot2d([discrete, xlist, ylist], [style, points]); /* points */
examples:
      plot2d(sin(x), [x, 0, 10]);
      plot2d(tan(x), [x, 0, 10], [y, -2, 2]);   /* truncate vertically */
      plot2d([8*sin(x), exp(x)], [x, -2, 2]);
      plot2d([parametric, t*cos(t), t*sin(t), [t, 0, 10]]);

      plot2d(sin(x), [x, 0, 10],  [gnuplot_term, ps],
            [gnuplot_out_file, "filename"]);    /* write PS file */

      plot3d(expr, range1, range2);       /* 3D mesh plot */
example:
      plot3d(sin(x)^2 * sin(y)^2, [x, -2, 2], [y, -2, 2]);

More details in an appendix and in section 12 of the Maxima manual.

top

I/O

Console interaction:
      print("text");
      print(expr1, expr2, ..);
      disp(expr1, expr2, ..);
      display(expr1, expr2, ..);

      z: read("what is z?");              /* terminate reply with ; */
Read/write data (in matrix or list form) from/to a file (space-separated numbers):
      load("numericalio");

      read_matrix("filename");
      write_data(matrix, "filename");

      read_nested_list("filename");
      write_data(list, "filename");
File search and display:
      file_search("filename");      check for the existence of a file, using
                                    file_search_maxima etc as search paths
      file_search("filename",["path/"]);  use specified path
                                          (relative or absolute path)
      file_search_maxima            search path list, for load etc
      file_search_usage             search path list, e.g. for printfile
      printfile("filename");        display contents of file

e.g. prepend a directory as follows:

      file_search_maxima: cons("/home/me/work/", file_search_maxima);
Notes:
o terminate path elements with /
o It appears that the current working directory (where maxima was started) is always searched first. top

Control Structures

      for var: first step incr thru limit do body
      for var: first step incr while cond do body
      for var: first step incr unless cond do body

      if cond then body
      if cond then body1 else body2

      return(expr);         /* abnormal termination of the "for" loop */
step 1 can be omitted.
body is a single command or a comma separated list of commands.
for returns done upon normal termination.
if returns the last result of the executed commands or false.
The following example computes sqrt(10) to floating point precision:
      x: 1.;
      for n: 1 thru 10 do
            (x0: x, x: .5*(x + 10./x), if x = x0 then return(x));
In this example, the control variable is obsolete and can be omitted:
      x: 1.;
      do (x0: x, x: .5*(x + 10./x), if x = x0 then return(x));
top

Scripts

      /* .. */                      comments in script
Run script in maxima:
      batch("filename");            run maxima commands from file
      batchload("filename");        same, in quiet mode
      load("filename");             run maxima and lisp code from file
Run script from the command line:
      unix> maxima -b filename
top

wxMaxima

Greek letters

Variables starting with % are displayed as (small or capital) greek letters, e.g. %omega and %Omega.
Beware: %pi %gamma %phi are predefined.

There is a config option to display greek letters by name (without %):

      ->Edit ->Configure
         ->Worksheet
            [x] Change names of greek letters to greek letters
Beware: beta gamma zeta are pre-defined functions!

Math display modes

      set_display('xml);      nice format (default)
      set_display('ascii);    multi-line mode, like maxima with display2d:true
      set_display('none);     one-line mode, like maxima with display2d:false
May be set via ->Maxima ->Change 2d display.
In xml mode, long numbers are displayed with a shortcut.

Subscripts

An underscore converts integers and single letters to subscripts.
This is governed by the variable
      wxsubscripts: false
                    true      /* default */
                    all       /* for multi-letter subscripts */
which can also be changed in Configure ->Worksheet.

(Mis)use of array indices as subscripts (e.g. alpha[new]) is discouraged.

wxMaxima-0.8.x notes

In 0.8.0/0.8.1 The latter is made configurable in 0.8.2:

  [x] Enter evaluates cells

In wxMaxima-0.8.5, %alpha etc are represented as greek letters by default (no need to configure).

It appears that wxMaxima has an additional mechanism to auto-load packages, in addition to setup_autoload(..) in maxima.

top

Documentation and Publications

Tutorials

Antonio Cangiano, A 10 minute tutorial for solving Math problems with Maxima
Boris Gaertner, The Computer Algebra Program Maxima - a Tutorial
Moses Glasner, The Maxima Primer
Richard H. Rand, Introduction to MACSYMA
wxMaxima tutorials  [in *.wxm.zip format]

Advanced

Maxima Beginner's FAQ [with many tips for advanced usage, in fact]
Paulo Ney de Souza et al., The Maxima Book (19-Sept-2004)
Moses Glasner, A Maxima Guide for Calculus Students
Robert Dodier, Minimal Maxima
Edwin L. Woollett, Maxima by Example
P. Lutus, Symbolic Mathematics Using Maxima
Maxima, Maple, and Mathematica: the Summary
Gilberto E. Urroz, Maxima Book

Plotting

Examples of the Maxima Gnuplot interface
A Maxima-Gnuplot interface

Manuals

Maxima Manual  [5.41.0]
Michael Clarkson, DOE-Maxima Reference Manual  [Maxima manual v5.9 reformatted]

Help

Maxima mailing list and archives
Maxima user interface tips

In German

Johann Weilharter, Mathematik mit Computerunterstützung: CAS Maxima  [Sammlung von Unterrichtsmaterial]
Walter Wegscheider, Maxima 5.xx unter der Oberfläche wxMaxima
Robert Glöckner, Einführung in Maxima
H.-G. Gräbe, Skript zu "Einführung in das symbolische Rechnen"  [not using Maxima]

More links

see maxima.sourceforge.net

top

Appendices

top

Startup Scripts

      maxima_userdir                directory for user startup files
                                    (Unix default: $HOME/.maxima)
Startup files, see maxima(1):
      maximarc
      maxima-init.lisp
      maxima-init.mac
The latter can be used to configure auto-loading of modules, e.g.
      setup_autoload("to_poly_solve.mac", to_poly_solve, %solve);
top

Command display and session log

Disable 2D display, use 1-line output:
      display2d:false
Convert expression to TeX format:
      tex(expr);
Save command output and input to file:
      with_stdout("filename", commands);  writes output of commands to file
            file_output_append: true;     switch to append mode

      stringout("filename", expr1, ..);   write expressions in a form
                                                suitable for maxima input
Session transcript:
      writefile("filename");        session transcript in console output format
      appendfile("filename");       same, but append to file
      closefile();                  terminate session transcript
top

Checking the installation

      build_info();
      run_testsuite();
      run_testsuite(true);          show bugs only
top

Experimental solver to_poly_solve()

by Barton Willis, 2006ff

provided e.g. with Maxima-5.15.0 + 5.17.1:
files:
topoly.lisp (engine)
topoly_solver.mac (wrapper).

They also work with Maxima-5.10.

      load(topoly_solver);
            /home/b/maxima/5.15.0/topoly_solver.mac
      to_poly_solve(s + sqrt(1-s^2) = 1/2, s);
                    sqrt(7) - 1
            [[s = - -----------]]
                         4
      to_poly_solve([sqrt(x) + y = 0, sqrt(x) = 1], [x, y]);
            [[x = 1, y = - 1]]
      to_poly_solve(sin(x) + cos(x) = 1/2, x);
            Nonalgebraic argument given to 'topoly'
In Maxima-5.18.1, there is a new version (which does not work with Maxima-5.10?) - it solves the last example as well:
      load(to_poly_solver);
      to_poly_solve(sin(x) + cos(x) = 1/2, x);
            %union{...}
In Maxima-5.21.1, the to_poly_solver package is auto-loaded as needed.
Same with Maxima-5.24.0 (Ubuntu-12.04).
In Maxima-5.27.0 (Debian-7), the package is named to_poly_solve and has to be loaded by hand.

top

More plot details

plot2d command structure

      plot2d(plot, options, ...)                   one plot item
      plot2d([plot_1, plot_2, ...], options, ...)  several plot items
Each plot item can be one of
      expr                                functional expression
      [parametric, expr1, expr2, range]   parametric function
      [discrete, xlist, ylist]            discrete points
      [discrete, xylist]                  xylist = [[x1, y1], [x2, y2], ...]
If expressions are present, the (common) name and range of the independent variable has to be given as the first option.

Discrete points are drawn as polygons by default. For point symbols, a style option is required, specifying which items in the plot list should be points instead of lines, e.g.

      [style, lines, points, lines, ..]

plot2d options

See section 12.4 "Plotting Options" in the Maxima manual.
      [same_xy, true]               equal scales for x and y
      [logx, true]                  logrithmic scale(s)
      [logy, true]
      [yx_ratio, value]             set aspect ratio

      [x, min, max]                 horizontal range
      [y, min, max]                 vertical range

      [label, ["text",x,y], ..]     write text at specified location(s)

      [title, "text"]
      [xlabel, "text"]
      [ylabel, "text"]
      [legend, "text1",..,"textn"]  legends for n curves
      [legend, false]               suppress legends

      [grid2d, true]                display grid

      [point_type, value]
            value = bullet, circle, plus, times, asterisk, box, square,
                    triangle, delta, wedge, nabla, diamond, lozenge      
      [color, value]
            value = red, green, blue, magenta, cyan, yellow, orange, violet,
                    brown, gray, black, white, #RRGGBB

      [pdf_file, "filename"]        better use absolute pathname
      [png_file, "filename"]
      [ps_file, "filename"]
      [svg_file, "filename"]

      [gnuplot_default_term_command, "set term wxt 1"]
            plot to alternative window 1 etc (default: 0)
            see Maxima manual, section 12.5 "Gnuplot Options"
Note: The option name alone is a shorthand for true (if applicable).

Special symbols in text strings

Subscripts and superscripts are written in TeX syntax.

The Greek letters can be displayed by {/Symbol a}. This gives "alpha" which corresponds to "a". The relation of the Symbol and alphabet is as follows:
ALPHABET SYMBOL ALPHABET SYMBOL alphabet symbol alphabet symbol
A Alpha N Nu a alpha n nu
B Beta O Omicron b beta o omicron
C Chi P Pi c chi p pi
D Delta Q Theta d delta q theta
E Epsilon R Rho e epsilon r rho
F Phi S Sigma f phi s sigma
G Gamma T Tau g gamma t tau
H Eta U Upsilon h eta u upsilon
I iota W Omega i iota w omega
K Kappa X Xi k kappa x xi
L Lambda Y Psi l lambda y psi
M Mu Z Zeta m mu z zeta
[copied from Kawano's FAQ]

top

GCL

GCL (GNU Common Lisp) prompt and commands:
      MAXIMA>>(help)          show GCL help
      MAXIMA>>(run)           restart Maxima session
      MAXIMA>>(bye)           exit
      MAXIMA>>(by)            exit
top

TO DO

wxMaxima cells