/* mpf_sparse.h Sparse storage of a matrix * specifically designed for solving PDE * simultaneous equations. * zero based subscripting * column (nrow) is right hand side * * #include "mpf_sparse.h" * struct sparse A; * int nrow = 100; * int i,j; * mpf_t val; * sparseInit(&A, nrow); * sparsePut(A, i, j, val); * sparseGet(result, A, i, j); * sparseSimeq(A, X); X returned solution */ #include #include extern int digits; static int nrow; struct cell; typedef struct cell* link; struct cell { int j; /* = -1; when created */ mpf_t 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, mpf_t val); void sparseAdd(struct sparse A, int i, int j, mpf_t val); void sparseSimeq(struct sparse A, mpf_t X[]); /* X returned solution */ void sparseMul(struct sparse A, mpf_t X[], mpf_t Y[]); /* Y output */ void sparseImport(struct sparse A, mpf_t M[]); /* single index i*nrow+j */ void sparseExport(struct sparse A, mpf_t M[]); /* size nrow*(nrow-1) */ void sparseGet(mpf_t result, struct sparse A, int i, int j); void sparseGetRHS(struct sparse A, mpf_t Y[]); void sparseSetRHS(struct sparse A, mpf_t 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 */ int sparseGetCellCount(); /* of nrow*(nrow+1) */ /* end mpf_sparse.h */