Q: How can I save the stuff that I'm working on?

I want to quit for now and come back to the same place later.

A: Use save like this to store the contents of your Maxima session in a file:

    save ("my_session", all)$

Then use load to recover the session:

    load ("my_session")$

Note 1: Input and output labels (%i{n} and %o{n} variables) recovered from a stored session will clobber existing labels of the same names.

Note 2: save stores the Maxima session as a Lisp file. Use stringout to store the Maxima session as a Maxima file.

Note 3: Files created by save and stringout aren't pleasant to look at. Use writefile to capture expressions as they are displayed.

Note 4: Saving and restoring files is a big topic! See: save, load, stringout, and writefile. (Execute "describe (save)$" or "? save", etc., to see the on-line documentation.)


Q: How do I make a list of function values, one for each element in a list of arguments?

For example, given [1, 2, 3], I want [cos (%pi/N), cos (2*%pi/N), cos (3*%pi/N)].

A. Use map or makelist like this:

    i: [1, 2, 3]$
    map (cos, i*%pi/N);

or

    makelist (cos (i*%pi/N), i, 1, 3);

map works for any kind of list (not necessarily a sequence of integers).


Q: How do I add up all the elements in a list?

For example, given [7, -2, 13], I want 18.

A. Use apply like this:

    x: [7, -2, 13]$
    apply ("+", x);

Equivalent one can use sum but the expression is a little more verbose:

    x: [7, -2, 13]$
    sum (x[i], i, 1, length(x));

Q: Speaking of lists, how can I make a list like [1, 2, 3] ?

A: makelist is a versatile way to make lists, but it's a little clumsy for a simple list of integers. To make a list of integers from m to n:

    makelist (i, i, m, n);

Now let's define an operator named .. to do this:

    ".." (m, n) := makelist (i, i, m, n);
    infix ("..");

Let's make some lists:

    1 .. 7;
    a: 1;  b: 7;  a..b;
    (a..b)*2*%pi/8;

Note the spaces in "1 .. 7". That's to help Maxima understand you mean to use the new "..", since "." has other uses. Note also that the limits must be known when the list is constructed. This scheme won't do the right thing given something like "0 .. (n-1)" when n is unknown.


Q: How do I use an expression I've calculated using Maxima as the definition of a Maxima function?

For example, given

    expr: logcontract (integrate (2/(x^2-1), x));

I want to define

    f(x) := log((x-1)/(x+1));

without re-entering the right-hand side by hand.

A: There are two (main) ways:

(1) Use the ''(...) operator. ''(...) substitutes the value of ... in the expression as it is being read. So:

    f(x):= ''(expr);

The parentheses are not necessary in this case, but you can use them for clarity and consistency. Note that '' is two single-quotes, not one double-quote.

(2) Use the define function. define allows both the function to be defined and the definition to be calculated:

    define('(f(x)),expr);

f(x) is quoted here. This is only strictly necessary if f has a previous definition, but it's good practice to quote explicitly.

When you make a function with := , the right-hand side of the definition is not evaluated at the time you make the definition. Applying the quote-quote operator to the function body, or calling define, evaluates the right-hand side.


Q. How do I plot a function which I defined?

I defined a function using the ":=" operator. For some functions f(x) the obvious "plot2d (f(x), [x, 0, 1])" works correctly and for some I get an error message.

A: Try quoting the function call like this -- '(f(x)) -- in the plot2d argument list. Examples:

f(x) := if x > 1 then 2/(x^2+1) else x^2$
plot2d ('(f(x)), [x, 0, 3])$

g(x) := quad_qag (t^2, t, 0, x, 2) [1]$
plot2d ('(g(x)), [x, -2, 2])$

In these examples, you'll get an error if f(x) and g(x) are written without the quote mark. Note the parentheses -- you want '(f(x)), not 'f(x).


Q: How do I plot a list of points?

A: Use "plot2d([discrete, x, y])" where x and y are lists of x and y values, or "plot2d([discrete, xy])" where xy is a list of xy value pairs. Current releases of Maxima has a problem dealing with rational x values. Converting them to numerical values solves the problem:

(%i41) x:makelist(i/2,i,0,5);
(%o41) [0,1/2,1,3/2,2,5/2]

(%i42) y:makelist(x^2, x, x);
(%o42) [0,1/4,1,9/4,4,25/4]

(%i43) plot2d([discrete, x, y]), numer;

The ",numer" causes Maxima to evaluate numerically.



Q: How do I make a log-log plot?


(More fun stuff goes here!)


Q: How do I use Maxima to do quaternion maths?

A: You need to use the atensor package. See http://googloids.blogspot.com/2007/01/quaternions-in-maxima.html.