diff options
| author | Soikk | 2021-10-25 00:52:13 +0200 |
|---|---|---|
| committer | Soikk | 2021-10-25 00:52:13 +0200 |
| commit | 7603bfcadc6168addbb7a876e3e3f87c45c0a81f (patch) | |
| tree | 7bd013e52c72c0a1deaea00a24ae6b3e0c1da46e /matrix-operations.c | |
| parent | d1ab35eb7f6cdd400ccc3626d2c010430ec8d126 (diff) | |
| download | soikk-matrix-calculator-7603bfcadc6168addbb7a876e3e3f87c45c0a81f.tar.xz soikk-matrix-calculator-7603bfcadc6168addbb7a876e3e3f87c45c0a81f.tar.zst | |
You can now raise a matrix to a negative power and store the resulting matrixes from an operation with a scalar in another matrix
Diffstat (limited to 'matrix-operations.c')
| -rw-r--r-- | matrix-operations.c | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/matrix-operations.c b/matrix-operations.c index ae253f7..18c29c1 100644 --- a/matrix-operations.c +++ b/matrix-operations.c @@ -21,6 +21,7 @@ matrix_t matrixError(error_t error){ } return createMatrix(0, 0); } + // Creates a rows x columns matrix; matrix_t createMatrix(size_t rows, size_t columns){ matrix_t newmatrix; @@ -155,8 +156,11 @@ matrix_t divideMatrices(matrix_t a, matrix_t b){ matrix_t raiseMatrixToN(matrix_t m, int n){ if(!isSquare(m)) return matrixError(NOT_SQUARE); - // TODO: only accepts positive values of n matrix_t raisedmatrix = identityMatrix(m.rows); + if(n < 0){ + m = inverse(m); + n = -n; + } for(int i = 0; i < n; ++i) raisedmatrix = multiplyMatrices(raisedmatrix, m); return raisedmatrix; @@ -164,6 +168,7 @@ matrix_t raiseMatrixToN(matrix_t m, int n){ // Creates a submatrix from "matrix" without the column "column" and row "row" of "matrix" matrix_t createSubmatrix(matrix_t m, size_t row, size_t column){ + // TODO: not remove any int mod = m.rows, nmod = mod-1, sr = 0, sc = 0; matrix_t submatrix = createMatrix(nmod, nmod); for(size_t r = 0; r < mod; ++r){ @@ -239,5 +244,5 @@ matrix_t inverse(matrix_t m){ int det = determinant(m); if(det == 0) return matrixError(ZERO_DET); - return multiplyByN(adjugate(m), (float)1/det); + return divideByN(adjugate(m), det); }
\ No newline at end of file |
