next up previous contents
Next: SPRAND Sparse Uniform Random Up: Sparse Matrix Support Previous: SPONES Sparse Ones Function   Contents

Subsections

SPEYE Sparse Identity Matrix

Usage

Creates a sparse identity matrix of the given size. The syntax for its use is

  y = speye(m,n)

which forms an m x n sparse matrix with ones on the main diagonal, or

  y = speye(n)

which forms an n x n sparse matrix with ones on the main diagonal. The matrix type is a float single precision matrix.

Example

The following creates a 5000 by 5000 identity matrix, which would be difficult to do using sparse(eye(5000)) because of the large amount of intermediate storage required.

--> I = speye(5000)
I = 
  <float>  - size: [5000 5000]
	Matrix is sparse with 5000 nonzeros
--> full(I(1:10,1:10))
ans = 
  <float>  - size: [10 10]
 
Columns 1 to 3
    1.0000000          0.00000000         0.00000000      
    0.00000000         1.0000000          0.00000000      
    0.00000000         0.00000000         1.0000000       
    0.00000000         0.00000000         0.00000000      
    0.00000000         0.00000000         0.00000000      
    0.00000000         0.00000000         0.00000000      
    0.00000000         0.00000000         0.00000000      
    0.00000000         0.00000000         0.00000000      
    0.00000000         0.00000000         0.00000000      
    0.00000000         0.00000000         0.00000000      
 
Columns 4 to 6
    0.00000000         0.00000000         0.00000000      
    0.00000000         0.00000000         0.00000000      
    0.00000000         0.00000000         0.00000000      
    1.0000000          0.00000000         0.00000000      
    0.00000000         1.0000000          0.00000000      
    0.00000000         0.00000000         1.0000000       
    0.00000000         0.00000000         0.00000000      
    0.00000000         0.00000000         0.00000000      
    0.00000000         0.00000000         0.00000000      
    0.00000000         0.00000000         0.00000000      
 
Columns 7 to 9
    0.00000000         0.00000000         0.00000000      
    0.00000000         0.00000000         0.00000000      
    0.00000000         0.00000000         0.00000000      
    0.00000000         0.00000000         0.00000000      
    0.00000000         0.00000000         0.00000000      
    0.00000000         0.00000000         0.00000000      
    1.0000000          0.00000000         0.00000000      
    0.00000000         1.0000000          0.00000000      
    0.00000000         0.00000000         1.0000000       
    0.00000000         0.00000000         0.00000000      
 
Columns 10 to 10
    0.00000000      
    0.00000000      
    0.00000000      
    0.00000000      
    0.00000000      
    0.00000000      
    0.00000000      
    0.00000000      
    0.00000000      
    1.0000000


Samit K. Basu 2005-03-16