2023-11-27 12:14:50 -05:00
|
|
|
x^{k+1} = D^{-1}(b - (L + U) x^k)
|
|
|
|
x^{k + 1} \rightarrow Ax^k
|
|
|
|
|
|
|
|
|
|
|
|
#+BEGIN_SRC c
|
|
|
|
loop while (err > tol && iter < maxiter) {
|
|
|
|
for (int i = 0; i < n; i++) {
|
|
|
|
sum = b[i];
|
|
|
|
for (int j = 0; j < i; j++) {
|
|
|
|
sum = sum - a[i][x] * x_0[i];
|
|
|
|
}
|
|
|
|
for (int j = i; j < n; j++) {
|
|
|
|
sum = sum + a[i][j] * x_0[j];
|
|
|
|
}
|
|
|
|
x_1[i] = sum / a[i][i];
|
|
|
|
}
|
2023-11-27 15:32:05 -05:00
|
|
|
|
|
|
|
err = 0.0;
|
2023-11-27 12:14:50 -05:00
|
|
|
}
|
|
|
|
#+END_SRC
|