Construct matrix from vectors in Mathematica

2 replies · 8K views · last reply
nikolafmf
Messages
112
Reaction score
0
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?
 
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}}