Skip to content

Library for matrix creation and basic operations on matrices. Written on C.

Notifications You must be signed in to change notification settings

georghegel/matrix

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

34 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Kendrick Lamar - Section .80

Kendrick Lamar - Section .80

Beginning of the new era

matrix

Matrix - is a library with basic operations, written on C.
It allows to create, delete, add/subtract/multiply matrices.
Also you can get determinant, inverse and algebraic complements in O(n^3) time complexity.

Installation and usage

MacOS

$ git clone https://github.com/georghegel/matrix.git
$ cd matrix
$ make

For testing:

$ make test

Ubuntu

Pretty similar to macOS.
for now make test doesn't work correctly, and I'm fixing it

$ git clone https://github.com/georghegel/matrix.git
$ cd matrix
$ make

For testing:

$ make test

Windows

not ready yet

Matrix creation, deletion, comparer

Create matrix (initial matrix will be filled with zeros):

matrix_t my_matrix;
create_matrix(3, 3, &my_matrix);

my_matrix[0][0] = 7;
my_matrix[0][1] = 3;
my_matrix[0][2] = 4;

my_matrix[1][0] = 5;
my_matrix[1][1] = 2;
my_matrix[1][2] = 1;

my_matrix[2][0] = 9;
my_matrix[2][1] = 11;
my_matrix[2][2] = 17;

Delete matrix:

delete_matrix(&my_matrix);

Next function returns 0 if element-wise comparison is successful (e.g. each corresponding element are equal).
Otherwise 1 will return.

matrix_t A, B;
create_matrix(3, 3, &A);
create_matrix(3, 3, &B);

// fill matrix A and B with your values as we did before

int res = eq_matrix(&A, &B);

Basic operations on matrices

Addition/subtraction:

matrix_t A, B, result;

create_matrix(3, 3, &A);
create_matrix(3, 3, &B);

sum_matrix(&A, &B, &result);
sub_matrix(&A, &B, &result); 

Scalar multiplication:

double number = 2.73;

mult_number(&A, number, &result);

Matrix multiplication:

matrix_t A, B, result;

create_matrix(3, 4, &A);
create_matrix(4, 5, &B);

mult_matrix(&A, &B, &result);

Transpose

Matrix transposition:

matrix_t A, result;

create_matrix(3, 7, &A);

transpose(&A, &result);
// result matrice's rows and cols = (7, 3);

Determinant, inverse and algebraic complements matrix

Determinant:(a bit difficult concept)

double result = 0.0;
determinant_m(&A, &result);

Inverse matrix:

inverse(&A, &result);

Algebraic complements matrix:
To understand this concept you should be familiar with minors, which is obvious.

complements(&A, &result);

References:

[1] Кострикин - Введение в Алгебру
[2] Винберг - Курс алгебры
[3] Gauss elimination - wikipedia
[4] Invertible matrices - wikipedia