This is documentation for Mathematica 8, which was
based on an earlier version of the Wolfram Language.
View current documentation (Version 11.2)
How to | Input a Matrix
Mathematica supports operations on matrices of any size and has a range of input methods appropriate for different needs, from small formatted matrices via keyboard or palettes, to text-based entry or automatic import.
This is a selection of examples from the complete "How to" screencast. »
Lists are very important general structures in Mathematica. A matrix in Mathematica is represented as a list of sublists of the same length.
Input a matrix:
In[4]:=
Click for copyable input
Out[4]=
Use MatrixForm to display as a matrix:
In[5]:=
Click for copyable input
Out[5]//MatrixForm=
Mathematica also has a user interface to input matrices.
Select Insert Table/MatrixNew:
In the window that appears, select Matrix (List of lists), enter the number of rows and columns for your matrix, and click OK:
Your matrix is inserted into your notebook:
Click for copyable input
Click a placeholder to enter input. Once one is highlighted, you can move to the next one using the tab or arrow keys:
Evaluating the matrix gives its underlying structure as a uniform nested list:
In[6]:=
Click for copyable input
Out[6]=
You can also enter matrices using the Basic Math Assistant palette.
Open the palette from the Palettes menu:
On the Advanced tab, click the Matrix button to insert a 2×2 matrix:
As before, you can move through the empty placeholders using the tab or arrow keys.
To create a new row, use Ctrl+ Enter. The new row will be inserted immediately below the position of your cursor. Pressing Ctrl+ Enter with the cursor positioned after any entry in the last row creates a new row at the bottom of the matrix:
Similarly, new columns can be entered using Ctrl+ ,:
    
You can import a matrix from a file. In this example, data is imported from a file and displayed in MatrixForm:
In[7]:=
Click for copyable input
Out[7]//MatrixForm=