matrix.h 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. /****************************************************************
  2. *
  3. * MODULE: v.generalize
  4. *
  5. * AUTHOR(S): Daniel Bundala
  6. *
  7. * PURPOSE: definition of a matrix and basic operations with
  8. * with matrices
  9. *
  10. * COPYRIGHT: (C) 2002-2005 by the GRASS Development Team
  11. *
  12. * This program is free software under the
  13. * GNU General Public License (>=v2).
  14. * Read the file COPYING that comes with GRASS
  15. * for details.
  16. *
  17. ****************************************************************/
  18. #ifndef MATRIX_H
  19. #define MATRIX_H
  20. #include <grass/vector.h>
  21. typedef struct
  22. {
  23. int rows, cols;
  24. double **a;
  25. } MATRIX;
  26. /* return 1 on success, 0 on error (out of memory) */
  27. extern int matrix_init(int rows, int cols, MATRIX *res);
  28. /* free the memory occupied by the values of m */
  29. extern void matrix_free(MATRIX *m);
  30. /* multiply two matrices, Return 1 on success, 0 on failure.
  31. * return value 0 means - bad dimensions */
  32. extern int matrix_mult(MATRIX *a, MATRIX *b, MATRIX *res);
  33. /* adds a multiple of the identity matrix to the given matrix
  34. * M = M + s * Id. Returns 1 on success, 0 otherwise */
  35. extern int matrix_add_identity(double s, MATRIX *m);
  36. /* calculate the inverse of given (square) matrix. Returns 0 if
  37. * the matrix is not invertible or if an error occurs.
  38. * percents indicates whether we want to show the progress of
  39. * computation
  40. * Otherwise it returns 1 */
  41. extern int matrix_inverse(MATRIX *a, MATRIX *res, int percents);
  42. /* multiplies matrix by a scalar */
  43. extern void matrix_mult_scalar(double s, MATRIX *m);
  44. /* res = a + b. Does not cheack the dimensions */
  45. extern void matrix_add(MATRIX *a, MATRIX *b, MATRIX *res);
  46. /* debug function */
  47. extern void matrix_print(MATRIX *a);
  48. #endif