Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

History

7 Commits

Repository files navigation

Matrix

A lightweight C library for common matrix operations, including determinant calculation, matrix inversion, transposition, and more.

Files

FileDescription
matrixlib.hHeader file — function declarations
matrixlib.cLibrary implementation
example01.cUsage example 1
example02.cUsage example 2
example03.cUsage example 3

Getting Started

Compilation

Include matrixlib.c in your build alongside your source file:

gcc your_program.c matrixlib.c -o your_program

Usage

Include the header in your C file:

#include"matrixlib.h"

API Reference

All matrices are represented as double ** (pointer to pointer to double).

Matrix Creation

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.

Matrix Operations

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.

Matrix Analysis

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).

Example

#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;
}

Requirements

  • C compiler (GCC recommended)
  • C standard library

License

Do whatever you want with it.

About

Matrix

Resources

Stars

1 star

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages