


MATRIX(3)              C LIBRARY FUNCTIONS              MATRIX(3)



NAME
     matrix - matrix manipulation routines

SYNOPSIS
     #include "matrix.h"             /* matrix structure definitions */

     extern int materrlevel;         /* matrix exception control */

     typedef struct {                /* matrix structure definition */
             int     row;
             int     col;
             double  *ptr;
             char    *name;
     } matrix;

     MATRIX(mat,row,col)             /* matrix cell macro */
     matrix  *mat;                   /* matrix pointer */
     int     row,col;                /* required row, col */

     matrix *matcreate(rows,cols,title)
                                     /* create a new matrix */
     int     rows;                   /* number of rows required */
     int     cols;                   /* number of columns required */
     char    *title;                 /* matrix title (for error reporting) */

     matdelete(mat)                  /* delete a matrix */
     matrix  *mat;                   /* matrix to be deleted */

     matinput(mat,ip)                /* input a matrix from file */
     matrix  *mat;                   /* matrix to be loaded */
     FILE    *ip;                    /* file stream supplying data */

     matprint(mat,op,format)         /* print a matrix to file */
     matrix  *mat;                   /* matrix to be printed */
     FILE    *op;                    /* file stream to send data */
     char    *format;                /* printf format for each data item */

     matcopy(omat,imat)              /* duplicate a matrix */
     matrix  *omat;                  /* copy */
     matric  *imat;                  /* input */

     matident(mat)                   /* generate identity matrix */
     matrix  *mat;                   /* result */

     mataddscalar(omat,imat,scal)    /* add scalar to matrix */
     matrix  *omat;                  /* result */
     matrix  *imat;                  /* input */
     double  scal;                   /* scalar value */

     matmultscalar(omat,imat,scal)   /* multiply matrix by scalar */
     matrix  *omat;                  /* result */
     matrix  *imat;                  /* input */



Sun Release 4.1         Last change: UCL                        1






MATRIX(3)              C LIBRARY FUNCTIONS              MATRIX(3)



     double  scal;                   /* scalar value */

     matadd(omat,imat1,imat2)        /* add matrices */
     matrix  *omat;                  /* result */
     matrix  *imat1,*imat2;          /* input */

     matsub(omat,imat1,imat2)        /* subtract matrices */
     matrix  *omat;                  /* result */
     matrix  *imat1,*imat2;          /* input */

     matmult(omat,imat1,imat2)       /* multiply matrices */
     matrix  *omat;                  /* result /
     matrix  *imat1,*imat2;          /* input */

     mattrans(omat,imat)             /* transpose matrix */
     matrix  *omat;                  /* result */
     matrix  *imat;                  /* input */

     double  matsolve(X,A,B)         /* solve linear equations A.X=B */
                                     /* returns determinant of coefficients */
     matrix  *X;                     /* solution vector */
     matrix  *A;                     /* coefficient matrix */
     matrix  *B;                     /* constant vector */

     double  matinv(omat,imat)       /* invert matrix */
                                     /* returns determinant of input */
     matrix  *omat;                  /* inverse */
     matrix  *imat;                  /* input */

     matsubmatrix(omat,imat,srow,scol,erow,ecol)
                                     /* copy sub-part of matrix */
     matrix  *omat;                  /* result */
     matrix  *imat;                  /* input */
     int     srow,scol;              /* starting row,col */
     int     erow,ecol;              /* ending row,col */


DESCRIPTION
     The matrix mainpulation  routines  above  provide  range  of
     functions  for  creating  and deleting matrices, for loading
     and printing, for scalar and vector arithmetic, for  finding
     solutions   and   inverting.    All  matrices  created  with
     matcreate have dynamically allocated memory and hold  double
     precision  floating  point  numbers.  matsolve uses modified
     Gaussian-Jordan elimination with partial pivoting. All  rou-
     tines  allow  the  output  matrix  to  be  one  of the input
     matrices, i.e. "matadd(A,A,A)" works with no  problems.  The
     output  matrices  are  automatically re-created.  The MATRIX
     macro, can be used to access a single element  of  a  matrix
     for reference or assignment.





Sun Release 4.1         Last change: UCL                        2






MATRIX(3)              C LIBRARY FUNCTIONS              MATRIX(3)



DIAGNOSTICS
     The internal variable materrlevel may be set to  MATERRABORT
     (default),  MATERRWARN,  or MATERRIGNORE. The default action
     is to print a message and to exit the process.  The  warning
     level,  prints  the message and continues.  The ignore level
     simply continues  processing.   matcreate  returns  NULL  on
     failure.   matsolve  and  matinv return 0.0 on failure.  The
     other routines return 0 on success and -1 on failure.

EXAMPLE
     /* invert a matrix */
     #include <stdio.h>
     #include "matrix.h"
     main()
     {
             int     size;
             matrix  *A;

             /* get square size */
             scanf("%d",&size);
             /* create matrix */
             A = matcreate(size,size,"A");
             /* load matrix */
             matinput(A,stdin);
             /* calculate inverse */
             matinv(A,A);
             /* print result */
             matprint(A,stdout,"%7g ");
             exit(0);
     }

FILES
     libmat.a   matrix subroutine library

VERSION/AUTHOR
     2.0 - Mark Huckvale



















Sun Release 4.1         Last change: UCL                        3



