2. Jacobi’s method¶
Derivation¶
Row \(i\) of \(Ax = b\) reads \(\sum_j a_{ij} x_j = b_i\). Solve it for \(x_i\):
Jacobi’s method uses this formula for every row at once, with the old values on the right-hand side:
In matrix form, with the splitting of section 1,
Because every new component uses only old values, the components can be computed in any order, or all at once with whole-array NumPy operations.
Your task¶
Open student/steps.py and write jacobi_sweep(A, b, x). It must:
compute every new component from the old vector
x;return the new iterate as a new array, without changing
A,borx.
You may use a loop over the rows, or whole-array operations (A @ x and
np.diag(A) are useful). Then run python verify.py. If your sweep is correct
you will see Jacobi 4/4 gates passed and an observed factor of about 0.9888.
If a gate fails¶
The most common Jacobi mistake is to update x while looping over the rows:
then later rows use new values, and the method is no longer Jacobi’s. Build the
new values in a separate array.