Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions src/linearization.jl
Original file line number Diff line number Diff line change
Expand Up @@ -501,9 +501,9 @@ where `x` are differential unknown variables, `z` algebraic variables, `u` input
"""
function linearize_symbolic(sys::AbstractSystem, inputs,
outputs; simplify = false, allow_input_derivatives = false,
eval_expression = false, eval_module = @__MODULE__,
eval_expression = false, eval_module = @__MODULE__, split = true,
kwargs...)
sys = mtkcompile(sys; inputs, outputs, simplify, kwargs...)
sys = mtkcompile(sys; inputs, outputs, simplify, split, kwargs...)
diff_idxs, alge_idxs = eq_idxs(sys)
sts = unknowns(sys)
t = get_iv(sys)
Expand All @@ -512,10 +512,15 @@ function linearize_symbolic(sys::AbstractSystem, inputs,

fun_expr = generate_rhs(sys; expression = Val{true})[1]
fun = eval_or_rgf(fun_expr; eval_expression, eval_module)
dx = fun(sts, p, t)


Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[JuliaFormatter] reported by reviewdog 🐶

Suggested change

h = build_explicit_observed_function(sys, outputs; eval_expression, eval_module)
y = h(sts, p, t)
if split
dx = fun(sts, p, t)
y = h(sts, p, t)
else
dx = fun(sts, p..., t)
y = h(sts, p..., t)
end

fg_xz = Symbolics.jacobian(dx, sts)
fg_u = Symbolics.jacobian(dx, inputs)
Expand Down
2 changes: 2 additions & 0 deletions test/linearize.jl
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,9 @@ lsys2 = ModelingToolkit.reorder_unknowns(lsys1, unknowns(ssys), desired_order)
@test lsys.D[] == lsys2.D[] == 0

## Symbolic linearization
lsyss_ns, ssys_ns = ModelingToolkit.linearize_symbolic(cl, [f.u], [p.x], split=false)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[JuliaFormatter] reported by reviewdog 🐶

Suggested change
lsyss_ns, ssys_ns = ModelingToolkit.linearize_symbolic(cl, [f.u], [p.x], split=false)
lsyss_ns, ssys_ns = ModelingToolkit.linearize_symbolic(cl, [f.u], [p.x], split = false)

lsyss, ssys = ModelingToolkit.linearize_symbolic(cl, [f.u], [p.x])
@test isequal(lsyss.A, lsyss_ns.A)

lsyss = ModelingToolkit.reorder_unknowns(lsyss, unknowns(ssys), [f.x, p.x])
@test ModelingToolkit.fixpoint_sub(lsyss.A, ModelingToolkit.defaults(cl)) == lsys.A
Expand Down
Loading