Skip to content

Commit 7cb95f6

Browse files
committed
make feedback differentiable by avoiding try-catch
1 parent 5c4a565 commit 7cb95f6

File tree

1 file changed

+14
-17
lines changed

1 file changed

+14
-17
lines changed

src/connections.jl

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -286,28 +286,23 @@ See Zhou, Doyle, Glover (1996) for similar (somewhat less symmetric) formulas.
286286
D = [s1_D11 + α*s1_D12*s2_D22*s1_D21 α*s1_D12*s2_D21;
287287
s2_D12*s1_D21 s2_D11 + α*s2_D12*s1_D22*s2_D21]
288288
else
289-
# inv seems to be better than lu
290-
R1 = try
291-
inv*I - s2_D22*s1_D22) # slightly faster than α*inv(I - α*s2_D22*s1_D22)
292-
catch
289+
R1 = lu*I - s2_D22*s1_D22, check=false) # slightly faster than α*inv(I - α*s2_D22*s1_D22)
290+
issuccess(R1) || # Avoid try-catch for differtiability
293291
error("Ill-posed feedback interconnection, I - α*s2_D22*s1_D22 or I - α*s2_D22*s1_D22 not invertible")
294-
end
295292

296-
R2 = try
297-
inv(I - α*s1_D22*s2_D22)
298-
catch
293+
R2 = lu(I - α*s1_D22*s2_D22, check=false)
294+
issuccess(R2) || # Avoid try-catch for differtiability
299295
error("Ill-posed feedback interconnection, I - α*s2_D22*s1_D22 or I - α*s2_D22*s1_D22 not invertible")
300-
end
301296

302-
A = [sys1.A + s1_B2*R1*s2_D22*s1_C2 s1_B2*R1*s2_C2;
303-
s2_B2*R2*s1_C2 sys2.A + α*s2_B2*R2*s1_D22*s2_C2]
297+
A = [sys1.A + s1_B2*(R1\s2_D22)*s1_C2 s1_B2*(R1\s2_C2);
298+
s2_B2*(R2\s1_C2) sys2.A + α*s2_B2*(R2\s1_D22)*s2_C2]
304299

305-
B = [s1_B1 + s1_B2*R1*s2_D22*s1_D21 s1_B2*R1*s2_D21;
306-
s2_B2*R2*s1_D21 s2_B1 + α*s2_B2*R2*s1_D22*s2_D21]
307-
C = [s1_C1 + s1_D12*R1*s2_D22*s1_C2 s1_D12*R1*s2_C2;
308-
s2_D12*R2*s1_C2 s2_C1 + α*s2_D12*R2*s1_D22*s2_C2]
309-
D = [s1_D11 + s1_D12*R1*s2_D22*s1_D21 s1_D12*R1*s2_D21;
310-
s2_D12*R2*s1_D21 s2_D11 + α*s2_D12*R2*s1_D22*s2_D21]
300+
B = [s1_B1 + s1_B2*(R1\s2_D22)*s1_D21 s1_B2*(R1\s2_D21);
301+
s2_B2*(R2\s1_D21) s2_B1 + α*s2_B2*(R2\s1_D22)*s2_D21]
302+
C = [s1_C1 + s1_D12*(R1\s2_D22)*s1_C2 s1_D12*(R1\s2_C2);
303+
s2_D12*(R2\s1_C2) s2_C1 + α*s2_D12*(R2\s1_D22)*s2_C2]
304+
D = [s1_D11 + s1_D12*(R1\s2_D22)*s1_D21 s1_D12*(R1\s2_D21);
305+
s2_D12*(R2\s1_D21) s2_D11 + α*s2_D12*(R2\s1_D22)*s2_D21]
311306
end
312307

313308
return StateSpace(A, B[:, Wperm], C[Zperm,:], D[Zperm, Wperm], timeevol)
@@ -390,10 +385,12 @@ end
390385

391386
"""
392387
starprod(sys1, sys2, dimu, dimy)
388+
starprod(sys1, sys2)
393389
394390
Compute the Redheffer star product.
395391
396392
`length(U1) = length(Y2) = dimu` and `length(Y1) = length(U2) = dimy`
393+
If `dimu, dimy` are not provided, the maximum interconnection is formed, where all inputs and outputs of `sys2` are connected.
397394
398395
For details, see Chapter 9.3 in
399396
**Zhou, K. and JC Doyle**. Essentials of robust control, Prentice hall (NJ), 1998

0 commit comments

Comments
 (0)