Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2009

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

Search the Archive

Re: Creating Matrix from vectors specific issue.

  • To: mathgroup at smc.vnet.net
  • Subject: [mg100761] Re: [mg100745] Creating Matrix from vectors specific issue.
  • From: Murray Eisenberg <murray at math.umass.edu>
  • Date: Sat, 13 Jun 2009 06:03:04 -0400 (EDT)
  • Organization: Mathematics & Statistics, Univ. of Mass./Amherst
  • References: <200906120946.FAA27906@smc.vnet.net>
  • Reply-to: murray at math.umass.edu

Did you look carefully at the result of the following?

   v1 = {{1},{2},{3}};
   v2 = {{4},{5},{6}};
   A = {v1,v2}

You get:

   {{{1}, {2}, {3}}, {{4}, {5}, {6}}}

What you have is a list of two 3-element lists, with each of those 
individual elements itself being a 1-element list.  That is, A has 
ArrayDepth of 3 (and a Depth of 4) whereas to have a list of lists that 
represents a matrix, you want an ArrayDepth of 2 (and a Depth of 3).

So all you need to do to reduce your "1st case" to your "2nd case" is to 
Flatten each vector:

   B = {Flatten[v1],Flatten[v2]}
{{1,2,3},{4,5,6}}

And now you have a list of two 3-element lists, where each individual 
element is a number (and no longer a 1-element list holding a number). 
So it can represent a matrix in the conventional meaning of the term, 
and you can make what are the rows into the columns by using Transpose, 
as you did in your "2nd case".

For a whole bunch of vectors of the form list v1, v2, you can Map the 
function Flatten onto the whole list of vectors at once rather than 
evaluating Flatten separately upon each. In the case of your two two:

   v1 = {{1},{2},{3}};
   v2 = {{4},{5},{6}};
   Flatten /@ {v1,v2}

I do recommend you study the Documentation Center tutorials "Lists" and 
"VectorsAndMatrices".  Learning more of the fundamentals will eventually 
save you a lot of time.

Kinu wrote:
> Thanks to all who replied before
> My exact problem is as follows..
> I am getting vectors from my program which is of the form
> v1 = {{1},{2},{3}};
> v2 = {{4},{5},{6}};
> BUT NOT v1 = {1,2,3} and v2 = {4,5,6}
> 
> Now if i use A = {v1,v2} and then Transpose[A] i am getting the
> required matrix only in the 2nd case i.e when v1 =  {1,2,3} and
> similarly v2.
> However when i use the same A = {v1,v2} in the 1st case and then
> Transpose[] i.e when v1 =
> {{1},{2},{3}} and similarly v2, i am not getting the required matrix.
> If anyone would help me with this specific point it will be helpful.
> 
> I have also seen that the dimension in case 1 is {3,1} while that in
> case 2 is {3}. If there is any way to interchange the two .. that also
> will suffice. i.e if i can change {{1},{2},{3}} to {1,2,3} that will
> also suffice.
> 
> Please help.
> 

-- 
Murray Eisenberg                     murray at math.umass.edu
Mathematics & Statistics Dept.
Lederle Graduate Research Tower      phone 413 549-1020 (H)
University of Massachusetts                413 545-2859 (W)
710 North Pleasant Street            fax   413 545-1801
Amherst, MA 01003-9305


  • Prev by Date: Re: Correction to "Fundamental Theorem of Calculus and
  • Next by Date: Problem of NUMERICAL constraints (Ndsolve) with Nminimize
  • Previous by thread: Re: Creating Matrix from vectors specific issue.
  • Next by thread: Re: Creating Matrix from vectors specific issue.