My Project
 All Classes Files Functions Variables Typedefs Enumerations Enumerator
Classes | Typedefs | Functions
matrix.h File Reference
#include <stdbool.h>

Go to the source code of this file.

Classes

struct  Matrix
 

Typedefs

typedef struct Matrix Matrix
 

Functions

Matrixcreate_matrix (int rows, int columns)
 Returns a pointer to a Matrix with rows rows and columns columns. Note that the new matrix is empty, but it's elemnts are, by default 0. More...
 
void read_matrix (Matrix *a)
 Utility function used to read a matrix from the standard input. More...
 
int print_matrix (Matrix *a)
 utility function used to print a matrix to the standar output. More...
 
Matrixget_minor (Matrix *a, int line, int column)
 Returns the minorant of a matrix by a specific row and column. More...
 
void multiply_matrix_with_scalar (Matrix *a, double scalar)
 Multiplies a matrix a with an scalar. Note that the new value of the matrix will be the result of this operation. More...
 
int get_transpose (Matrix *a, Matrix **transpose)
 Stores the transpose of the matrix a in the matrix transpose. More...
 
void destroy_matrix (Matrix *a)
 
int compute_inverse (Matrix *a)
 Computes the inverse of the matrix a. Note that the inverse of matrix a will be stored in the inverse member of a. So, after calling this function you will access the inverse of a like this: a->inverse. More...
 
double get_determinant (Matrix *a)
 Returns the determinant of a matrix. More...
 
int multiply_matrices (Matrix *a, Matrix *b, Matrix **result)
 Multiplies the matrices a and b and stores their results in the matrix result. Note that the function will alocate memory for the matrix result. More...
 
int add_matrices (Matrix *a, Matrix *b, Matrix **result)
 Use this function to add 2 matrices. Note that the result will be stored in a third matrix. More...
 
void copy_matrix (Matrix *a, Matrix **destination)
 Copies the contents of the matrix a to the matrix destinaation. More...
 
Matrixmatrix_pow (Matrix *a, int power)
 raise the matrix a to the power power. More...
 
bool compare_matrices (Matrix *a, Matrix *b)
 Use this function to compare to matrices. The criteria used to compare the matrices are the dimensions and the actual values of the 2 matrices. More...
 

Typedef Documentation

typedef struct Matrix Matrix

Function Documentation

int add_matrices ( Matrix a,
Matrix b,
Matrix **  result 
)

Use this function to add 2 matrices. Note that the result will be stored in a third matrix.

Parameters
aAn instance of Matrix.
bAn instance of Matrix.
cAn instance of Matrix.
Returns
int Returns and error status.
bool compare_matrices ( Matrix a,
Matrix b 
)

Use this function to compare to matrices. The criteria used to compare the matrices are the dimensions and the actual values of the 2 matrices.

Parameters
aAn instance of struct matrix.
bAn instance of sruct martix.
Returns
bool 1 if the matrices are equal and 0 otherwise.
int compute_inverse ( Matrix a)

Computes the inverse of the matrix a. Note that the inverse of matrix a will be stored in the inverse member of a. So, after calling this function you will access the inverse of a like this: a->inverse.

Parameters
aThe matrix that we want to compute inverse of.
Returns
int If the matrix doesn't have an inverse the NO_INVERSE error will be returned, otherwise NO_ERROR.
void copy_matrix ( Matrix a,
Matrix **  destination 
)

Copies the contents of the matrix a to the matrix destinaation.

Parameters
aThe matrix whose contents we will copy.
destinationThe matrix where the contents of a will be stored. Note that the functio doesn't allocate memory for destination you should create this matrix by yourself.
Returns
void It doesn't return anything.
Matrix* create_matrix ( int  rows,
int  columns 
)

Returns a pointer to a Matrix with rows rows and columns columns. Note that the new matrix is empty, but it's elemnts are, by default 0.

Parameters
rowsThe number of rows of the matrix.
columnsThe number of columns of the matrix.
Returns
Matrix A pointer to an empty Matrix.
void destroy_matrix ( Matrix a)

Dealocates the memory allocated for a matrix, after calling this function on a matrix all memory used for that matrix will be dealocated, this includes, also, the memory alocate for it's inverse.

Parameters
aThe matrix that should be destroyed.
Returns
void It doesn't return anything.
double get_determinant ( Matrix a)

Returns the determinant of a matrix.

Parameters
aThe matrix whose determinant will be computed.
Returns
double The determinant of matrix a.
Matrix* get_minor ( Matrix a,
int  line,
int  column 
)

Returns the minorant of a matrix by a specific row and column.

Parameters
aThe matrix that we want to compute the minorant of.
lineThe line That should be elimined when selecting the minorant.
columThe column that should be elimined when computing the minorant.
Returns
Matrix * It returns NULL or a pointer o to a Matrix that represents the minorant of the matrix a.
int get_transpose ( Matrix a,
Matrix **  transpose 
)

Stores the transpose of the matrix a in the matrix transpose.

Parameters
aThe matrix that the transpose of we will compute.
transposeThis matrix will hold the value of the matrix a. Note that you should pass a reference to the matrix transpose. That's the way a call to this function would look like: get_transpose(some_matrix, &transpose_of_a). Also, keep in mind that the matrix transpose doesn't need to be initialized, the function will do that for you;
Returns
int CANT_CREATE_MATRIX if the transpose can't be created and NO_ERROR if all wen ok.
Matrix* matrix_pow ( Matrix a,
int  power 
)

raise the matrix a to the power power.

Parameters
aThe matrix that will be raised to the power power.
powerThe power that the matrix a will be raised to.
Returns
Matrix * Returns a matrix that will contain the result of raising a to power.
int multiply_matrices ( Matrix a,
Matrix b,
Matrix **  result 
)

Multiplies the matrices a and b and stores their results in the matrix result. Note that the function will alocate memory for the matrix result.

Parameters
aThe matrix who will be multiplied with matrix b.
bThe matrix wo will be multiplied with matrix a.
Returns
int SIZE_NOT_MATCH if matrix a doesn't have the same number of lines as the matrix b, CANT_CREATE_MATRIX if the function can't allocate memory for the matrix result and NO_ERROR if the matrices successully multiplied.
void multiply_matrix_with_scalar ( Matrix a,
double  scalar 
)

Multiplies a matrix a with an scalar. Note that the new value of the matrix will be the result of this operation.

Parameters
aThe matrix that should be multiplied with an scalar.
scalarThe scalar that should be multiplied withe the matrix a.
Returns
void It doesn't return anything.
int print_matrix ( Matrix a)

utility function used to print a matrix to the standar output.

Parameters
aThe matrix that should be printed.
Returns
int If the matrix doesn't exists it will return MATRIX_NOT_EXISTS and NO_ERROR if the matrix was successfully printed.
void read_matrix ( Matrix a)

Utility function used to read a matrix from the standard input.

Parameters
aThe matrix in which the readed elements will be stored.

void It doesn't return anything.