All problems
Gauss-Seidel Iteration One Step
Problem
Perform one Gauss-Seidel iteration step for A*x = b from the guess x0, updating in place:
x_new[i] = (b[i] - sum over j != i of A[i][j] * x[j]) / A[i][i]
Already updated components are used immediately. Assume nonzero diagonal.
Hint
Unlike Jacobi, the first updated entry is immediately used by later rows.
Test cases
case 1
in: [[[4,1],[1,3]],[1,2],[0,0]]
expected: [0.25,0.5833333333333334]
case 2
in: [[[2,0],[0,4]],[4,8],[0,0]]
expected: [2,2]
case 3
in: [[[3,-1],[-1,2]],[5,3],[0,0]]
expected: [1.6666666666666667,2.3333333333333335]
case 4
in: [[[4,1],[1,3]],[1,2],[1,1]]
expected: [0,0.6666666666666666]
Starter codePython
def gauss_seidel_step(A, b, x0):
# Your code here
pass4 test cases · run your code against them in the editor