File tree Expand file tree Collapse file tree 1 file changed +29
-0
lines changed Expand file tree Collapse file tree 1 file changed +29
-0
lines changed Original file line number Diff line number Diff line change @@ -283,3 +283,32 @@ sys = structural_simplify(ns)
283
283
@test length (equations (sys)) == 0
284
284
sys = structural_simplify (ns; conservative = true )
285
285
@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
+ 2 x* (- 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
You can’t perform that action at this time.
0 commit comments