Skip to content

Commit f229fe1

Browse files
committed
fix matrix sizes in linearize
when there are input derivatives present.
1 parent 8ae69d2 commit f229fe1

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

src/systems/abstractsystem.jl

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1198,6 +1198,8 @@ function linearize(sys, lin_fun; t = 0.0, op = Dict(), allow_input_derivatives =
11981198
nz = size(f_z, 2)
11991199
ny = size(h_x, 1)
12001200

1201+
D = h_u
1202+
12011203
if isempty(g_z)
12021204
A = f_x
12031205
B = f_u
@@ -1213,20 +1215,20 @@ function linearize(sys, lin_fun; t = 0.0, op = Dict(), allow_input_derivatives =
12131215
A = [f_x f_z
12141216
gzgx*f_x gzgx*f_z]
12151217
B = [f_u
1216-
zeros(nz, nu)]
1218+
gzgx*f_u]
1219+
12171220
C = [h_x h_z]
12181221
Bs = -(gz \ g_u) # This equation differ from the cited paper, the paper is likely wrong since their equaiton leads to a dimension mismatch.
12191222
if !iszero(Bs)
12201223
if !allow_input_derivatives
12211224
der_inds = findall(vec(any(!=(0), Bs, dims = 1)))
1222-
error("Input derivatives appeared in expressions (-g_z\\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.")
1225+
error("Input derivatives appeared in expressions (-g_z\\g_u != 0), the following inputs appeared differentiated: $(inputs(sys)[der_inds]). Call `linear_statespace` 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.")
12231226
end
1224-
B = [B Bs]
1227+
B = [B [zeros(nx, nu); Bs]]
1228+
D = [D zeros(ny, nu)]
12251229
end
12261230
end
12271231

1228-
D = h_u
1229-
12301232
(; A, B, C, D)
12311233
end
12321234

0 commit comments

Comments
 (0)