Construct matrix from vectors in Mathematica

Click For Summary
SUMMARY

This discussion focuses on constructing a matrix from predefined column vectors in Mathematica. Users can create a matrix by utilizing the Transpose function on a list of vectors. Specifically, defining vectors as v1={a,b} and v2={c,d} allows the command mat=Transpose[{v1,v2}] to yield the desired matrix {{a,c},{b,d}}. If vectors are mistakenly defined as nested lists, such as v1={{a},{b}}, the Flatten function must be applied before transposing to achieve the correct matrix structure.

PREREQUISITES
  • Understanding of Mathematica syntax and functions
  • Familiarity with vector and matrix concepts
  • Knowledge of the Transpose function in Mathematica
  • Experience with the Flatten function in Mathematica
NEXT STEPS
  • Research the use of the Transpose function in Mathematica
  • Learn about vector manipulation techniques in Mathematica
  • Explore advanced matrix operations in Mathematica
  • Investigate the implications of nested lists in Mathematica
USEFUL FOR

Mathematica users, data analysts, and anyone involved in mathematical modeling or computational tasks requiring matrix manipulation.

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!
 

Similar threads

  • · Replies 3 ·
Replies
3
Views
4K
  • · Replies 5 ·
Replies
5
Views
4K
  • · Replies 7 ·
Replies
7
Views
2K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 9 ·
Replies
9
Views
3K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 2 ·
Replies
2
Views
4K
  • · Replies 4 ·
Replies
4
Views
3K
  • · Replies 11 ·
Replies
11
Views
3K
  • · Replies 5 ·
Replies
5
Views
3K