/* * smallmatrix.h */ #ifndef MATUTIL #define MATUTIL #include typedef double *vector; typedef vector *matrix; static matrix new_matrix(int nrow, int ncol) { int i; vector ap; matrix a; if ((a = malloc(nrow * sizeof(vector))) == NULL) return NULL; if ((ap = malloc(nrow * ncol * sizeof(double))) == NULL) { free(a); return NULL; } for (i = 0; i < nrow; i++) a[i] = ap + (i * ncol); return a; } #endif