From 09fda2ff33c616b76ab369bd2eae171feb10e94e Mon Sep 17 00:00:00 2001 From: Herman Sletmoen Date: Thu, 3 Oct 2024 20:56:44 +0200 Subject: [PATCH] Test linear equation system with vector variable --- test/nonlinearsystem.jl | 14 ++++++++++++++ test/reduction.jl | 1 + 2 files changed, 15 insertions(+) diff --git a/test/nonlinearsystem.jl b/test/nonlinearsystem.jl index a71d34a880..c42eb6f87b 100644 --- a/test/nonlinearsystem.jl +++ b/test/nonlinearsystem.jl @@ -325,3 +325,17 @@ end prob = @test_nowarn NonlinearProblem(sys, nothing) @test_nowarn solve(prob) end + +@testset "System of linear equations with vector variable" begin + # 1st example in https://en.wikipedia.org/w/index.php?title=System_of_linear_equations&oldid=1247697953 + @variables x[1:3] + A = [3 2 -1 + 2 -2 4 + -1 1/2 -1] + b = [1, -2, 0] + @named sys = NonlinearSystem(A * x ~ b, [x], []) + sys = structural_simplify(sys) + prob = NonlinearProblem(sys, unknowns(sys) .=> 0.0) + sol = solve(prob) + @test all(sol[x] .≈ A \ b) +end diff --git a/test/reduction.jl b/test/reduction.jl index 064a2efd81..80969d5794 100644 --- a/test/reduction.jl +++ b/test/reduction.jl @@ -178,6 +178,7 @@ A = reshape(1:(N^2), N, N) eqs = xs ~ A * xs @named sys′ = NonlinearSystem(eqs, [xs], []) sys = structural_simplify(sys′) +@test length(equations(sys)) == 3 && length(observed(sys)) == 2 # issue 958 @parameters k₁ k₂ k₋₁ E₀