Construct matrix from vectors in Mathematica

In summary, Mathematica does not differentiate between row and column vectors and will automatically use a vector as needed. To construct a matrix with pre-defined column vectors, use the Transpose function. If the vectors are in the form of a list of lists, use Flatten to convert them to a vector before using Transpose.
  • #1
nikolafmf
114
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
  • #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}}
 
  • #3
It works! Thank you very much!
 

1. How do I create a matrix from vectors in Mathematica?

To create a matrix from vectors in Mathematica, use the "ArrayReshape" function. This function takes in a list of vectors and reshapes them into a matrix. For example, if you have two vectors with 3 elements each, the resulting matrix will have 2 rows and 3 columns.

2. Can I specify the dimensions of the resulting matrix when using "ArrayReshape"?

Yes, you can specify the dimensions of the resulting matrix by including a third argument in the "ArrayReshape" function. For example, if you want a 3x3 matrix, you would use "ArrayReshape[list, {3,3}]."

3. How do I add or remove elements in a matrix created from vectors?

To add or remove elements in a matrix created from vectors, you can use the "Part" function. This function allows you to access specific elements in the matrix by specifying their row and column index. You can then use the "Append" or "Delete" function to add or remove elements respectively.

4. Can I perform mathematical operations on a matrix created from vectors?

Yes, you can perform mathematical operations on a matrix created from vectors using the standard arithmetic operators (+, -, *, /). You can also use built-in functions such as "Transpose" or "Dot" to perform more complex operations on matrices.

5. How do I convert a matrix created from vectors back into individual vectors?

To convert a matrix created from vectors back into individual vectors, you can use the "Flatten" function. This function takes in a matrix and flattens it into a single list of elements. You can then use the "Partition" function to split this list into individual vectors based on the desired dimensions.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
1K
Replies
3
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
7
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
887
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
399
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
220
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
756
  • Linear and Abstract Algebra
Replies
14
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
Back
Top