forked from SciML/ModelingToolkit.jl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlinalg.jl
30 lines (28 loc) · 792 Bytes
/
linalg.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
using ModelingToolkit
using LinearAlgebra
using Test
A = [0 1 1 2 2 1 1 2 1 2
0 1 -1 -3 -2 2 1 -5 0 -5
0 1 2 2 1 1 2 1 1 2
0 1 1 1 2 1 1 2 2 1
0 2 1 2 2 2 2 1 1 1
0 1 1 1 2 2 1 1 2 1
0 2 1 2 2 1 2 1 1 2
0 1 7 17 14 2 1 19 4 23
0 1 -1 -3 -2 1 1 -4 0 -5
0 1 1 2 2 1 1 2 2 2]
N = ModelingToolkit.nullspace(A)
@test size(N, 2) == 3
@test rank(N) == 3
@test iszero(A * N)
A = [0 1 2 0 1 0;
0 0 0 0 0 1;
0 0 0 0 0 1;
1 0 1 2 0 1;
0 0 0 2 1 0]
col_order = Int[]
N = ModelingToolkit.nullspace(A; col_order)
colspan = A[:, col_order[1:4]] # rank is 4
@test iszero(ModelingToolkit.nullspace(colspan))
@test !iszero(ModelingToolkit.nullspace(A[:, col_order[1:5]]))
@test !iszero(ModelingToolkit.nullspace(A[:, [col_order[1:4]..., col_order[6]]]))