How to do matrix operation programatically in lisp
Subject: How to do matrix operation programatically in lisp
From: Kun Lin
Date: Sat, 24 Nov 2007 12:29:03 -0500
Robert Dodier wrote:
> 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
>
Hi Robert,
Thanks for you reply.
Just wanna see if i understand you correctly.
I have a matrix
[1 2]
[3 4]
and let say i want to invert it.
so here is what i did
MAXIMA> (mfuncall '$invertmx '(($matrix) ((mlist) 1 2) ((mlist) 3 4)))
output: (($MATRIX) ((MLIST) -2 1) ((MLIST) ((RAT SIMP) 3 2) ((RAT
SIMP) -1 2)))
//
Maybe i am gonna write a parser so i can do something like
(eval (parse-maxima-to-lisp "invert(matrix[1,2],[3,4])"))
to automate the conversion between maxima and lisp.
I am on the right track to effectively use maxima as a library?
- Kun
<http://www.math.utexas.edu/pipermail/maxima/2007/008152.html>//