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(int rows, int columns);Allocates and initializes a new matrix with the given dimensions.
double **identity_matrix(int size);Creates a square identity matrix of the given size.
double **reallocMatrix(double **original, int rows, int columns);Reallocates an existing matrix to new dimensions.
double **transpose(double **matrix, int rows, int columns);Returns the transpose of the given matrix.
double **scalar_multiplication(double **matrix, int rows, int columns, long number);Multiplies every element of a matrix by a scalar value.
double **sum_matrices(double **matrix1, double **matrix2, int rows, int columns, int type);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,
int matrix1_rows, int matrix1_columns,
int matrix2_rows, int matrix2_columns);Multiplies two matrices. Requires matrix1_columns == matrix2_rows.
double determinant(double **matrix, int size);Computes the determinant of a square matrix.
double **inverse_matrix(double **matrix, int size);Returns the inverse of a square matrix. The matrix must be non-singular (i.e., determinant != 0).
#include <stdio.h>
#include "matrixlib.h"
int main() {
int size = 3;
// Create a 3x3 identity matrix
double **m = identity_matrix(size);
// Compute its determinant (should be 1.0)
double det = determinant(m, size);
printf("Determinant: %f\n", det);
// Get its inverse (should also be the identity)
double **inv = inverse_matrix(m, size);
return 0;
}- C compiler (GCC recommended)
- C standard library
Do whatever you want with it.