![](/media/cache/group/Diana_su_nero.jpg.50x50_q85.jpg)
test_IPKF
Dependencies: mbed
header/matrix.h
- Committer:
- LudovicoDani
- Date:
- 2016-04-20
- Revision:
- 0:fb6e494a7656
File content as of revision 0:fb6e494a7656:
/** @brief * @file matrix.h * @author Daniele Ludovico * @date 20/3/2016 * @brief File containing the function to manipulates matrices. * */ #ifndef MATRIX_H_INCLUDED #define MATRIX_H_INCLUDED #ifdef __cplusplus extern "C" { #endif #include <stdio.h> #include <stdlib.h> /** @brief struct matrix * allows to execute matrix computation */ typedef struct s_matrix { int row;/**< number of row of the matrix */ int col;/**< number of column of the matrix */ float** element; /**< this field allows to read and write the elements of the matrix */ }matrix; /********************************************//** * \brief this function allows to allocate a * matrix in memory * * \param matrix pointer to the object to * allocate * * \return 0 if the allocation is done * correctly * \return 1 if there is not enough space in * memory to create a new matrix * ***********************************************/ int CreateMatrix(matrix* m); /********************************************//** * \brief this function allows to delete from * memory a matrix struct * * \param matrix pointer to the object to * delete * \return void * ***********************************************/ void DeleteMatrix(matrix* m); /********************************************//** * \brief this function initialize a matrix * * \param m is the pointer to the matrix to * initialize * \param row is the number of row of the matrix * \param col is the number of column of the matrix * * \return 0 if the allocation is done * correctly * \return 1 if there is not enough space in * memory to create a new matrix * ***********************************************/ int InitMatrix(matrix* m, int row, int col); /********************************************//** * \brief this function allows to compute * the product between 2 matrices * * \param a is the first element of the product * \param b is the second element of the product * \param r is the matrix which will contain * the result * * \return 0 if the product is computed correctly * \return 1 if the number of column of a is different * from the row of b * \return 2 if the number of row of a is different * from number of row of r * \return 3 if the number of column of b is different * from number of column of r * ***********************************************/ int MxM (matrix* a, matrix* b, matrix* r); /********************************************//** * \brief this function allows to compute the * product between a scalar and a matrix * * \param m is the pointer to the matrix * \param a is the scalar number * \param r is the pointer to the result * * \return 0 if the the product is computed * correctly * \return 1 if the number of row of a is different * from number of row of r * \return 2 if the number of col of a is different * from number of col of r * ***********************************************/ int axM (matrix* m, float a, matrix* r); /********************************************//** * \brief this function allows to compute the * sum between two matrices * * \param a is the pointer to the first matrix * \param b is the pointer to the second matrix * \param c is the pointer to the result * * \return 0 if the sum is computed correctly * \return 1 if the number of column of a is different * from the column of b * \return 2 if the number of row of a is different * from number of row of b * \return 3 if the number of row of a is different * from number of row of r * \return 4 if the number of column of a is different * from number of column of r * ***********************************************/ int Sum (matrix* a, matrix* b, matrix* r); /********************************************//** * \brief this function allows to compute the * subtraction between two matrices * * \param a is the pointer to the first matrix * \param b is the pointer to the second matrix * \param c is the pointer to the result * * \return 0 if the subtraction is computed correctly * \return 1 if the number of column of a is different * from the column of b * \return 2 if the number of row of a is different * from number of row of b * \return 3 if the number of row of a is different * from number of row of r * \return 4 if the number of column of a is different * from number of column of r * ***********************************************/ int Sub (matrix* a, matrix* b, matrix* r); /********************************************//** * \brief this function allows to compute the * traspost of a matrix * * \param m is the pointer to the matrix to * be trasposed * \param r is the pointer to the result * * \return 0 if the operation is done correctly * \return 1 if the number of row of m is different * from the column of r * \return 2 if the number of column of m is different * from the row of r * ***********************************************/ int Traspost(matrix* m, matrix* r); /********************************************//** * \brief this function allows to compute the * inverse of a matrix using the Gauss algorithm * * \param m is the pointer to the original matrix * \param inv_m is the pointer to the result * * \return 0 if the inversion is done correctly * \return 1 if m is not a square matrix * \return 2 if the number of row of m is different * from the row of inv_m * \return 3 if the number of column of m is different * from the column of inv_m * \return 4 if m is not invertible * ***********************************************/ int Inv (matrix* m, matrix* inv_m); /********************************************//** * \brief Computes the cross product between two vectors * * \param v is the first vector * \param w is the second vector * \param r is address to the resulting matrix * \return void * ***********************************************/ void CrossProd(matrix* v, matrix* w, matrix* r); /********************************************//** * \brief print the matrix in the prompt * * \param m is the pointer to the matrix to print * * \return void * ***********************************************/ void Print_Matrix(matrix* m); #ifdef __cplusplus } #endif #endif // MATRIX_H_INCLUDED