mirror of
https://github.com/BelfrySCAD/BOSL2.git
synced 2025-01-01 09:49:45 +00:00
explore new scope of transpose in linear_solve and _qr_factor
This commit is contained in:
parent
0dc8bf6c8f
commit
2e9d87f584
1 changed files with 12 additions and 13 deletions
19
math.scad
19
math.scad
|
@ -698,9 +698,8 @@ function linear_solve(A,b) =
|
|||
zeros != [] ? [] :
|
||||
m<n
|
||||
// avoiding input validation in back_substitute
|
||||
? let( n = len(R),
|
||||
Rt = [for(i=[0:n-1]) [for(j=[0:n-1]) R[n-1-j][n-1-i]]] )
|
||||
Q*reverse(_back_substitute(Rt,reverse(b)))
|
||||
? let( n = len(R) )
|
||||
Q*reverse(_back_substitute(transpose(R, reverse=true), reverse(b)))
|
||||
: _back_substitute(R, transpose(Q)*b);
|
||||
|
||||
// Function: matrix_inverse()
|
||||
|
@ -728,11 +727,12 @@ function qr_factor(A) =
|
|||
n = len(A[0])
|
||||
)
|
||||
let(
|
||||
qr =_qr_factor(A, column=0, m = m, n=n, Q=ident(m)),
|
||||
Rzero = [
|
||||
for(i=[0:m-1]) [
|
||||
for(j=[0:n-1])
|
||||
i>j ? 0 : qr[1][i][j]
|
||||
qr =_qr_factor(A, Q=ident(m), column=0, m = m, n=n),
|
||||
Rzero =
|
||||
let( R = qr[1] )
|
||||
[ for(i=[0:m-1]) [
|
||||
let( ri = R[i] )
|
||||
for(j=[0:n-1]) i>j ? 0 : ri[j]
|
||||
]
|
||||
]
|
||||
) [qr[0],Rzero];
|
||||
|
@ -763,8 +763,7 @@ function back_substitute(R, b, transpose = false) =
|
|||
let(n=len(R))
|
||||
assert(is_vector(b,n) || is_matrix(b,n),str("R and b are not compatible in back_substitute ",n, len(b)))
|
||||
transpose
|
||||
? reverse(_back_substitute([for(i=[0:n-1]) [for(j=[0:n-1]) R[n-1-j][n-1-i]]],
|
||||
reverse(b)))
|
||||
? reverse(_back_substitute(transpose(R, reverse=true), reverse(b)))
|
||||
: _back_substitute(R,b);
|
||||
|
||||
function _back_substitute(R, b, x=[]) =
|
||||
|
|
Loading…
Reference in a new issue