Construct matrix from vectors in Mathematica

Join the discussion
Ask a follow-up here, or get your own question answered by working scientists, mathematicians and engineers — people, not an autocomplete.
Real named experts · corrections over time · the nuance an AI answer skips
2 replies · 8K views
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?
 
Physics news on Phys.org
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}}
 
It works! Thank you very much!