@@ -591,4 +591,45 @@ eqs[end] = D(D(z)) ~ α*x - β*y
591
591
sol = solve (prob, Euler (); dt= 0.1 )
592
592
593
593
@test c[1 ] == length (sol)
594
- end
594
+ end
595
+
596
+ let
597
+ @parameters t
598
+ D = Differential (t)
599
+ @variables x[1 : 2 ](t) = zeros (2 )
600
+ @variables y (t) = 0
601
+ @parameters k = 1
602
+ eqs= [
603
+ D (x[1 ]) ~ x[2 ]
604
+ D (x[2 ]) ~ - x[1 ] - 0.5 * x[2 ] + k
605
+ y ~ 0.9 * x[1 ] + x[2 ]
606
+ ]
607
+ @named sys = ODESystem (eqs, t, vcat (x, [y]), [k])
608
+ sys = structural_simplify (sys)
609
+
610
+ u0 = [0.5 , 0 ]
611
+ du0 = 0 .* copy (u0)
612
+ prob = DAEProblem (sys, du0, u0, (0 , 50 ))
613
+ @test prob. u0 ≈ u0
614
+ @test prob. du0 ≈ du0
615
+ @test prob. p ≈ [1 ]
616
+ sol = solve (prob, IDA ())
617
+ @test isapprox (sol[x[1 ]][end ], 1 , atol= 1e-3 )
618
+
619
+ prob = DAEProblem (sys, [D (y) => 0 , D (x[1 ]) => 0 , D (x[2 ]) => 0 ], Pair[x[1 ] => 0.5 ], (0 , 50 ))
620
+ @test prob. u0 ≈ [0.5 , 0 ]
621
+ @test prob. du0 ≈ [0 , 0 ]
622
+ @test prob. p ≈ [1 ]
623
+ sol = solve (prob, IDA ())
624
+ @test isapprox (sol[x[1 ]][end ], 1 , atol= 1e-3 )
625
+
626
+ prob = DAEProblem (sys, [D (y) => 0 , D (x[1 ]) => 0 , D (x[2 ]) => 0 ], Pair[x[1 ] => 0.5 ], (0 , 50 ), [k => 2 ])
627
+ @test prob. u0 ≈ [0.5 , 0 ]
628
+ @test prob. du0 ≈ [0 , 0 ]
629
+ @test prob. p ≈ [2 ]
630
+ sol = solve (prob, IDA ())
631
+ @test isapprox (sol[x[1 ]][end ], 2 , atol= 1e-3 )
632
+
633
+ # no initial conditions for D(x[1]) and D(x[2]) provided
634
+ @test_throws ArgumentError prob = DAEProblem (sys, Pair[], Pair[], (0 , 50 ))
635
+ end
0 commit comments