genvector() on the model of genmatrix()



For a zero-based indexing using genmatrix, try

  (%i18) genmatrix(lambda([i,j],A[i-1,j-1]),2,2);
  (%o18) matrix([A[0,0],A[0,1]],[A[1,0],A[1,1]])

Using undeclared arrays this has some pitfalls. Be careful out there.

To construct a diagonal matrix, try

  (%i19) diag_matrix(a,b,c);
  (%o19) matrix([a,0,0],[0,b,0],[0,0,c])

--Barton

________________________________________
From: maxima-bounces at math.utexas.edu [maxima-bounces at math.utexas.edu] on behalf of Emmanuel Michon [emmanuel.michon+maxima at gmail.com]
Sent: Wednesday, February 27, 2013 07:27
To: maxima at math.utexas.edu
Subject: genvector() on the model of genmatrix()

Hello,

I'm quite used to maxima but now I stumble on more subtle things with macros&co.

1/ minor concern: let's look at this

(%i3) genmatrix(A,3,5);
                     [ A      A      A      A      A     ]
                     [  1, 1   1, 2   1, 3   1, 4   1, 5 ]
                     [                                   ]
(%o3)                [ A      A      A      A      A     ]
                     [  2, 1   2, 2   2, 3   2, 4   2, 5 ]
                     [                                   ]
                     [ A      A      A      A      A     ]
                     [  3, 1   3, 2   3, 3   3, 4   3, 5 ]

is there a manner to tell maxima to subscript starting at value zero A[0,0] etc?

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

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 ?

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) );

genvector(A,5);
genvector(B,7);

but W isn't replaced as should.

3/ I also miss the magic thing that would transform [x,y,z] in to
x,y,z arguments like

(%i4) [a,b,c];
(%o4)                              [a, b, c]
(%i3) diag_matrix(a,b,c);
                                  [ a  0  0 ]
                                  [         ]
(%o3)                             [ 0  b  0 ]
                                  [         ]
                                  [ 0  0  c ]

...

Thanks for any useful advise,

Sincerely yours,

e.m.

(*) I'm eventually exporting long maxima formulae to C code. So it's
important to me to expand vectors and matrices with a syntax
consistent with C indexing, and easily mapped (double m[][], v[];).
_______________________________________________
Maxima mailing list
Maxima at math.utexas.edu
http://www.math.utexas.edu/mailman/listinfo/maxima