matrix.h
A Matrix header file
|
Matrices. More...
#include <stdio.h>
#include <malloc.h>
#include <stdlib.h>
Data Structures | |
struct | _Matrix |
Defination of a _Matrix structure to hold the matrix entries. More... | |
Typedefs | |
typedef struct _Matrix | Matrix |
Repersents the structure which holds the matrix. More... | |
Functions | |
void | matrix_print (Matrix *matrix) |
Print whole entire matrix to stdout. More... | |
void | matrix_fill (Matrix *matrix) |
This fills the entire matrix with values which are inputed in the terminal. More... | |
Matrix * | matrix_callalloc (int matrix_size) |
Creates an identity matrix that is all the diagonal entries are initialised to 1 and all other entries to zero). More... | |
Matrix * | matrix_alloc (int row_size, int col_size) |
Allocates memory for a new matrix. More... | |
void | matrix_copy (Matrix *matrix1, Matrix *matrix2) |
Copies the content of one matrix1 into matrix2. More... | |
Matrix * | matrix_multiply (const Matrix *matrix1, const Matrix *matrix2) |
Multiplies two matrices. More... | |
Matrix * | matrix_pow (Matrix *matrix, int index) |
Multiplies a matrix by itself 'n' times. More... | |
void | matrix_free (Matrix *matrix) |
Free an entire matrix. More... | |
void | row_divide (Matrix *matrix, int pivot) |
Divides an entire row of a matrix by a value of the pivot position. More... | |
void | row_operation (Matrix *multiplier_matrix, Matrix *matrix, int pivot, int row_index) |
Row operations on the matrix. More... | |
void | matrix_row_reduce (Matrix *matrix, int zero_control) |
Row echelon reduction a matrix. More... | |
void | matrix_print_part (Matrix *matrix, int start_index) |
Printing some columns of a matrix. More... | |
void | LU_decompose (Matrix *upper_triangular, Matrix *lower_triangular) |
This function performs the LU decomposition of a matrix. More... | |
void | terminate (char *string) |
Fucntion to terminate an application in case of an error. More... | |
void | matrix_subtract (Matrix *result, Matrix *matrix1, Matrix *matrix2) |
Subtracts one matrix from another. More... | |
void | matrix_add (Matrix *result, Matrix *matrix1, Matrix *matrix2) |
Adds one matrix to another. More... | |
void | matrix_invert (Matrix *inverse_matrix) |
Perform the inverse of a matrix. More... | |
int | matrix_equal_size (Matrix *matrix1, Matrix *matrix2) |
Checks if two matrices have equal rows and columns. More... | |
Matrices.
This header file contains all the functions which can be used to manipulate the matrices so as to obtain required outputs.
To create a new matrix, you will have to allocate space for the matrix using matrix_alloc or matrix_callalloc
To copy a matrix into another, use matrix_copy.
To multiply two matrices, use matrix_multiply.
To multiply a matrix by itself 'n' times (ie raise the matrix to the nth power) use matrix_pow.
To add or subtract two matrices, use matrix_add or matrix_subtract respectively.
To perform LU decompostion of a matrix, use LU_decompose.
To perform row echelon reduction of a particular matrix, use matrix_row_reduce.
To print the matrix at any time, use matrix_print or matrix_print_part
The fuction row_divide is used as an accesory function in other functions to divide a row of a matrix by a specific value.
The function row_operation is used as an accesory function in other functions to perform row operations on a matrix.
The function matrix_equal_size checks if two matrices have the same number or rows and columns
Repersents the structure which holds the matrix.
to initialise a new Matrix, simply create a variable of this type and initialise to NULL if neccesary
This function performs the LU decomposition of a matrix.
upper_triangular | A pionter to the matrix on which to perform LU decomposition. |
lower_triangular | A pointer to the lower triangular matrix |
Adds one matrix to another.
result | A matrix to hold the result of the addition |
matrix1 | The first matrix for the addition |
matrix2 | The second matrix for the addition |
Matrix* matrix_alloc | ( | int | row_size, |
int | col_size | ||
) |
Allocates memory for a new matrix.
row_size | The number of rows in the matrix |
col_size | The number of columns in the matrix |
Matrix* matrix_callalloc | ( | int | matrix_size | ) |
Creates an identity matrix that is all the diagonal entries are initialised to 1 and all other entries to zero).
matrix_size | The number of rows and columns in the identity matrix. |
Copies the content of one matrix1 into matrix2.
matrix1 | Pointer the matrix to be copied |
matrix2 | Pointer to the matrix to which the other is to be copied into |
Checks if two matrices have equal rows and columns.
matrix1 | The first matrix |
matrix2 | The second matrix |
void matrix_fill | ( | Matrix * | matrix | ) |
This fills the entire matrix with values which are inputed in the terminal.
matrix | Pointer to the matrix structure which is to be filled. |
void matrix_free | ( | Matrix * | matrix | ) |
Free an entire matrix.
matrix | The matrix to free. |
void matrix_invert | ( | Matrix * | inverse_matrix | ) |
Perform the inverse of a matrix.
inverse_matrix | The matrix which is to be inverted |
Multiplies two matrices.
matrix1 | Pointer to the first matrix for the multiplication |
matrix2 | The second matrix for the multiplication |
Multiplies a matrix by itself 'n' times.
matrix | The matrix which is to self multiplied 'n' times |
index | The number of times the matrix is to be multiplied to itself |
void matrix_print | ( | Matrix * | matrix | ) |
Print whole entire matrix to stdout.
matrix | Pointer to the matrix to be printed to stdout |
void matrix_print_part | ( | Matrix * | matrix, |
int | start_index | ||
) |
Printing some columns of a matrix.
matrix | The matrix whose part is to be printed |
start_index | The column number to start printing from |
void matrix_row_reduce | ( | Matrix * | matrix, |
int | zero_control | ||
) |
Row echelon reduction a matrix.
matrix | The matrix on which to carry out row reduction |
zero_control | Maximum amount of zeros that can be found on a row |
Subtracts one matrix from another.
result | A matrix to hold the result of the subraction |
matrix1 | The matrix to subtract from |
matrix2 | The matrix to be subtrated from another |
void row_divide | ( | Matrix * | matrix, |
int | pivot | ||
) |
Divides an entire row of a matrix by a value of the pivot position.
matrix | The matrix whose row is to be divided |
pivot | The pivot postion of the matrix to do the division |
Row operations on the matrix.
multiplier_matrix | A matrix to store the various multipliers used in row reduction |
matrix | A matrix on which to carry out the row operations |
pivot | The pivot position of the matrix to use |
row_index | The row number on which to carry out row operations |
void terminate | ( | char * | string | ) |
Fucntion to terminate an application in case of an error.
string | Message to displayed to stdout in case of an error |