Skip to content

Commit

Permalink
Merge pull request #2317 from SciML/fb/scalarlin
Browse files Browse the repository at this point in the history
allow scalar IO in `linearize`
  • Loading branch information
baggepinnen authored Nov 3, 2023
2 parents a0a95b5 + dd23d21 commit 0f94b02
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/systems/abstractsystem.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1291,6 +1291,8 @@ function linearization_function(sys::AbstractSystem, inputs,
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 @@ -1486,7 +1488,7 @@ end
(; A, B, C, D), simplified_sys = linearize(sys, inputs, outputs; t=0.0, op = Dict(), allow_input_derivatives = false, zero_dummy_der=false, kwargs...)
(; A, B, C, D) = linearize(simplified_sys, lin_fun; t=0.0, op = Dict(), allow_input_derivatives = false, zero_dummy_der=false)
Return a NamedTuple with the matrices of a linear statespace representation
Linearize `sys` between `inputs` and `outputs`, both vectors of variables. Return a NamedTuple with the matrices of a linear statespace representation
on the form
```math
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 0f94b02

Please sign in to comment.