Mathematica 9 is now available
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: [mg100771] Re: Creating Matrix from vectors specific issue.
  • From: Bill Rowe <readnews at sbcglobal.net>
  • Date: Sat, 13 Jun 2009 06:04:53 -0400 (EDT)

On 6/12/09 at 5:46 AM, basukinjal at gmail.com (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.

You really ought to read the tutorials on working with lists in
Mathematica. To convert any multi-dimensional list to a 1D list,
use Flatten. For example,

In[1]:= v1 = {{1}, {2}, {3}};
v2 = {{4}, {5}, {6}};

In[3]:= Flatten[v1]

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

So, the desired result can be obtained with Transpose as follows:

In[4]:= Transpose[Flatten /@ {v1, v2}]

Out[4]= {{1, 4}, {2, 5}, {3, 6}}

Or even more directly with ArrayFlatten as follows:

In[5]:= ArrayFlatten@{{v1, v2}}

Out[5]= {{1, 4}, {2, 5}, {3, 6}}



  • Prev by Date: Re: Creating Matrix from vectors specific issue.
  • Next by Date: Re: Re: Correction to "Fundamental Theorem of Calculus
  • Previous by thread: Re: Creating Matrix from vectors specific issue.
  • Next by thread: Combined Set, SetDelayed