Skip to content
DeepForgeby svx
All problems
HardOptimizationop-266

Gauss-Newton Step 2D

Problem

Take one Gauss-Newton step for a two-dimensional least-squares problem.

Given the 2x2 Jacobian J and residual vector r, solve (J^T J) delta = J^T r and return [x - delta, delta]. If J^T J is singular, return [x, [0.0, 0.0]].

Hint

Assemble J^T J and J^T r, then solve the 2x2 system for delta.

Test cases

case 1
in: [[0,0],[[1,0],[0,1]],[1,-2]]
expected: [[-1,2],[1,-2]]
case 2
in: [[1,1],[[1,2],[3,4]],[1,1]]
expected: [[2,0],[-1,1]]
case 3
in: [[0.5,-0.5],[[1,0],[0,0]],[2,3]]
expected: [[0.5,-0.5],[0,0]]
case 4
in: [[1,2],[[2,0],[1,1]],[0,0]]
expected: [[1,2],[0,0]]
Starter codePython
def gauss_newton_step_2d(x, J, r):
    # Returns [x_new, delta]
    # Your code here
    pass

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