4 // code to generate a sparse Hamiltonian matrix //
5 // H matrix filled with random numbers at random locations //
7 // assignment 2 - part b //
9 // Michel Vallieres, Fall 2007 //
17 /* # non-zero elements */
18 #define Nelements 1012717
21 int main( int argc, char * argv[] )
25 int scan, repeat, kepti[Nelements], keptj[Nelements];
28 fp = fopen( "sparse_Hamiltonian_size", "w" );
29 fprintf( fp, "%d %d\n", N, Nelements);
32 fp = fopen( "sparse_Hamiltonian", "w" );
33 /* initialize random numbers */
35 /* loop over non-zero Hij */
37 while ( element<Nelements )
40 i = N * (float)rand() / (float)RAND_MAX;
41 j = N * (float)rand() / (float)RAND_MAX;
43 /* symmetric matrix */
51 /* avoid repetition */
56 while ( scan < element )
58 if ( i == kepti[scan] && j == keptj[scan] )
71 Hij = (float)rand() / (float)RAND_MAX;
76 fprintf( fp, "%d %d %f\n", i, j, Hij );