Skip to content

Commit d2cbf05

Browse files
committed
Add iszero check in linear equation detection
1 parent 805811b commit d2cbf05

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

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)