Identity and Diagonal Sparse MatricesMathematica does not provide special functions for generating sparse identity or sparse diagonal matrices because they are so easy to build with SparseArray. This generates a 4 4 sparse identity matrix. In[1]:=  |
Out[2]//MatrixForm=
|
This generates a 4 4 sparse diagonal matrix. In[3]:=  |
Out[5]//MatrixForm=
|
If you want to compute with floating point numbers it can be advantageous to use matrices that contain floating point entries; this is described in more detail in the section Performance: Matrix Contents. If you start with an integer matrix, such as the identity matrix generated previously, it can be converted to a floating point matrix by using the function N. This is shown in the following. In[6]:=  |
Out[7]//MatrixForm=
|
An alternative would be to create the initial sparse identity matrix using floating point entries. In[8]:=  |
Out[9]//MatrixForm=
|
The different types of matrix that Mathematica can work with are described in more detail in the section Matrix Types.
|