Skip to content

Commit c5dc992

Browse files
authored
Merge pull request #886 from SciML/myb/lineq
Add `iszero` check in linear equation detection
2 parents fefe559 + 6821ff2 commit c5dc992

File tree

3 files changed

+9
-2
lines changed

3 files changed

+9
-2
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "ModelingToolkit"
22
uuid = "961ee093-0014-501f-94e3-6117800e7a78"
33
authors = ["Chris Rackauckas <[email protected]>"]
4-
version = "5.13.1"
4+
version = "5.13.2"
55

66
[deps]
77
ArrayInterface = "4fba245c-0d91-5ea0-9b3e-6abc04ee57a9"

src/systems/systemstructure.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ function find_linear_equations(sys)
194194
c = expand_derivatives(Differential(var)(term), false)
195195
# test if `var` is linear in `eq`.
196196
if !(c isa Symbolic) && c isa Number
197-
if isinteger(c)
197+
if isinteger(c) && !iszero(c)
198198
c = convert(Integer, c)
199199
linear_term += c * var
200200
push!(coeffs, c)

test/reduction.jl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,3 +191,10 @@ reducedsol = solve(nlprob, NewtonRaphson())
191191
residual = fill(100.0, length(states(reducedsys)))
192192
nlprob.f(residual, reducedsol.u, pp)
193193
@test all(x->abs(x) < 1e-5, residual)
194+
195+
N = 5
196+
@variables xs[1:N]
197+
A = reshape(1:N^2, N, N)
198+
eqs = xs .~ A * xs
199+
sys′ = NonlinearSystem(eqs, xs, [])
200+
sys = structural_simplify(sys′)

0 commit comments

Comments
 (0)