sig_seg_v
sig_seg_v

Reputation: 570

How to pass an array as an argument to a maxima function?

I'm working on creating maxima functions to simplify the del operator on vectors. How can I pass a list/vector to a function in maxima? This works:

(%i7) dot(a,b) := a[1]*b[1]+a[2]*b[2]+a[3]*b[3];
(%o7)                 dot(a, b) := a  b  + a  b  + a  b
                                    1  1    2  2    3  3
(%i8) dot(a,b);
                                            2
(%o8)                            3 x y - 4 x

but this doesn't:

(%i13) grad(a) := diff(a[1],x) + diff(a[2],y) + diff(a[3],z);
define: argument cannot be an atom or a subscripted memoizing function; found: 
                                                                              a
 -- an error. To debug this try: debugmode(true);

Upvotes: 2

Views: 1376

Answers (1)

Robert Dodier
Robert Dodier

Reputation: 17576

Maxima has extremely confusing rules about scope and subscripts. First of all, I'll apologize for that.

My guess is that you already have an array named a by the time you define grad. Try a different name for the argument of grad -- try something which you haven't used yet. Does it work that way?

Anyway, shouldn't the definition be:

grad(a) := [diff(a, x), diff(a, y), diff(a, z)];

??

Upvotes: 2

Related Questions