|
17.6 Basic Matrix Operations
Some basic matrix operations.
Det[M] gives the determinant of a square matrix M. Minors[m, k] gives a matrix of the determinants of all the submatrices of M. You can apply Minors to rectangular, as well as square, matrices.
Here is the determinant of a simple matrix.
In[1]:= Det[ {{a, b}, {c, d}} ]
Out[1]= 
This generates a matrix, whose  entry is a[i, j].
In[2]:= MatrixForm[ m = Array[a, {3, 3}] ]
Out[2]//MatrixForm= 
Here is the determinant of m.
In[3]:= Det[ m ]
Out[3]= 
This is the matrix of all minors of m.
In[4]:= Minors[m, 2]
Out[4]= 
You can use Det to find the characteristic polynomial for a matrix. Section 18.2 discusses ways to find eigenvalues and eigenvectors directly.
Here is a matrix.
In[5]:= m = Table[ 1/(i + j), {i, 3}, {j, 3} ]
Out[5]= 
Following precisely the standard mathematical definition, this gives the characteristic polynomial for m.
In[6]:= Det[ m - x IdentityMatrix[3] ]
Out[6]= 
There are many other operations on matrices that can be built up from standard Mathematica TE functions. One example is the trace or spur of a matrix, given by the sum of the terms on the leading diagonal.
Here is a simple matrix.
In[7]:= m = {{a, b}, {c, d}}
Out[7]= 
You can get the trace of the matrix by explicitly constructing a sum of the elements on its leading diagonal.
In[8]:= Sum[ m[[i, i]], {i, 2} ]
Out[8]= 
Powers and exponentials of matrices.
Here is a matrix.
In[9]:= m = {{0.4, 0.6}, {0.525, 0.475}}
Out[9]= 
This gives the third matrix power of m.
In[10]:= MatrixPower[m, 3]
Out[10]= 
It is equivalent to multiplying three copies of the matrix.
In[11]:= m . m . m
Out[11]= 
Here is the millionth matrix power.
In[12]:= MatrixPower[m, 10^6]
Out[12]= 
This gives the matrix exponential of m.
In[13]:= MatrixExp[m]
Out[13]= 
Here is an approximation to the exponential of m, based on a power series approximation.
In[14]:= Sum[MatrixPower[m, i]/i!, {i, 0, 5}]
Out[14]= 
    
|