Author: Alessandro Conti - AlessandroConti11
License: MIT license.
Tags: #C
, #cofactor
, #determinant
, #inverse_matrix
, #matrix
, #matrix_operation
, #matrix_type
, #minor
, #pivot
, #rank
, #row_echelon_matrix
, #transpose_matrix
.
The project aims to create a library that contains all useful functions for handling matrices and their operations.
For all functions that require a result: you must provide the requested data structure (you can also use the one present as input).
Operation | Function | Description | Order of the Matrices | Example of Mathematical Representation |
---|---|---|---|---|
create a matrix | matrix *createMatrix(int n, int m); | create an empty matrix | ||
create identity matrix | matrix *createIdentityMatrix(int n); | create an identity matrix | ||
create a null matrix | matrix *createNullMatrix(int n, int m); | create a null matrix | ||
initialize a matrix | void initializeMatrix(matrix *a, ...); | initialize an empty matrix by filling it by rows | ||
copy a matrix | void copyMatrix(matrix *a, matrix *b); | copy a matrix to another | ||
delete a matrix | void deleteMatrix(matrix *a); | delete a given matrix | ||
print a matrix | void printMatrix(matrix *a); | print a given matrix | ||
check if a matrix is an identity matrix | int isIdentityMatrix(matrix *a); | check whether the matrix only elements on the main diagonal equal 1 and the others equal | ||
check if a matrix is a null matrix | int isNullMatrix(matrix *a); | check whether the all matrix elements are equal to 0 | ||
check if a matrix is a diagonal matrix | int isDiagonalMatrix(matrix *a); | check whether the matrix has all elements not on the main diagonal equal to 0 | ||
check if a matrix is anti-diagonal matrix | int isAntidiagonalMatrix(matrix *a); | check whether the matrix has all elements not on the secondary diagonal equal to 0 | ||
check if a matrix is an upper diagonal matrix | int isUpperDiagonalMatrix(matrix *a); | check whether the matrix has all elements below the main diagonal equal to 0 | ||
check if a matrix is a lower diagonal matrix | int isLowerDiagonalMatrix(matrix *a); | check whether the matrix has all elements above the main diagonal equal to 0 | ||
check if a matrix is a symmetric matrix | int isSymmetricMatrix(matrix *a); | check whether the matrix has all the element (i, j) equal to the element (j, i) | ||
check if a matrix is an anti-symmetric matrix | int isAntisymmetricMatrix(matrix *a); | check whether the matrix has the elements (i, j) opposite to those (j, i) | ||
check if a matrix is invertible | int isInvertibleMatrix(matrix *a); | check whether the determinant is different from 0 | ||
check if a matrix is a row-echelon matrix | int isRowEchelonMatrix(matrix *a); | check whether the first nonzero element of each row is further to the right than the first nonzero element of the previous row. | ||
check if a matrix is an Hankel matrix | int isHankelMatrix(matrix *a); | check whether the matrix has all the element (i, j) equal to the element (i-1, j+1) | ||
check if a matrix is a Toeplitz matrix | int isToeplitzMatrix(matrix *a); | check whether the matrix has all the element (i, j) equal to the element (i-1, j-1) | ||
transpose a matrix | void transposingMatrix(matrix *a, matrix *trans); | the transposed matrix is given by the elements (j, i) | ||
invert a matrix | void inverseMatrix(matrix *a, matrix *inv); | inverse the matrix using the method of cofactors | ||
transform a matrix to a row-echelon matrix | void rowEchelonMatrix(matrix *a, matrix *step); | transform the matrix using the Gaussian elimination method | ||
compute the absolute matrix | void absMatrix(matrix *a, matrix *abs); | compute the absolute value for each matrix element | ||
compute the minor of a matrix | double minor(matrix *a, int row, int column); | compute the minor (row, column)-th, the determinant of the matrix without the row and the column specified | ||
compute the cofactor of a matrix | double cofactor(matrix *a, int row, int column); | compute the cofactor (row, column)-th, the (-1)^(row+column) determinant of the matrix without the row and the column specified | ||
compute the determinant of a matrix | double determinantMatrix(matrix *a); | compute the determinant of the matrix | ||
compute the rank of a matrix | int rankMatrix(matrix *a); | compute the rank of the matrix using the minor method | ||
compute the sum between two matrices | void sumMatrix(matrix *a, matrix *b, matrix *res); | compute the sum between two given matrices | ||
compute the difference between two matrices | void subMatrix(matrix *a, matrix *b, matrix *res); | compute the difference between two given matrices | ||
compute the scalar product of a matrix | void scalarProductMatrix(double scalar, matrix *a, matrix *res); | compute the scalar product of the matrix | ||
compute the product between two matrices | void productMatrix(matrix *a, matrix *b, matrix *res); | compute the product between two given matrices | ||
compute the power elevation of a matrix | void powerMatrix(matrix *a, int k, matrix *res); | compute the power elevation of the matrix | ||
compute the direct sum between two matrices | void directSumMatrix(matrix *a, matrix *b, matrix *res); | compute the direct sum between two matrices, the first matrix is placed in the upper-left corner and the second matrix in the bottom-right corner | ||
compute the Kronecker product between two matrices | void kroneckerProductMatrix(matrix *a, matrix *b, matrix *res); | compute the Kronecker product between two matrices | ||
swap two rows of a matrix | void swapRowMatrix(matrix *a, int row1, int row2, matrix *swap); | swap two rows of given matrix | ||
swap two column of a matrix | void swapColumnMatrix(matrix *a, int col1, int col2, matrix *swap); | swap two column of given matrix | ||
find the maximum value in a matrix | double findMaxMatrix(matrix *a, int *rowPos, int *colPos); | find the maximum value in the matrix and return its position | ||
find the minimum value in a matrix | double findMinMatrix(matrix *a, int *rowPos, int *colPos); | find the minimum value in the matrix and return its position | ||
find the elements on the diagonal of a matrix | double *diagonalMatrix(matrix *a, int *numberOfElements); | find the elements on the diagonal of the matrix | ||
find the pivot in a matrix | double *pivot(matrix *a, int *pivotsNumber); | find the pivots in the matrix transforming it in a row-echelon matrix | ||
decompose a matrix using Lower-Upper decomposition | void luDecomposition(matrix *a, matrix *l, matrix *u); | decompose a matrix using Lower-Upper decomposition, the matrix is decomposed in a lower triangular matrix and an upper triangular matrix |
- install gcc
sudo apt-get install gcc
- compile the project
gcc -Wall -Werror -O2 -g3 main.c -o EXECUTABLE
- run the project
./EXECUTABLE
The Makefile in the repository can also be used to compile the code.
- this option allows you to compile with the following tags: -Wall -Werror -O2 -g3
make compile
- if you want to specify different tags, you can set them
make compile CFLAGS=YOUR_FLAGS
- if you want to use Address SANitizer
make asan
- if you want to delete some file - default is the executable file
make clean
- If you find a security vulnerability, do NOT open an issue. Email Alessandro Conti instead.
- If you find a bug or error or want to add some other function that is not implemented yet
- FORK the repo
- CLONE the project to your own machine
- COMMIT to your own branch
- PUSH your work back up to your fork
- submit a PULL REQUEST so that I can review your changes
NOTE: Be sure to merge the latest from "upstream" before making a pull request!
Each new function must be documented using the following style:
- Short function description: A brief description explaining what the function does.
- @details: A detailed section describing how the function works, explaining the algorithms and logic used.
- @warning: A section listing all the assumptions made by the function, such as the preconditions that the parameters must fulfil.
- Blank line: Add a blank line to separate the documentation sections.
- @param: A list of the parameters required by the function, each accompanied by a brief description of its role and type.
- @return: A description of what the function returns, including the data type.
Within the function, each variable must be commented out to explain its purpose. In general, any additional comments that might improve understanding of the code are welcome. 😃