A small C library for matrix manipulation.
To install, run following commands from terminal :
make
make install
Use LIB_PATH and INCLUDE_PATH to install the library in specific directory. By default, library is installed at /usr/local/lib and header file is stored at /usr/local/include.
At compilation, use -lcmat flag. i.e.
gcc sample.c -lcmat
After installation, include cmat and use any of the following functions.
-
MATRIX* cmat_malloc(int r, int c);Returns a pointer to MATRIX structure with
rrows andccolumns. -
void cmat_free(MATRIX* m);Frees the memory allocated to the matrix pointed my
m. -
int cmat_set(MATRIX* m, int row, int col, double data);Sets the value of (
row,col) todatain the matrix pointed bym. Returns 0 on success, -1 ifroworcolis out of bounds. -
double cmat_get(MATRIX* m, int row, int col);Returns the value stored at (
row,col) in matrixm; 0 if eitherroworcolis out of bounds.
-
MATRIX* cmat_add_const(MATRIX* m, double a);Adds constant
ato the each element of matrixmand returns the new matrix. -
MATRIX* cmat_multiply_const(MATRIX* m, double a);Multiplies each element of matrix
mwithaand returns the new matrix. -
MATRIX* cmat_add(MATRIX* m, MATRIX* n);Adds two matrices
mandnand returns the new matrix. NULL if both matrices do not have same number of rows and columns. -
MATRIX* cmat_subtract(MATRIX* m, MATRIX* n);Subtracts two matrices
mandnand returns the new matrix. NULL if both matrices do not have same number of rows and columns. -
MATRIX* cmat_divide_each(MATRIX* m, MATRIX* n);Divides each element of
mwith respective element ofnand returns the new matrix. NULL if both matrices do not have same number of rows and columns. -
MATRIX* cmat_multiply_each(MATRIX* m, MATRIX* n);Multiplies each element of
mwith respective element ofnand returns the new matrix. NULL if both matrices do not have same number of rows and columns. -
MATRIX* cmat_multiply(MATRIX* m, MATRIX* n);Performs matrix multiplication on matrices
mandnand returns the answer matrix.
-
MATRIX* cmat_zeros(int r, int c);Returns a matrix of dimension
rxc, filled with zeros. -
MATRIX* cmat_ones(int r, int c);Returns a matrix of dimension
rxc, filled with ones. -
MATRIX* cmat_identity(int dim);Returns an identity matrix of dimension
dimxdim. -
MATRIX* cmat_upper_trig(int dim);Returns an upper triangular matrix of dimension
dimxdim. -
MATRIX* cmat_lower_trig(int dim);Returns an lower triangular matrix of dimension
dimxdim.
-
double cmat_min(MATRIX* m);Returns the smallest element in the matrix
m. -
double cmat_max(MATRIX* m);Returns the largest element in the matrix
m. -
MATRIX* cmat_transpose(MATRIX* m);Returns the transpose matrix of the matrix
m. -
MATRIX* cmat_normalize(MATRIX* m);Returns the normalized version of the matrix
m.
- Transpose
- Normalization
- Determinant
- Rank of the matrix
- Inverse of a matrix
- Gaussian Reduction
- Reshaping and merging
Copyright (C) 2016 Nijraj Gelani (MIT)