How to do matrix operation programatically in lisp



On 11/22/07, Kun Lin <klin at umd.edu> wrote:

> I was trying to figure out a way to do matrix operations programatically in lisp.

Maxima expressions (of which objects such as a matrix are examples)
are represented as ((foo) x y z), i.e. the car is a list and the caar
is the operator name. E.g. a list is ((mlist) ...) and a matrix is
(($matrix) ((mlist) ...) ((mlist) ...) ...).

Maxima can carry out various operations on matrices with symbolic
expressions, e.g. eigenvalues, LU decomposition, etc.
There is also a Lisp translation of the LAPACK package which
contains numerical routines for eigenvalues & svd, & lots of
other stuff.

A random note -- a matrix is not represented as a Lisp array.

> Is there a general way of doing something like this.  Meaning is there a
> calling convention i can follow if i know the maxima input form i can
> deduce its equivalent lisp function call and arguments.

Most of the built-in Maxima functions (i.e. the stuff in maxima/src) are
ordinary Lisp functions. Some of them are so-called argument
quoting functions (aka mfexpr or defmspec functions within Maxima).
The mfexpr functions are implemented via a lambda expression attached
to the property list of the function name; they can be called via
mfuncall, mapply, or (meval '((foo) ...)).

All Lisp functions (whether defun or defmspec or whatever) expect
arguments like ((foo) ...).

> My ultimate goal is to use maxima as the backbone of all my
> mathematical  computing needs (symbolic, matrices ...) in writing lisp
> programs.  Can maxima do this?

What might be especially useful in engineering problem is to use
Maxima's symbolic functions to formulate a problem, and then
call Maxima's numerical functions to solve it. It is convenient
that both capabilities are present.

> Another idea is maybe my lisp code can
> call a .mac file.  I am just not sure what would be the best approach.

>From Lisp, mfuncall calls a function defined in Maxima.

You might take a look at the references I mentioned in my response
to Robert Gloeckner a little while ago.

best

Robert Dodier