Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Construct matrix from vectors in Mathematica

  1. Jun 2, 2012 #1
    I have defined vectors which are to be column vectors of some matrix. How to tell Mathematica to construct such matrix whose column vectors are already defined vectors?
  2. jcsd
  3. Jun 2, 2012 #2
    Mathematica doesn't usually distinguish row from column vectors and will use a vector as needed.

    So if you have

    In[1]:= v1={a,b};v2={c,d};

    Then this will give you what you want

    In[3]:= mat=Transpose[{v1,v2}]
    Out[3]= {{a,c},{b,d}}

    But if you have done something like this, thinking you need that for columns,

    In[4]:= v1={{a},{b}};v2={{c},{d}};

    then this will undo what you have done and give you what you want

    In[6]:= mat=Transpose[{Flatten[v1],Flatten[v2]}]
    Out[6]= {{a,c},{b,d}}
  4. Jun 3, 2012 #3
    It works! Thank you very much!
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Similar Threads - Construct matrix vectors Date
Mathematica Summing matrix components Today at 3:56 PM
Mathematica - Constructing Matrices Aug 24, 2010
Mathematica - Construct a Matrix Feb 7, 2010
5-point Gaussian Quadrature using constructed approximant in Matlab Mar 30, 2008
Constructing Mathematical Statements Mar 4, 2008