Wolfram ResearchPRODUCTSPURCHASEFOR USERSCOMPANYOUR SITES
THIS IS DOCUMENTATION FOR AN OBSOLETE PRODUCT.
SEE THE DOCUMENTATION CENTER FOR THE LATEST INFORMATION.

Identity and Diagonal Sparse Matrices

Mathematica 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 4Cross4 sparse identity matrix.

In[1]:= 

Out[2]//MatrixForm=

This generates a 4Cross4 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.


Any questions about topics on this page? Click here to get an individual response.Buy NowFree TrialMore Information



 © 2009 Wolfram Research, Inc.  Terms of Use  Privacy Policy |
Sign up for our newsletter: