Skip to content

Commit

Permalink
allow scalar IO in linearize
Browse files Browse the repository at this point in the history
  • Loading branch information
baggepinnen committed Nov 3, 2023
1 parent a0a95b5 commit 527a96b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
16 changes: 9 additions & 7 deletions src/systems/abstractsystem.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1285,12 +1285,14 @@ The `simplified_sys` has undergone [`structural_simplify`](@ref) and had any occ
See also [`linearize`](@ref) which provides a higher-level interface.
"""
function linearization_function(sys::AbstractSystem, inputs,
outputs; simplify = false,
initialize = true,
op = Dict(),
p = DiffEqBase.NullParameters(),
zero_dummy_der = false,
kwargs...)
outputs; simplify = false,
initialize = true,
op = Dict(),
p = DiffEqBase.NullParameters(),
zero_dummy_der = false,
kwargs...)
inputs isa AbstractVector || (inputs = [inputs])
outputs isa AbstractVector || (outputs = [outputs])
ssys, diff_idxs, alge_idxs, input_idxs = io_preprocessing(sys, inputs, outputs;
simplify,
kwargs...)
Expand Down Expand Up @@ -1584,7 +1586,7 @@ lsys_sym, _ = ModelingToolkit.linearize_symbolic(cl, [f.u], [p.x])
```
"""
function linearize(sys, lin_fun; t = 0.0, op = Dict(), allow_input_derivatives = false,
p = DiffEqBase.NullParameters())
p = DiffEqBase.NullParameters(), kwargs...)
x0 = merge(defaults(sys), op)
u0, p2, _ = get_u0_p(sys, x0, p; use_union = false, tofloat = true)

Expand Down
7 changes: 7 additions & 0 deletions test/linearize.jl
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,13 @@ lsys, ssys = linearize(sys, [r], [r])
@test lsys.C[] == 0
@test lsys.D[] == 1

lsys, ssys = linearize(sys, r, r) # Test allow scalars

@test lsys.A[] == -2
@test lsys.B[] == 1
@test lsys.C[] == 0
@test lsys.D[] == 1

##
```
Expand Down

0 comments on commit 527a96b

Please sign in to comment.