mirror of
https://github.com/revarbat/BOSL2.git
synced 2025-08-21 13:31:39 +02:00
Added null_space and diagonal_matrix
This commit is contained in:
@@ -481,6 +481,14 @@ module test_block_matrix() {
|
||||
test_block_matrix();
|
||||
|
||||
|
||||
module test_diagonal_matrix() {
|
||||
assert_equal(diagonal_matrix([1,2,3]), [[1,0,0],[0,2,0],[0,0,3]]);
|
||||
assert_equal(diagonal_matrix([1,"c",2]), [[1,0,0],[0,"c",0],[0,0,2]]);
|
||||
assert_equal(diagonal_matrix([1,"c",2],"X"), [[1,"X","X"],["X","c","X"],["X","X",2]]);
|
||||
assert_equal(diagonal_matrix([[1,1],[2,2],[3,3]], [0,0]), [[ [1,1],[0,0],[0,0]], [[0,0],[2,2],[0,0]], [[0,0],[0,0],[3,3]]]);
|
||||
}
|
||||
test_diagonal_matrix();
|
||||
|
||||
module test_submatrix_set() {
|
||||
test = [[1,2,3,4,5],[6,7,8,9,10],[11,12,13,14,15], [16,17,18,19,20]];
|
||||
ragged = [[1,2,3,4,5],[6,7,8,9,10],[11,12], [16,17]];
|
||||
|
@@ -969,6 +969,29 @@ module test_quadratic_roots(){
|
||||
}
|
||||
test_quadratic_roots();
|
||||
|
||||
|
||||
module test_null_space(){
|
||||
assert_equal(null_space([[3,2,1],[3,6,3],[3,9,-3]]),[]);
|
||||
|
||||
function nullcheck(A,dim) =
|
||||
let(v=null_space(A))
|
||||
len(v)==dim && is_zero(A*transpose(v),eps=1e-12);
|
||||
|
||||
A = [[-1, 2, -5, 2],[-3,-1,3,-3],[5,0,5,0],[3,-4,11,-4]];
|
||||
assert(nullcheck(A,1));
|
||||
|
||||
B = [
|
||||
[ 4, 1, 8, 6, -2, 3],
|
||||
[ 10, 5, 10, 10, 0, 5],
|
||||
[ 8, 1, 8, 8, -6, 1],
|
||||
[ -8, -8, 6, -1, -8, -1],
|
||||
[ 2, 2, 0, 1, 2, 1],
|
||||
[ 2, -3, 10, 6, -8, 1],
|
||||
];
|
||||
assert(nullcheck(B,3));
|
||||
}
|
||||
test_null_space();
|
||||
|
||||
module test_qr_factor() {
|
||||
// Check that R is upper triangular
|
||||
function is_ut(R) =
|
||||
|
Reference in New Issue
Block a user