A lightweight C library for common matrix operations, including determinant calculation, matrix inversion, transposition, and more.
| File | Description |
|---|---|
matrixlib.h | Header file — function declarations |
matrixlib.c | Library implementation |
example01.c | Usage example 1 |
example02.c | Usage example 2 |
example03.c | Usage example 3 |
Include matrixlib.c in your build alongside your source file:
gcc your_program.c matrixlib.c -o your_programInclude the header in your C file:
#include"matrixlib.h"All matrices are represented as double ** (pointer to pointer to double).
double**seed(introws, intcolumns);Allocates and initializes a new matrix with the given dimensions.
double**identity_matrix(intsize);Creates a square identity matrix of the given size.
double**reallocMatrix(double**original, introws, intcolumns);Reallocates an existing matrix to new dimensions.
double**transpose(double**matrix, introws, intcolumns);Returns the transpose of the given matrix.
double**scalar_multiplication(double**matrix, introws, intcolumns, longnumber);Multiplies every element of a matrix by a scalar value.
double**sum_matrices(double**matrix1, double**matrix2, introws, intcolumns, inttype);Adds or subtracts two matrices of equal dimensions. The type parameter controls the operation (e.g., addition or subtraction).
double**matricial_multiplication(double**matrix1, double**matrix2,
intmatrix1_rows, intmatrix1_columns,
intmatrix2_rows, intmatrix2_columns);Multiplies two matrices. Requires matrix1_columns == matrix2_rows.
doubledeterminant(double**matrix, intsize);Computes the determinant of a square matrix.
double**inverse_matrix(double**matrix, intsize);Returns the inverse of a square matrix. The matrix must be non-singular (i.e., determinant != 0).
#include<stdio.h>#include"matrixlib.h"intmain() {
intsize=3;
// Create a 3x3 identity matrixdouble**m=identity_matrix(size);
// Compute its determinant (should be 1.0)doubledet=determinant(m, size);
printf("Determinant: %f\n", det);
// Get its inverse (should also be the identity)double**inv=inverse_matrix(m, size);
return0;
}- C compiler (GCC recommended)
- C standard library
Do whatever you want with it.