All problems
Matrix Square Root Newton Step
Problem
Perform one Newton iteration for the matrix square root of A, starting from X:
X_new = 0.5 * (X + A * inv(X))
A and X are 2x2 matrices. Return None if X is singular. For a good starting X this doubles the number of correct digits.
Hint
This is the matrix analogue of the scalar Newton iteration x <- (x + a/x) / 2.
Test cases
case 1
in: [[[4,0],[0,9]],[[2,0],[0,3]]]
expected: [[2,0],[0,3]]
case 2
in: [[[4,0],[0,9]],[[1,0],[0,1]]]
expected: [[2.5,0],[0,5]]
case 3
in: [[[5,4],[4,5]],[[2,0],[0,2]]]
expected: [[2.25,1],[1,2.25]]
case 4
in: [[[1,0],[0,1]],[[1,1],[1,1]]]
expected: null
Starter codePython
def sqrt_newton_step(A, X):
# Your code here
pass4 test cases · run your code against them in the editor