On Wed, Feb 27, 2013 at 8:27 AM, Emmanuel Michon <
emmanuel.michon+maxima at gmail.com> wrote:
> 2/ I want to do the same for vectors. genmatrix(A,1,5) or
> genmatrix(A,5,1) will still use double subscript.
>
> So the only way seems to use declared arrays (this time, array indices
> start from zero... (*)).
>
> array(W,5);
> W:makelist(W[i-1],i,5);
> (%o8) [W , W , W , W , W ]
> 0 1 2 3 4
>
You do not need to declare the array to do makelist(W[i],i,0,4).
2a: is there an issue with having the token W used for, successively,
> the array name W, the array bits W[3] etc, and then, a list named W
> that is the only suitable things to evaluate A.W ?
>
Using the same symbol in multiple ways is a very bad idea. Even if it
seems to work in some cases, it will cause you problems in the long run.
It is a particularly bad idea to assign W:makelist(W[i-1],i,5), because
now W[3] will evaluate to W[2] -- is that really what you want?
I'm not sure why Barton says that undeclared arrays have pitfalls.
Personally, I'm *much* more comfortable with vectors as values (e.g. Q:
[a,b,c]) than declared arrays where the individual elements have values but
the array object can't be manipulated directly (e.g. array(Q,5)$ Q[1]:a$
Q[2]:b$) I suppose if you're used to Fortran/C, that might be more
natural, but most Maxima functions are set up to work with values, not
named, declared arrays.
> 2b: I'm unable to macro-ify the previous thing to make it generic.
> That would be something like
>
> genvector(W,n) ::= block(array(''W,n), W:makelist(W[i-1],i,n) );
>
The ''X construct is very handy in interactive use, but this sort of case
is *precisely* why I recommend avoiding it as much as possible. ''X means
"evaluate X at the time Maxima *reads the expression*". In this case, it
would evaluate W when you *define* genvector, not when you call it.
> 3/ I also miss the magic thing that would transform [x,y,z] in to x,y,z
> arguments like
>
I think you are looking for 'apply' -- not magic!
apply('diag_matrix,[a,b,c]) => matrix([a,0,0], ...)
Hope this helps.
-s