Domanda

I want to use (make-array '(4 3 8)) in maxima which is basically to generate multi-d matrix as I am not able to find API to create multi-d matrices including with array(name,d1,d2...dm).

I can execute it using :lisp (make-array '(4 3 8)) but I don't know how I can label it as something like,

arr: :lisp(make-array '(4 3 8))

I also want to know if it is possible to use lisp code inside maxima functions. Any sort of help shall be highly regarded.

È stato utile?

Soluzione

To create a named array in Lisp code just exactly the same as array(name, d1, d2, ..., dm), write:

(mfuncall '$array name d1 d2 ... dm)

You can't include Lisp code directly in Maxima functions. But you can call Lisp functions. If the lisp function is named $foo, then in Maxima it's foo; if in Lisp it's foo, then in Maxima it's ?foo. E.g.:

:lisp (defun $foo (x) ...)

f(x) := print (foo (x));

By the way, Maxima's treatment of arrays is still a mess ... maybe someday we'll clean it up.

Altri suggerimenti

You can use make_array to create arrays directly:

(%i18) make_array(fixnum,4,3,8);
(%o18) {Array:  #3A(((0 0 0 0 0 0 0 0) (0 0 0 0 0 0 0 0) (0 0 0 0 0 0 0 0))
    ((0 0 0 0 0 0 0 0) (0 0 0 0 0 0 0 0) (0 0 0 0 0 0 0 0))
    ((0 0 0 0 0 0 0 0) (0 0 0 0 0 0 0 0) (0 0 0 0 0 0 0 0))
    ((0 0 0 0 0 0 0 0) (0 0 0 0 0 0 0 0) (0 0 0 0 0 0 0 0)))}

Or bind results of Lisp invocations like this:

(%i21) :lisp (msetq $foo (make-array '(4 3 8)));

#3A(((NIL NIL NIL NIL NIL NIL NIL NIL)
     (NIL NIL NIL NIL NIL NIL NIL NIL)
     (NIL NIL NIL NIL NIL NIL NIL NIL))
    ((NIL NIL NIL NIL NIL NIL NIL NIL)
     (NIL NIL NIL NIL NIL NIL NIL NIL)
     (NIL NIL NIL NIL NIL NIL NIL NIL))
    ((NIL NIL NIL NIL NIL NIL NIL NIL)
     (NIL NIL NIL NIL NIL NIL NIL NIL)
     (NIL NIL NIL NIL NIL NIL NIL NIL))
    ((NIL NIL NIL NIL NIL NIL NIL NIL)
     (NIL NIL NIL NIL NIL NIL NIL NIL)
     (NIL NIL NIL NIL NIL NIL NIL NIL)))
(%i21) foo;
(%o21) {Array:  #3A(((NIL NIL NIL NIL NIL NIL NIL NIL)
     (NIL NIL NIL NIL NIL NIL NIL NIL)
     (NIL NIL NIL NIL NIL NIL NIL NIL))
    ((NIL NIL NIL NIL NIL NIL NIL NIL)
     (NIL NIL NIL NIL NIL NIL NIL NIL)
     (NIL NIL NIL NIL NIL NIL NIL NIL))
    ((NIL NIL NIL NIL NIL NIL NIL NIL)
     (NIL NIL NIL NIL NIL NIL NIL NIL)
     (NIL NIL NIL NIL NIL NIL NIL NIL))
    ((NIL NIL NIL NIL NIL NIL NIL NIL)
     (NIL NIL NIL NIL NIL NIL NIL NIL)
     (NIL NIL NIL NIL NIL NIL NIL NIL)))}

By the way, array probably worked for you, too. I have never used it and was confused at first, since it is not printed after creation. But after checking the documentation and a Wikibooks article:

(%i22) array(A,2,2,2);
(%o22)                                 A
(%i23) arrayinfo(A);
(%o23)                     [declared, 3, [2, 2, 2]]
(%i24) A[0,1,2]: 2;
(%o24)                                 2
(%i25) listarray(A);
(%o25) [#####, #####, #####, #####, #####, 2, #####, #####, #####, #####, 
#####, #####, #####, #####, #####, #####, #####, #####, #####, #####, #####, 
#####, #####, #####, #####, #####, #####]

There seem to be quite a few options for this kind of thing in Maxima, or, as the above linked Wikibooks article quotes Robert Dodier: "Maxima's current array/matrix semantics are a mess […]"

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top