Skip to content

Commit b27da2e

Browse files
committed
add docstring
1 parent 233a743 commit b27da2e

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

src/systems/abstractsystem.jl

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1287,6 +1287,13 @@ function linearization_function(sys::AbstractSystem, inputs,
12871287
return lin_fun, sys
12881288
end
12891289

1290+
"""
1291+
(; A, B, C, D), simplified_sys = linearize_symbolic(sys::AbstractSystem, inputs, outputs; simplify = false, kwargs)
1292+
1293+
Similar to [`linearize`](@ref), but returns symbolic matrices `A,B,C,D` rather than numeric. While `linearize` uses ForwardDiff to perform the linearization, this function uses `Symbolics.jacobian`.
1294+
1295+
See [`linearize`](@ref) for a description of the arguments.
1296+
"""
12901297
function linearize_symbolic(sys::AbstractSystem, inputs,
12911298
outputs; simplify = false,
12921299
kwargs...)
@@ -1365,7 +1372,7 @@ the default values of `sys` are used.
13651372
13661373
If `allow_input_derivatives = false`, an error will be thrown if input derivatives (``u̇``) appear as inputs in the linearized equations. If input derivatives are allowed, the returned `B` matrix will be of double width, corresponding to the input `[u; u̇]`.
13671374
1368-
See also [`linearization_function`](@ref) which provides a lower-level interface, and [`ModelingToolkit.reorder_states`](@ref).
1375+
See also [`linearization_function`](@ref) which provides a lower-level interface, [`linearize_symbolic`](@ref) and [`ModelingToolkit.reorder_states`](@ref).
13691376
13701377
See extended help for an example.
13711378
@@ -1427,14 +1434,19 @@ connections = [f.y ~ c.r # filtered reference to controller reference
14271434
14281435
@named cl = ODESystem(connections, t, systems = [f, c, p])
14291436
1430-
lsys, ssys = linearize(cl, [f.u], [p.x])
1437+
lsys0, ssys = linearize(cl, [f.u], [p.x])
14311438
desired_order = [f.x, p.x]
1432-
lsys = ModelingToolkit.reorder_states(lsys, states(ssys), desired_order)
1439+
lsys = ModelingToolkit.reorder_states(lsys0, states(ssys), desired_order)
14331440
14341441
@assert lsys.A == [-2 0; 1 -2]
14351442
@assert lsys.B == [1; 0;;]
14361443
@assert lsys.C == [0 1]
14371444
@assert lsys.D[] == 0
1445+
1446+
## Symbolic linearization
1447+
lsys_sym, _ = ModelingToolkit.linearize_symbolic(cl, [f.u], [p.x])
1448+
1449+
@assert substitute(lsys_sym.A, ModelingToolkit.defaults(cl)) == lsys.A
14381450
```
14391451
"""
14401452
function linearize(sys, lin_fun; t = 0.0, op = Dict(), allow_input_derivatives = false,

0 commit comments

Comments
 (0)