Skip to content
DeepForgeby svx
All problems
MediumLinear Algebrala-113

Jacobi Iteration One Step

Problem

Perform one Jacobi iteration step for the system A*x = b from the current guess x0:

x_new[i] = (b[i] - sum over j != i of A[i][j] * x0[j]) / A[i][i]

Assume all diagonal entries are nonzero. Return the updated vector as floats.

Hint

Every component is updated using only the old vector x0.

Test cases

case 1
in: [[[4,1],[1,3]],[1,2],[0,0]]
expected: [0.25,0.6666666666666666]
case 2
in: [[[2,0],[0,4]],[4,8],[0,0]]
expected: [2,2]
case 3
in: [[[4,1],[1,3]],[1,2],[1,1]]
expected: [0,0.3333333333333333]
case 4
in: [[[3,-1],[-1,2]],[5,3],[0,0]]
expected: [1.6666666666666667,1.5]
Starter codePython
def jacobi_step(A, b, x0):
    # Your code here
    pass

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