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
|
#ifndef MATRIX_H
#define MATRIX_H
#include <stddef.h>
#define matrix_at(mat, i, j) ((mat)->xs[(i) * (mat)->n + (j)])
#define TRUE 1
#define FALSE 0
typedef enum {
MATRIX_DIAG,
MATRIX_TRIAG_UPPER,
MATRIX_TRIAG_LOWER,
MATRIX_TRIAG_SUPPER, /* S for strict */
MATRIX_TRIAG_SLOWER,
MATRIX_NONE
} MatrixType;
typedef struct {
double *xs;
size_t m;
size_t n;
} Matrix;
Matrix *matrix_alloc(size_t m, size_t n);
void matrix_free(Matrix *mat);
void matrix_freen(Matrix **mats);
void matrix_print(const Matrix *mat);
Matrix *matrix_from_str(char *str);
Matrix *matrix_from_arr(double arr[], size_t m, size_t n);
char *matrix_to_str(const Matrix *mat);
Matrix *matrix_id(size_t n);
Matrix *matrix_const(size_t m, size_t n, double x);
Matrix *matrix_copy (const Matrix *mat);
Matrix *matrix_swap_rows(const Matrix *mat, size_t i, size_t j);
void matrix_swap_rows1(Matrix *mat, size_t i, size_t j);
Matrix *matrix_swap_cols(const Matrix *mat, size_t i, size_t j);
void matrix_swap_cols1(const Matrix *mat, size_t i, size_t j);
double matrix_trace(const Matrix *mat);
Matrix *matrix_transpose(const Matrix *mat);
Matrix *matrix_add(const Matrix *A, const Matrix *B);
Matrix *matrix_scale(double x, const Matrix *A);
Matrix *matrix_sub(const Matrix *A, const Matrix *B);
Matrix *matrix_mult(const Matrix *A, const Matrix *B);
Matrix *matrix_rand(size_t m, size_t n, int bound_l, int bound_u, MatrixType type);
int matrix_is_square(const Matrix *mat);
int matrix_eq(const Matrix *A, const Matrix *B, double tol);
double matrix_norm_frob(const Matrix *mat);
Matrix **matrix_LR(const Matrix *A, const Matrix *b);
Matrix *matrix_forwardel(const Matrix *L, const Matrix *b);
Matrix *matrix_backsubst(const Matrix *R, const Matrix *y);
#endif
|