Skip to content

Commit 890d859

Browse files
committed
Added test
1 parent f736a78 commit 890d859

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

test/nonlinearsystem.jl

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,3 +283,32 @@ sys = structural_simplify(ns)
283283
@test length(equations(sys)) == 0
284284
sys = structural_simplify(ns; conservative = true)
285285
@test length(equations(sys)) == 1
286+
287+
# https://github.com/SciML/ModelingToolkit.jl/issues/2858
288+
@testset "Jacobian with observed equations that depend on unknowns" begin
289+
@variables x y z
290+
@parameters σ ρ β
291+
eqs = [
292+
0 ~ σ * (y - x)
293+
0 ~ x *- z) - y
294+
0 ~ x * y - β * z
295+
]
296+
guesses = [x => 1.0, y => 0.0, z => 0.0]
297+
ps ==> 10.0, ρ => 26.0, β => 8 / 3]
298+
@mtkbuild ns = NonlinearSystem(eqs)
299+
300+
@test isequal(calculate_jacobian(ns), [
301+
(-1-z+ρ)*σ -x*σ
302+
2x*(-z+ρ) -β-(x^2)
303+
])
304+
305+
# solve without analytical jacobian
306+
prob = NonlinearProblem(ns, guesses, ps)
307+
sol = solve(prob, NewtonRaphson())
308+
@test sol.retcode == ReturnCode.Success
309+
310+
# solve with analytical jacobian
311+
prob = NonlinearProblem(ns, guesses, ps, jac = true)
312+
sol = solve(prob, NewtonRaphson())
313+
@test sol.retcode == ReturnCode.Success
314+
end

0 commit comments

Comments
 (0)