How to perform a vec or vech operation on a matrix.



S. McKay Curtis wrote:
> Hello,
>
> I am looking for a way to "half-vectorize" a matrix in Maxima.  I
> couldn't find any "built-in" functions to do this, and my meager
> attempts to write some loops to do this have failed.  I've tried
>
> vecVar:zeromatrix(21,1);
> k:1;
> for j:1 thru 6 do
>     (for i:j thru 6 do
>         (vecVar[k,1]:Var[i,j],k:k+1));
>
> where Var is a 6x6 matrix.  But this gives me an error
>
> No such entry - `setelmx'
>  -- an error.  To debug this try debugmode(true);
>
> I get a similar error when I try to use the "setelmx" function directly.
>
> Any help would be appreciated.
>
> Thanks
> McKay
>
> (I am using Maxima through the Windows GUI wxMaxima 0.8.1.)
> _______________________________________________
> Maxima mailing list
> Maxima at math.utexas.edu
> http://www.math.utexas.edu/mailman/listinfo/maxima
>
>   
To S. McKay Curtis:

I found some syntax errors in you code that were preventing your loop 
from working.
In wxMaxima 0.8.1, which I'm using on PCLinuxOS, I tried the following.
I added a 6 x 6 Var matrix of my own construction because you did not 
provide your's:
-----------------------------------------------------
vecVar:zeromatrix(21,1);
Var : matrix( [01,02,03,04,05,06],
              [07,08,09,10,11,12],
              [13,14,15,16,17,18],
              [19,20,21,22,23,24],
              [25,26,27,28,29,30],
              [31,32,33,34,35,36] );
k:1;
for j:1 thru 6 do (
 for i:j thru 6 do (
   vecVar[k][1] : Var[i][j],
   k : k+1
 )
);
vecVar;
-----------------------------------------------------
which produced this output:

matrix([1],[7],[13],[19],[25],[31],[8],[14],[20],[26],[32],[15],[21],[27],[33],[22],[28],[34],[29],[35],[36])

I hope this helps,

Paul Bowyer