All problems
Orthogonal Diagonalization Check
Problem
Check whether the 2x2 matrix A is orthogonally diagonalized by Q: Q must be orthogonal and Q^T*A*Q must be diagonal, all within 1e-9.
If both conditions hold, return the diagonal entries in order; otherwise return None.
Hint
A symmetric matrix is orthogonally diagonalizable; a non-orthogonal Q fails the first check.
Test cases
case 1
in: [[[2,0],[0,3]],[[1,0],[0,1]]]
expected: [2,3]
case 2
in: [[[2,1],[1,2]],[[0.7071067811865475,-0.7071067811865475],[0.7071067811865475,0.7071067811865475]]]
expected: [3,1]
case 3
in: [[[2,1],[1,2]],[[1,0],[0,1]]]
expected: null
case 4
in: [[[2,0],[0,3]],[[1,1],[0,1]]]
expected: null
Starter codePython
def orthogonal_diagonalization(A, Q):
# Your code here
pass4 test cases · run your code against them in the editor