Skip to content
DeepForgeby svx
All problems
HardLinear Algebrala-140

Matrix Square Root 2x2

Problem

Compute the unique symmetric positive definite square root S of a symmetric positive definite 2x2 matrix A, so that S*S = A.

Use the eigendecomposition A = Q*Lambda*Q^T with orthonormal Q and return S = Q*sqrt(Lambda)*Q^T.

Hint

Take square roots of the eigenvalues while keeping the eigenvectors unchanged.

Test cases

case 1
in: [[[4,0],[0,9]]]
expected: [[2,0],[0,3]]
case 2
in: [[[1,0],[0,1]]]
expected: [[1,0],[0,1]]
case 3
in: [[[2,1],[1,2]]]
expected: [[1.3660254037844384,0.3660254037844386],[0.3660254037844386,1.3660254037844384]]
case 4
in: [[[5,4],[4,5]]]
expected: [[2,1],[1,2]]
Starter codePython
def matrix_sqrt_2x2(A):
    # Your code here
    pass

4 test cases · run your code against them in the editor