[wpimath] Fix DARE Q decomposition (#5611)

This commit is contained in:
Tyler Veness
2023-09-05 10:48:43 -07:00
committed by GitHub
parent 9b3f7fb548
commit 1a6df6fec6
5 changed files with 49 additions and 8 deletions

View File

@@ -4,6 +4,7 @@
package edu.wpi.first.math;
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
@@ -312,4 +313,23 @@ class DARETest extends UtilityClassTest<DARE> {
assertThrows(IllegalArgumentException.class, () -> DARE.dare(A, B, Q, R, N));
}
@Test
void testQDecomposition() {
// Ensures the decomposition of Q into CᵀC is correct
var A = new Matrix<>(Nat.N2(), Nat.N2(), new double[] {1.0, 0.0, 0.0, 0.0});
var B = Matrix.eye(Nat.N2());
var R = Matrix.eye(Nat.N2());
// (A, C₁) should be detectable pair
var C_1 = new Matrix<>(Nat.N2(), Nat.N2(), new double[] {0.0, 0.0, 1.0, 0.0});
var Q_1 = C_1.transpose().times(C_1);
assertDoesNotThrow(() -> DARE.dare(A, B, Q_1, R));
// (A, C₂) shouldn't be detectable pair
var C_2 = C_1.transpose();
var Q_2 = C_2.transpose().times(C_2);
assertThrows(IllegalArgumentException.class, () -> DARE.dare(A, B, Q_2, R));
}
}