-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmatrixalgebra.h
More file actions
64 lines (54 loc) · 2.27 KB
/
matrixalgebra.h
File metadata and controls
64 lines (54 loc) · 2.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#define M_TYPE float // Matrix entry type
#define S_TYPE double // Scalar type
/* Uniqueness of Solutions */
#define UOS_ZERO 0
#define UOS_ONE 1
#define UOS_INF 2
/* Compare two matrice values */
#define ENTRY_COMPARE(x, y) ((x) == (y) ? 1 : 0) // Requires epsilon approximation fix
/* http://www.robertgamble.net/2012/01/c11-generic-selections.html */
#if __STDC_VERSION__ >= 201112L
#define printf_dec_format(x) _Generic((x), \
char: "%c", \
signed char: "%hhd", \
unsigned char: "%hhu", \
signed short: "%hd", \
unsigned short: "%hu", \
signed int: "%d", \
unsigned int: "%u", \
long int: "%ld", \
unsigned long int: "%lu", \
long long int: "%lld", \
unsigned long long int: "%llu", \
float: "%f", \
double: "%f", \
long double: "%Lf", \
char *: "%s", \
void *: "%p")
#define printNumber(x) printf(printf_dec_format(x), x);
#endif
typedef struct matrix {
size_t row, col; // Row, Column
M_TYPE *array; // Pointer to preallocated array filled with values
} Matrix;
Matrix* matrix_create (M_TYPE* matrixArray, size_t rows, size_t columns);
Matrix* matrix_create_diagonal (M_TYPE diagonalValue, size_t dimSize);
void matrix_free (Matrix* matrix);
void matrix_print (Matrix* matrix);
void eroScale (Matrix* matrix, size_t rowIndex, S_TYPE scalar);
void eroSwap (Matrix* matrix, size_t rowIndex1, size_t rowIndex2);
void eroSum (Matrix* matrix, size_t rowIndex1, size_t rowIndex2, S_TYPE scalar);
void rowEchelonForm (Matrix* matrix, int reducedRowEchelonForm);
void matrix_ref (Matrix* matrix);
void matrix_rref (Matrix* matrix);
int matrix_uniquenessOfSolutions(Matrix* matrix);
int matrix_isEqualDimensions (Matrix* matrix1, Matrix* matrix2);
int matrix_isZero (Matrix* matrix);
Matrix* matrix_add (Matrix* matrix1, Matrix* matrix2);
Matrix* matrix_scale (Matrix* matrix, S_TYPE scalar);
Matrix* matrix_compose (Matrix* matrix1, Matrix* matrix2);
Matrix* matrix_augment (Matrix* matrix1, Matrix* matrix2);
Matrix* matrix_solve (Matrix* matrixA, Matrix* matrixB);
Matrix* matrix_transpose (Matrix* matrix);
M_TYPE matrix_trace (Matrix* matrix);
M_TYPE matrix_determinant (Matrix* matrix);