You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
`lin_fun` is a function `(u,p,t) -> (; f_x, f_z, g_x, g_z, f_u, g_u, h_x, h_z, h_u)`, i.e., it returns a NamedTuple with the Jacobians of `f,g,h` for the nonlinear `sys` on the form
976
+
```math
977
+
ẋ = f(x, z, u)
978
+
0 = g(x, z, u)
979
+
y = h(x, z, u)
980
+
```
981
+
where `x` are differential states, `z` algebraic states, `u` inputs and `y` outputs. To obtain a linear statespace representation, see [`linearize`](@ref).
982
+
983
+
The `simplified_sys` has undergone [`structural_simplify`](@ref) and had any occurring input or output variables replaced with the variables provided in arguments `inputs` and `outputs`. The states of this system also indicates the order of the states that holds for the linearized matrices.
984
+
985
+
# Arguments:
986
+
- `sys`: An [`ODESystem`](@ref). This function will automatically apply simplification passes on `sys` and return the resulting `simplified_sys`.
987
+
- `inputs`: A vector of variables that indicate the inputs of the linearized input-output model.
988
+
- `outputs`: A vector of variables that indicate the outputs of the linearized input-output model.
989
+
- `simplify`: Apply simplification in tearing.
990
+
- `kwargs`: Are passed on to `find_solvables!`
991
+
992
+
See also [`linearize`](@ref) which provides a higher-level interface.
@@ -1047,6 +1071,143 @@ function markio!(state, inputs, outputs)
1047
1071
state
1048
1072
end
1049
1073
1074
+
"""
1075
+
(; A, B, C, D), simplified_sys = linearize(sys, inputs, outputs; op = Dict(), allow_input_derivatives = false, kwargs...)
1076
+
(; A, B, C, D) = linearize(simplified_sys, lin_fun; op = Dict(), allow_input_derivatives = false)
1077
+
1078
+
Return a NamedTuple with the matrices of a linear statespace representation
1079
+
on the form
1080
+
```math
1081
+
\\begin{aligned}
1082
+
ẋ &= Ax + Bu\\\\
1083
+
y &= Cx + Du
1084
+
\\end{aligned}
1085
+
```
1086
+
1087
+
The first signature automatically calls [`linearization_function`](@ref) internally,
1088
+
while the second signature expects the outputs of [`linearization_function`](@ref) as input.
1089
+
1090
+
`op` denotes the operating point around which to linearize. If none is provided,
1091
+
the default values of `sys` are used.
1092
+
1093
+
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̇]`.
1094
+
1095
+
See also [`linearization_function`](@ref) which provides a lower-level interface, and [`ModelingToolkit.reorder_states`](@ref).
1096
+
1097
+
See extended help for an example.
1098
+
1099
+
# Extended help
1100
+
This example builds the following feedback interconnection and linearizes it from the input of `F` to the output of `P`.
error("g_z not invertible, this indicates that the DAE is of index > 1.")
1182
+
gzgx =-(gz \ g_x)
1183
+
A = [f_x f_z
1184
+
gzgx*f_x gzgx*f_z]
1185
+
B = [f_u
1186
+
zeros(nz, nu)]
1187
+
C = [
1188
+
h_x h_z
1189
+
]
1190
+
Bs =-(gz \ (f_x * f_u + g_u))
1191
+
if!iszero(Bs)
1192
+
if!allow_input_derivatives
1193
+
der_inds =findall(vec(any(!=(0), Bs, dims =1)))
1194
+
error("Input derivatives appeared in expressions (-g_z\\(f_x*f_u + g_u) != 0), the following inputs appeared differentiated: $(inputs(sys)[der_inds]). Call `linear_staespace` with keyword argument `allow_input_derivatives = true` to allow this and have the returned `B` matrix be of double width ($(2nu)), where the last $nu inputs are the derivatives of the first $nu inputs.")
1195
+
end
1196
+
B = [B Bs]
1197
+
end
1198
+
end
1199
+
1200
+
D = h_u
1201
+
1202
+
(; A, B, C, D)
1203
+
end
1204
+
1205
+
functionlinearize(sys, inputs, outputs; op =Dict(), allow_input_derivatives =false,
0 commit comments