From bf8973c4617c30b1474bed2b7e399d6bf7f68839 Mon Sep 17 00:00:00 2001 From: Jasper Date: Mon, 8 Sep 2025 10:05:32 +0200 Subject: More functions with '1' suffix Added more versions of existing functions with suffix '1' that take a matrix as argument and perform the action (e.g. filling a matrix with random entries) to the passed matrix. 'matrix_add' and 'matrix_scale' save the result in the matrix passed first. --- matrix.h | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'matrix.h') diff --git a/matrix.h b/matrix.h index c3138e2..75e605e 100644 --- a/matrix.h +++ b/matrix.h @@ -19,9 +19,6 @@ #define matrix_is_square(mat) ((mat)->m == (mat)->n) -#define TRUE 1 -#define FALSE 0 - typedef enum { MATRIX_DIAG, MATRIX_TRIAG_UPPER, @@ -51,17 +48,23 @@ 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); +void matrix_const1(Matrix *mat, double x); Matrix *matrix_copy (const Matrix *mat); +void matrix_copy1(Matrix *A, const Matrix *B); Matrix *matrix_swap(const Matrix *mat, MatrixSwapType t, size_t i, size_t j); void matrix_swap1(Matrix *mat, MatrixSwapType t, 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); +void matrix_add1(Matrix *A, const Matrix *B); Matrix *matrix_scale(const Matrix *A, double x); +void matrix_scale1(Matrix *A, double x); Matrix *matrix_sub(const Matrix *A, const Matrix *B); +void matrix_sub1(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_eq(const Matrix *A, const Matrix *B, double tol); +void matrix_rand1(Matrix *mat, int bound_l, int bound_u, MatrixType type); +bool 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); -- cgit v1.2.3