Skip to content

Commit a2411f0

Browse files
Fix nlsys Jacobian calculation
1 parent 97d0e30 commit a2411f0

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

src/utils.jl

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,7 @@ toexpr(ex) = MacroTools.postwalk(x -> isa(x, Expression) ? convert(Expr, x) : x,
3535

3636
function partition(f, xs)
3737
idxs = map(f, xs)
38-
not_idxs = eachindex(xs) .∉ (idxs,)
39-
return (xs[idxs], xs[not_idxs])
38+
return (xs[idxs], xs[(!).(idxs)])
4039
end
4140

4241
is_constant(::Constant) = true

test/system_construction.jl

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,9 +119,21 @@ test_vars_extraction(de, DiffEqSystem(eqs))
119119
eqs = [0 ~ σ*(y-x),
120120
0 ~ x*-z)-y,
121121
0 ~ x*y - β*z]
122-
ns = NonlinearSystem(eqs)
122+
ns = NonlinearSystem(eqs, [x,y,z], [σ,ρ,β])
123+
jac = ModelingToolkit.calculate_jacobian(ns)
124+
@testset "nlsys jacobian" begin
125+
@test jac[1,1] == σ * -1
126+
@test jac[1,2] == σ
127+
@test jac[1,3] == 0
128+
@test jac[2,1] == ρ - z
129+
@test jac[2,2] == -1
130+
@test jac[2,3] == x * -1
131+
@test jac[3,1] == y
132+
@test jac[3,2] == x
133+
@test jac[3,3] == -1 * β
134+
end
123135
nlsys_func = ModelingToolkit.generate_nlsys_function(ns)
124-
jac = generate_jacobian(ns)
136+
jac_func = generate_jacobian(ns)
125137
f = @eval eval(nlsys_func)
126138

127139
# Intermediate calculations

0 commit comments

Comments
 (0)