Mathematica 9 is now available
Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2007

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Convert nxn matrix to a column vector with (n^2) elements

  • To: mathgroup at smc.vnet.net
  • Subject: [mg83731] Re: Convert nxn matrix to a column vector with (n^2) elements
  • From: Jean-Marc Gulliet <jeanmarc.gulliet at gmail.com>
  • Date: Thu, 29 Nov 2007 06:26:05 -0500 (EST)
  • Organization: The Open University, Milton Keynes, UK
  • References: <fiji4u$ijb$1@smc.vnet.net>

Tara.Ann.Lorenz at gmail.com wrote:

> Any ideas how to convert an nxn matrix to a column vector with n^2
> elements?

Beware that Mathematica does not have any special construct to 
distinguish row vectors from column vectors. A vector can be represented 
by a one dimensional list made of numeric or/and symbolic elements. 
Depending on the context and the operation in use, Mathematica 
interprets the vector as a column or a row vector. (More generally, 
vectors are tensors of rank 1.)

Having said that, I believe that what you are looking for is a command 
of  the form Flatten@Transpose@m (m being your square matrix) as 
illustrated in the following example:

Mathematica 6.0 for Microsoft Windows (32-bit)
Copyright 1988-2007 Wolfram Research, Inc.

In[1]:= m = Array[a, {2, 2}]

Out[1]= {{a[1, 1], a[1, 2]}, {a[2, 1], a[2, 2]}}

In[2]:= %//MatrixForm

Out[2]//MatrixForm= a[1, 1]   a[1, 2]

                     a[2, 1]   a[2, 2]

In[3]:= Flatten@Transpose@m

Out[3]= {a[1, 1], a[2, 1], a[1, 2], a[2, 2]}

In[4]:= %//MatrixForm

Out[4]//MatrixForm= a[1, 1]

                     a[2, 1]

                     a[1, 2]

                     a[2, 2]

In[5]:= Flatten@m

Out[5]= {a[1, 1], a[1, 2], a[2, 1], a[2, 2]}

In[6]:= %//MatrixForm

Out[6]//MatrixForm= a[1, 1]

                     a[1, 2]

                     a[2, 1]

                     a[2, 2]

Regards,
-- 
Jean-Marc


  • Prev by Date: Re: Re: PlotLabel - SubscriptBox - Vers. 6: FontColor not
  • Next by Date: Re: Controlling evaluation
  • Previous by thread: Re: Convert nxn matrix to a column vector with (n^2) elements
  • Next by thread: Epilog with 3 dimensional graphics primitives