summaryrefslogtreecommitdiff
path: root/matrix.h
blob: 3257fbc88cad6aad5ffa0414acac7e48f420e24e (plain)
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
#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(const size_t m, const 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(const size_t n);
Matrix *matrix_const(const size_t m, const size_t n, const double x);
Matrix *matrix_copy (const Matrix *mat);
double matrix_trace(const Matrix *mat);
Matrix *matrix_transpose(const Matrix *mat);
Matrix *matrix_add(const Matrix *A, const Matrix *B);
Matrix *matrix_scale(const 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(const size_t m, const size_t n, const int bound_l, const int bound_u, MatrixType type);
int matrix_is_square(const Matrix *mat);
int matrix_eq(const Matrix *A, const Matrix *B, const 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