|
17.2 Matrices
Functions for matrices.
A matrix is a list of vectors of the same length.
In[1]:= m = {{a, b}, {c, d}}
Out[1]= 
As with vectors, mathematical functions applied to a matrix get applied to each of the entries.
In[2]:= Log[m]
Out[2]= 
This builds a matrix S with elements .
In[3]:= s = Table[i+j, {i, 3}, {j, 3}]
Out[3]= 
This displays s in standard two-dimensional matrix format.
In[4]:= MatrixForm[s]
Out[4]//MatrixForm= 
This multiplies each of the entries of s by the scalar .
In[5]:= c s
Out[5]= 
This gives a matrix with symbolic elements in matrix format.
In[6]:= Array[p, {3, 2}]
Out[6]= 
Here are the dimensions of the matrix on the previous line.
In[7]:= Dimensions[%]
Out[7]= 
Transposing a matrix interchanges the rows and columns in the matrix. If you transpose an matrix, you get an matrix as the result.
Transposing a matrix gives a result.
In[8]:= Transpose[ {{a, b, c}, {ap, bp, cp}} ]
Out[8]= 
DiagonalMatrix makes a matrix with zeros everywhere except on the leading diagonal.
In[9]:= DiagonalMatrix[{a, b, c}]
Out[9]= 
IdentityMatrix[n] produces an identity matrix.
In[10]:= IdentityMatrix[3]
Out[10]= 
Of the functions for constructing matrices mentioned above, Table is the most general. You can use Table to produce many kinds of matrices.
Some special types of matrices.
Table evaluates Random[ ] separately for each element, to give a different pseudorandom number in each case.
In[11]:= Table[Random[ ], {2}, {2}]
Out[11]= 
This gives an upper-triangular matrix.
In[12]:= MatrixForm[ Table[If[i <= j, 1, 0], {i, 3}, {j, 3}] ]
Out[12]//MatrixForm= 
    
|