/* *----------------------------------------------------------------------------- * file: matcreat.c * desc: matrix mathematics - object creation * by: ko shu pui, patrick * date: 24 nov 91 v0.1 * revi: 14 may 92 v0.2 * 21 may 92 v0.3 * ref: * [1] Mary L.Boas, "Mathematical Methods in the Physical Sciene," * John Wiley & Sons, 2nd Ed., 1983. Chap 3. * * [2] Kendall E.Atkinson, "An Introduction to Numberical Analysis," * John Wiley & Sons, 1978. * *----------------------------------------------------------------------------- */ #include #ifdef __TURBOC__ #include #else #include #endif #include "matrix.h" MATRIX _mat_creat( row, col ) int row, col; { MATBODY *mat; int i, j; if ((mat = (MATBODY *)malloc( sizeof(MATHEAD) + sizeof(double *) * row)) == NULL) return (mat_error( MAT_MALLOC )); for (i=0; imatrix) + i) = (double *)malloc(sizeof(double) * col)) == NULL) return (mat_error( MAT_MALLOC )); } mat->head.row = row; mat->head.col = col; return (&(mat->matrix)); } /* *----------------------------------------------------------------------------- * funct: mat_creat * desct: create a matrix * given: row, col = dimension, type = which kind of matrix * retrn: allocated matrix (use mat_free() to free memory) *----------------------------------------------------------------------------- */ MATRIX mat_creat( row, col, type ) int row, col, type; { MATRIX A; if ((A =_mat_creat( row, col )) != NULL) { return (mat_fill(A, type)); } else return (NULL); } /* *----------------------------------------------------------------------------- * funct: mat_fill * desct: form a special matrix * given: A = matrix, type = which kind of matrix * retrn: A *----------------------------------------------------------------------------- */ MATRIX mat_fill( A, type ) MATRIX A; int type; { int i, j; switch (type) { case UNDEFINED: break; case ZERO_MATRIX: case UNIT_MATRIX: for (i=0; i *----------------------------------------------------------------------------- */ int mat_free( A ) MATRIX A; { int i; if (A == NULL) return (0); for (i=0; i