For this project you need to have Make and g++
In the directory, you can compile the library by using the command $ make
int main(int argc, char * const *argv)
{
// Create a new matrix of 2 x 3.
matrix_t *matrix = zeros(2, 3);
// Display the matrix content
matrix_display(matrix);
return (0);
}There are different functions to create a matrix. The next functions are going to have several parameters in common. Other parameters will be descripted directly in the functions description.
- rows - Number - The number of rows in the matrix.
- cols - Number - The number of columns in the matrix.
This function create a matrix of rows x cols, filled with zeros.
// Create a matrix of 2 x 3.
zeros(2, 3);This function create a matrix of rows x cols, filled with value.
- value - Float - The value used to fill the matrix.
// Create a matrix of 4 x 1 filled with -1.
custom(4, 1, -1);This function create a n x n identity matrix.
- n - Number - Size of the matrix (n x n).
// Create a 4 x 4 identity matrix.
identity(4);This function destroy properly matrix.
matrix_destroy(matrix);The next functions are going to have several parameters in common. Other parameters will be descripted directly in the functions description.
- a - Matrix - The first matrix.
- b - Matrix - The second matrix.
This function will display the matrix a with a precision of prec.
- prec - Number - Number of digits after the point (default : 2).
// Display the matrix a with a precision of 5.
matrix_display_prec(a, 5);This function return a new matrix who is the sum of the matrix a and the matrix b.
// This will add the matrix a and b and put the result in sum.
matrix_t *sum = matrix_add(a, b);
// Then the result is displayed in the standard output.
matrix_display(sum);This function return a new matrix who is the substract of the matrix a by the matrix b.
// This will substract the matrix a by b and put the result in sub.
matrix_t *sub = matrix_sub(a, b);
// Then the result is displayed in the standard output.
matrix_display(sub);This function multiply the matrix a by the factor coef.
// Create a new 3 x 4 matrix filled with 2
matrix_t *matrix = custom(3, 4, 2);
// Multiplie matrix values by 1.5
matrix_scale(matrix, 1.5);
// Display the matrix (filled with 3 so)
matrix_display(matrix);This function return a new matrix who is the multiplication of the matrix a by the matrix b.
// This will multiply the matrix a by b and put the result in sub.
matrix_t *mul = matrix_sub(a, b);
// Then the result is displayed in the standard output.
matrix_display(mul);This function return a new matrix who is the division of the matrix a by the matrix b.
// This will multiply the matrix a by b and put the result in sub.
matrix_t *div = matrix_sub(a, b);
// Then the result is displayed in the standard output.
matrix_display(div);