Skip to content

Commit 11c335a

Browse files
committed
Test linear equation system with vector variable
1 parent 9182a7d commit 11c335a

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

test/nonlinearsystem.jl

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -325,3 +325,17 @@ end
325325
prob = @test_nowarn NonlinearProblem(sys, nothing)
326326
@test_nowarn solve(prob)
327327
end
328+
329+
@testset "System of linear equations with vector variable" begin
330+
# 1st example in https://en.wikipedia.org/w/index.php?title=System_of_linear_equations&oldid=1247697953
331+
@variables x[1:3]
332+
A = [3 2 -1
333+
2 -2 4
334+
-1 1/2 -1]
335+
b = [1, -2, 0]
336+
@named sys = NonlinearSystem(A * x ~ b, [xs], [])
337+
sys = structural_simplify(sys)
338+
prob = NonlinearProblem(sys, unknowns(sys) .=> 0.0)
339+
sol = solve(prob)
340+
@test all(sol[x] .≈ A \ b)
341+
end

test/reduction.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,7 @@ A = reshape(1:(N^2), N, N)
178178
eqs = xs ~ A * xs
179179
@named sys′ = NonlinearSystem(eqs, [xs], [])
180180
sys = structural_simplify(sys′)
181+
@test length(equations(sys)) == 3 && length(observed(sys)) == 2
181182

182183
# issue 958
183184
@parameters k₁ k₂ k₋₁ E₀

0 commit comments

Comments
 (0)