1
0
mirror of https://github.com/nophead/NopSCADlib.git synced 2025-08-23 23:52:50 +02:00

Removed utility functions used by invert() from documentation as not generally useful.

This commit is contained in:
Chris Palmer
2023-03-29 13:21:26 +01:00
parent d3f0bfc17f
commit 1c5d9a8ef5
2 changed files with 4 additions and 8 deletions

View File

@@ -118,24 +118,24 @@ module position_children(list, t) //! Position children if they are on the Z = 0
// Matrix inversion: https://www.mathsisfun.com/algebra/matrix-inverse-row-operations-gauss-jordan.html
function augment(m) = let(l = len(m), n = identity(l)) [ //! Augment a matrix by adding an identity matrix to the right
function augment(m) = let(l = len(m), n = identity(l)) [ // Augment a matrix by adding an identity matrix to the right
for(i = [0 : l - 1])
concat(m[i], n[i])
];
function rowswap(m, i, j) = [ //! Swap two rows of a matrix
function rowswap(m, i, j) = [ // Swap two rows of a matrix
for(k = [0 : len(m) - 1])
k == i ? m[j] : k == j ? m[i] : m[k]
];
function solve_row(m, i) = let(diag = m[i][i]) [ //! Make diagonal one by dividing the row by it and subtract from other rows to make column zero
function solve_row(m, i) = let(diag = m[i][i]) [ // Make diagonal one by dividing the row by it and subtract from other rows to make column zero
for(j = [0 : len(m) - 1])
i == j ? m[j] / diag : m[j] - m[i] * m[j][i] / diag
];
function nearly_zero(x) = abs(x) < 1e-5; //! True if x is close to zero
function solve(m, i = 0, j = 0) = //! Solve each row ensuring diagonal is not zero
function solve(m, i = 0, j = 0) = // Solve each row ensuring diagonal is not zero
i < len(m) ?
assert(i + j < len(m), "matrix is singular")
solve(!nearly_zero(m[i + j][i]) ? solve_row(j ? rowswap(m, i, i + j) : m, i) : solve(m, i, j + 1), i + 1)