Skip to content

Commit f736a78

Browse files
committed
Substitute in observed before calculating jacobian
1 parent f5378df commit f736a78

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

src/systems/nonlinear/nonlinearsystem.jl

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,8 +193,11 @@ function calculate_jacobian(sys::NonlinearSystem; sparse = false, simplify = fal
193193
return cache[1]
194194
end
195195

196-
rhs = [eq.rhs for eq in equations(sys)]
196+
# observed equations may depend on unknowns, so substitute them in first
197+
obs = map(eq -> eq.lhs => eq.rhs, observed(sys))
198+
rhs = map(eq -> substitute(eq.rhs, obs), equations(sys))
197199
vals = [dv for dv in unknowns(sys)]
200+
198201
if sparse
199202
jac = sparsejacobian(rhs, vals, simplify = simplify)
200203
else

0 commit comments

Comments
 (0)