Mathematica 9 is now available
THIS IS DOCUMENTATION FOR AN OBSOLETE PRODUCT.
SEE THE DOCUMENTATION CENTER FOR THE LATEST INFORMATION.
Mathematica > Core Language > Expressions > Testing Expressions > MatrixQ >
Mathematica > Core Language > Procedural Programming > Conditionals > Testing Expressions > MatrixQ >

MatrixQ

MatrixQ[expr]
gives True if expr is a list of lists or a two-dimensional SparseArray object that can represent a matrix, and gives False otherwise.
MatrixQ
gives True only if test yields True when applied to each of the matrix elements in expr.
  • MatrixQ[expr] gives True only if expr is a list and each of its elements is a list of the same length, containing no elements that are themselves lists, or if expr is a two-dimensional SparseArray object.
Test of whether an object is a matrix:
These are not matrices:
Use tests to generalize and specialize:
Test of whether an object is a matrix:
In[1]:=
Click for copyable input
Out[1]=
In[2]:=
Click for copyable input
Out[2]=
 
These are not matrices:
In[1]:=
Click for copyable input
Out[1]=
In[2]:=
Click for copyable input
Out[2]=
 
Use tests to generalize and specialize:
In[1]:=
Click for copyable input
Out[1]=
In[2]:=
Click for copyable input
Out[2]=
Test if a matrix has positive (real) entries:
Test if a matrix has real numeric entries:
Faster test for real-valued numbers:
Define a function that only evaluates for explicit matrices:
This represents the Hermitian part of a matrix symbolically:
This gets the Hermitian part explicitly:
MatrixQ is a special case of ArrayQ:
A matrix is made up of vectors of equal length:
New in 1 | Last modified in 5
Ask a question about this page  |  Suggest an improvement  |  Leave a message for the team
Format:   HTML  |  CDF