All problems
Newton Step 2D
Problem
Take a full Newton step for a two-dimensional problem.
Compute delta = -H^{-1} grad using the 2x2 inverse and return [x + delta, delta]. If det(H) is zero, return [x, [0.0, 0.0]] with x unchanged.
Hint
The 2x2 inverse swaps the diagonal, negates the off-diagonals, and divides by the determinant.
Test cases
case 1
in: [[1,2],[1,1],[[2,0],[0,4]]]
expected: [[0.5,1.75],[-0.5,-0.25]]
case 2
in: [[0,0],[2,-2],[[3,1],[1,2]]]
expected: [[-1.2000000000000002,1.6],[-1.2000000000000002,1.6]]
case 3
in: [[1,1],[0,0],[[1,2],[2,4]]]
expected: [[1,1],[0,0]]
case 4
in: [[-1,0.5],[0.5,0.5],[[1,0],[0,1]]]
expected: [[-1.5,0],[-0.5,-0.5]]
Starter codePython
def newton_step_2d(x, grad, H):
# Returns [x_new, delta]
# Your code here
pass4 test cases · run your code against them in the editor