changing the dimensions of a matrix



Here's one way of doing it, not necessarily the most efficient but it works:

transpose(ev(funmake('append,makelist(col(A1,i),i,1,length(A1[1]))),eval));

(%i1) A1:matrix([1,2],[3,4],[5,6]);
                                   [ 1  2 ]
                                   [      ]
(%o1)                              [ 3  4 ]
                                   [      ]
                                   [ 5  6 ]
(%i2)
A2:transpose(ev(funmake('append,makelist(col(A1,i),i,1,length(A1[1]))),eval)
);
(%o2)                        [ 1  3  5  2  4  6 ]

You can also turn this into a user-defined function:

(%i3)
reshape(M):=transpose(ev(funmake('append,makelist(col(M,i),i,1,length(M[1]))
),eval));
(%o3) reshape(M) := transpose(ev(funmake('append, 

                                 makelist(col(M, i), i, 1, length(M ))),
eval))
                                                                   1
(%i4) reshape(A1);
(%o4)                        [ 1  3  5  2  4  6 ]


Viktor



-----Original Message-----
From: maxima-admin@math.utexas.edu [mailto:maxima-admin at math] On
Behalf Of Kamaraju Kusumanchi
Sent: Wednesday, April 06, 2005 10:58 PM
To: maxima@math.utexas.edu
Subject: changing the dimensions of a matrix

Hi

Let's say I have a matrix defined by

A1 : matrix([1,2], [3,4], [5,6])

Now I want to reshape the 3x2 matrix into a vector of 6x1 so that the
end result would be same as declaring

A2 = matrix([1, 3, 5, 2, 4, 6])

How can I do this? One method is to get each of the separate columns
and create a new variable. But this is tedious for very large matrices
and I have to do it for every column. I am sure there is an easy way
(intrinsic function?) to do this. Can someone provide couple of ideas?

thanks
raju


Please do not cc me separately. I am subscribed to the list and do not
wish to receive the same mail twice.
-- 
http://groups-beta.google.com/group/mpich

_______________________________________________
Maxima mailing list
Maxima@www.math.utexas.edu
http://www.math.utexas.edu/mailman/listinfo/maxima