Skip to content

Commit b9531d5

Browse files
committed
make feedback differentiable by avoiding try-catch
1 parent 181cf1f commit b9531d5

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
@@ -299,28 +299,23 @@ See Zhou, Doyle, Glover (1996) for similar (somewhat less symmetric) formulas.
299299
D = [s1_D11 + α*s1_D12*s2_D22*s1_D21 α*s1_D12*s2_D21;
300300
s2_D12*s1_D21 s2_D11 + α*s2_D12*s1_D22*s2_D21]
301301
else
302-
# inv seems to be better than lu
303-
R1 = try
304-
inv*I - s2_D22*s1_D22) # slightly faster than α*inv(I - α*s2_D22*s1_D22)
305-
catch
302+
R1 = lu*I - s2_D22*s1_D22, check=false) # slightly faster than α*inv(I - α*s2_D22*s1_D22)
303+
issuccess(R1) || # Avoid try-catch for differtiability
306304
error("Ill-posed feedback interconnection, I - α*s2_D22*s1_D22 or I - α*s2_D22*s1_D22 not invertible")
307-
end
308305

309-
R2 = try
310-
inv(I - α*s1_D22*s2_D22)
311-
catch
306+
R2 = lu(I - α*s1_D22*s2_D22, check=false)
307+
issuccess(R2) || # Avoid try-catch for differtiability
312308
error("Ill-posed feedback interconnection, I - α*s2_D22*s1_D22 or I - α*s2_D22*s1_D22 not invertible")
313-
end
314309

315-
A = [sys1.A + s1_B2*R1*s2_D22*s1_C2 s1_B2*R1*s2_C2;
316-
s2_B2*R2*s1_C2 sys2.A + α*s2_B2*R2*s1_D22*s2_C2]
310+
A = [sys1.A + s1_B2*(R1\s2_D22)*s1_C2 s1_B2*(R1\s2_C2);
311+
s2_B2*(R2\s1_C2) sys2.A + α*s2_B2*(R2\s1_D22)*s2_C2]
317312

318-
B = [s1_B1 + s1_B2*R1*s2_D22*s1_D21 s1_B2*R1*s2_D21;
319-
s2_B2*R2*s1_D21 s2_B1 + α*s2_B2*R2*s1_D22*s2_D21]
320-
C = [s1_C1 + s1_D12*R1*s2_D22*s1_C2 s1_D12*R1*s2_C2;
321-
s2_D12*R2*s1_C2 s2_C1 + α*s2_D12*R2*s1_D22*s2_C2]
322-
D = [s1_D11 + s1_D12*R1*s2_D22*s1_D21 s1_D12*R1*s2_D21;
323-
s2_D12*R2*s1_D21 s2_D11 + α*s2_D12*R2*s1_D22*s2_D21]
313+
B = [s1_B1 + s1_B2*(R1\s2_D22)*s1_D21 s1_B2*(R1\s2_D21);
314+
s2_B2*(R2\s1_D21) s2_B1 + α*s2_B2*(R2\s1_D22)*s2_D21]
315+
C = [s1_C1 + s1_D12*(R1\s2_D22)*s1_C2 s1_D12*(R1\s2_C2);
316+
s2_D12*(R2\s1_C2) s2_C1 + α*s2_D12*(R2\s1_D22)*s2_C2]
317+
D = [s1_D11 + s1_D12*(R1\s2_D22)*s1_D21 s1_D12*(R1\s2_D21);
318+
s2_D12*(R2\s1_D21) s2_D11 + α*s2_D12*(R2\s1_D22)*s2_D21]
324319
end
325320

326321
return StateSpace(A, B[:, Wperm], C[Zperm,:], D[Zperm, Wperm], timeevol)
@@ -403,10 +398,12 @@ end
403398

404399
"""
405400
starprod(sys1, sys2, dimu, dimy)
401+
starprod(sys1, sys2)
406402
407403
Compute the Redheffer star product.
408404
409405
`length(U1) = length(Y2) = dimu` and `length(Y1) = length(U2) = dimy`
406+
If `dimu, dimy` are not provided, the maximum interconnection is formed, where all inputs and outputs of `sys2` are connected.
410407
411408
For details, see Chapter 9.3 in
412409
**Zhou, K. and JC Doyle**. Essentials of robust control, Prentice hall (NJ), 1998

0 commit comments

Comments
 (0)