matrix.h
A Matrix header file
Data Structures | Typedefs | Functions
matrix.h File Reference

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...
 
Matrixmatrix_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...
 
Matrixmatrix_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...
 
Matrixmatrix_multiply (const Matrix *matrix1, const Matrix *matrix2)
 Multiplies two matrices. More...
 
Matrixmatrix_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...
 

Detailed Description

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

Typedef Documentation

typedef struct _Matrix Matrix

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

See Also
matrix_alloc

Function Documentation

void LU_decompose ( Matrix upper_triangular,
Matrix lower_triangular 
)

This function performs the LU decomposition of a matrix.

Parameters
upper_triangularA pionter to the matrix on which to perform LU decomposition.
lower_triangularA pointer to the lower triangular matrix
Note
You should allocate memory for the lower_triangular matrix with matrix_callalloc before passing it to this function
void matrix_add ( Matrix result,
Matrix matrix1,
Matrix matrix2 
)

Adds one matrix to another.

Parameters
resultA matrix to hold the result of the addition
matrix1The first matrix for the addition
matrix2The second matrix for the addition
Matrix* matrix_alloc ( int  row_size,
int  col_size 
)

Allocates memory for a new matrix.

Parameters
row_sizeThe number of rows in the matrix
col_sizeThe number of columns in the matrix
Returns
The location of the memory block that was allocated to hold 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).

Parameters
matrix_sizeThe number of rows and columns in the identity matrix.
Returns
A pointer to the new identity matrix just created
void matrix_copy ( Matrix matrix1,
Matrix matrix2 
)

Copies the content of one matrix1 into matrix2.

Parameters
matrix1Pointer the matrix to be copied
matrix2Pointer to the matrix to which the other is to be copied into
int matrix_equal_size ( Matrix matrix1,
Matrix matrix2 
)

Checks if two matrices have equal rows and columns.

Parameters
matrix1The first matrix
matrix2The second matrix
Returns
Non-zero if the matrix row and columns are equal, zero if they are not equal.
void matrix_fill ( Matrix matrix)

This fills the entire matrix with values which are inputed in the terminal.

Parameters
matrixPointer to the matrix structure which is to be filled.
void matrix_free ( Matrix matrix)

Free an entire matrix.

Parameters
matrixThe matrix to free.
void matrix_invert ( Matrix inverse_matrix)

Perform the inverse of a matrix.

Parameters
inverse_matrixThe matrix which is to be inverted
Matrix* matrix_multiply ( const Matrix matrix1,
const Matrix matrix2 
)

Multiplies two matrices.

Parameters
matrix1Pointer to the first matrix for the multiplication
matrix2The second matrix for the multiplication
Returns
The location of a matrix which holds the result of the multiplication
Matrix* matrix_pow ( Matrix matrix,
int  index 
)

Multiplies a matrix by itself 'n' times.

Parameters
matrixThe matrix which is to self multiplied 'n' times
indexThe number of times the matrix is to be multiplied to itself
Returns
The location of the matrix which holds the results of the multiplications
void matrix_print ( Matrix matrix)

Print whole entire matrix to stdout.

Parameters
matrixPointer to the matrix to be printed to stdout
void matrix_print_part ( Matrix matrix,
int  start_index 
)

Printing some columns of a matrix.

Parameters
matrixThe matrix whose part is to be printed
start_indexThe column number to start printing from
void matrix_row_reduce ( Matrix matrix,
int  zero_control 
)

Row echelon reduction a matrix.

Parameters
matrixThe matrix on which to carry out row reduction
zero_controlMaximum amount of zeros that can be found on a row
void matrix_subtract ( Matrix result,
Matrix matrix1,
Matrix matrix2 
)

Subtracts one matrix from another.

Parameters
resultA matrix to hold the result of the subraction
matrix1The matrix to subtract from
matrix2The 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.

Parameters
matrixThe matrix whose row is to be divided
pivotThe pivot postion of the matrix to do the division
void row_operation ( Matrix multiplier_matrix,
Matrix matrix,
int  pivot,
int  row_index 
)

Row operations on the matrix.

Parameters
multiplier_matrixA matrix to store the various multipliers used in row reduction
matrixA matrix on which to carry out the row operations
pivotThe pivot position of the matrix to use
row_indexThe row number on which to carry out row operations
void terminate ( char *  string)

Fucntion to terminate an application in case of an error.

Parameters
stringMessage to displayed to stdout in case of an error