Skip to content
DeepForgeby svx
All problems
MediumLinear Algebrala-311

Least Squares Residual Sum of Squares

Problem

Compute the residual sum of squares for a candidate solution x of A*x = b:

RSS = ||A*x - b||^2

Return the scalar sum of squared residuals. A zero result means x solves the system exactly.

Hint

Form the residual vector first, then square and sum its entries.

Test cases

case 1
in: [[[1,0],[0,1]],[2,3],[2,3]]
expected: 0
case 2
in: [[[1,1],[1,2],[1,3]],[1,2,3],[0,1]]
expected: 0
case 3
in: [[[1],[1]],[1,3],[1]]
expected: 4
case 4
in: [[[1,0],[0,1]],[1,1],[2,2]]
expected: 2
case 5
in: [[[1,2],[3,4]],[0,0],[0,0]]
expected: 0
Starter codePython
def least_squares_rss(A, b, x):
    # Your code here
    pass

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