Wolfram Function Repository
Instant-use add-on functions for the Wolfram Language
Function Repository Resource:
Create a random sparse symmetric positive definite matrix
| ResourceFunction["RandomSparseSPDMatrix"][n] creates an n×n random sparse symmetric positive definite matrix. | 
| "CholeskyFactorDensity" |  | density of the off-diagonal entries of the Cholesky factor | 
| “CholeskyFactorRange" | {  ,1} | the min and max values of the off-diagonal entries of the Cholesky factor | 
| WorkingPrecision | MachinePrecision | the precision to use in internal computations | 
Construct a random symmetric positive definite matrix:
| In[1]:= | ![ResourceFunction["RandomSparseSPDMatrix"][7]](https://www.wolframcloud.com/obj/resourcesystem/images/947/947a6e97-91fe-418d-a62f-799ef5f735f6/20f3342b09789f15.png) | 
| Out[1]= |  | 
Show the matrix:
| In[2]:= | ![Normal[%] // MatrixForm](https://www.wolframcloud.com/obj/resourcesystem/images/947/947a6e97-91fe-418d-a62f-799ef5f735f6/124bc54f4daff15b.png) | 
| Out[2]= |  | 
Verify that the matrix is symmetric and positive definite:
| In[3]:= | ![SymmetricMatrixQ[%] && PositiveDefiniteMatrixQ[%]](https://www.wolframcloud.com/obj/resourcesystem/images/947/947a6e97-91fe-418d-a62f-799ef5f735f6/237ea0660cf32c73.png) | 
| Out[3]= |  | 
Use the option "CholeskyFactorDensity"to construct a dense matrix:
| In[4]:= | ![ResourceFunction["RandomSparseSPDMatrix"][5, "CholeskyFactorDensity" -> 1]](https://www.wolframcloud.com/obj/resourcesystem/images/947/947a6e97-91fe-418d-a62f-799ef5f735f6/6b553e36acc99d4f.png) | 
| Out[4]= |  | 
| In[5]:= | ![Normal[%] // MatrixForm](https://www.wolframcloud.com/obj/resourcesystem/images/947/947a6e97-91fe-418d-a62f-799ef5f735f6/7ad45a16a420c94e.png) | 
| Out[5]= |  | 
Create a matrix with larger numerical values using the "CholeskyFactorRange" option:
| In[6]:= | ![ResourceFunction["RandomSparseSPDMatrix"][5, "CholeskyFactorRange" -> {0.1, 10}]](https://www.wolframcloud.com/obj/resourcesystem/images/947/947a6e97-91fe-418d-a62f-799ef5f735f6/4eb10fd49caa0e25.png) | 
| Out[6]= |  | 
| In[7]:= | ![Normal[%] // MatrixForm](https://www.wolframcloud.com/obj/resourcesystem/images/947/947a6e97-91fe-418d-a62f-799ef5f735f6/771e5a6a315a1468.png) | 
| Out[7]= |  | 
A random symmetric positive definite matrix with machine-number entries:
| In[8]:= | ![ResourceFunction["RandomSparseSPDMatrix"][5, WorkingPrecision -> MachinePrecision]](https://www.wolframcloud.com/obj/resourcesystem/images/947/947a6e97-91fe-418d-a62f-799ef5f735f6/3b50c49e42033e47.png) | 
| Out[8]= |  | 
| In[9]:= | ![Normal[%] // MatrixForm](https://www.wolframcloud.com/obj/resourcesystem/images/947/947a6e97-91fe-418d-a62f-799ef5f735f6/073ca4192657376c.png) | 
| Out[9]= |  | 
A random symmetric positive definite matrix with 24-digit precision entries:
| In[10]:= | ![ResourceFunction["RandomSparseSPDMatrix"][5, WorkingPrecision -> 24]](https://www.wolframcloud.com/obj/resourcesystem/images/947/947a6e97-91fe-418d-a62f-799ef5f735f6/06edde476c73c1ce.png) | 
| Out[10]= |  | 
| In[11]:= | ![Normal[%] // MatrixForm](https://www.wolframcloud.com/obj/resourcesystem/images/947/947a6e97-91fe-418d-a62f-799ef5f735f6/00bc26098146773c.png) | 
| Out[11]= |  | 
This work is licensed under a Creative Commons Attribution 4.0 International License