/* sparse.h Sparse storage of a matrix * specifically designed for solving PDE * simultaneous equations. * zero based subscripting * column (nrow) is right hand side * * #include "sparse.h" * struct sparse A; * int nrow = 100; * int i,j; * double val; * sparseInit(&A,nrow); * sparsePut(A,i,j,val); */ #include static int nrow; struct cell; typedef struct cell* link; struct cell { int j; /* = -1; */ double val; /* = 0.0; */ link next; /* = NULL; */ }; struct sparse { int nrow; link* A; }; void sparseInit(struct sparse* A, int nrow); void sparsePut(struct sparse A, int i, int j, double val); void sparseAdd(struct sparse A, int i, int j, double val); void sparseSimeq(struct sparse A, double X[]); /* X returned solution */ void sparseMul(struct sparse A, double X[], double Y[]); /* Y output */ void sparseImport(struct sparse A, double M[]); /* single index i*nrow+j */ void sparseExport(struct sparse A, double M[]); /* size nrow*(nrow-1) */ double sparseGet(struct sparse A, int i, int j); void sparseGetRHS(struct sparse A, double Y[]); void sparseSetRHS(struct sparse A, double Y[]); void sparseWrite_All(struct sparse A); void sparseDivide(struct sparse A, int krow, int k); /* works on a krow j=k+1..n */ void sparseReduce(struct sparse A, int irow, int k, int krow); /* works on complete irow j=k+1..n */ /* using krow j=k+1..n where it exists */ /* end sparse.h */