1 function [x, iterations, residual_norms] = ...
2 successive_over_relaxation(A, b, omega, x0, ...
3 tolerance, max_iterations)
9 % iteratively using SOR. That is, we let,
11 % A = M - N = ((1/omega)*D + L) - U
13 % where D is a diagonal matrix consisting of the diagonal entries of
14 % A (the rest zeros), and L,U are the upper- and lower-triangular
15 % parts of A respectively. Now,
17 % Ax = (M - N)x = Mx - Nx = b
23 % Thus, our iterations are of the form,
25 % x_{k+1} = M^(-1)*(Nx_{k} + b)
29 % ``A`` -- The n-by-n coefficient matrix of the system.
31 % ``b`` -- An n-by-1 vector; the right-hand side of the system.
33 % ``x0`` -- An n-by-1 vector; an initial guess to the solution.
35 % ``omega`` -- The relaxation factor.
37 % ``tolerance`` -- (optional; default: 1e-10) the stopping tolerance.
38 % we stop when the relative error (the infinity norm
39 % of the residual divided by the infinity norm of
40 % ``b``) is less than ``tolerance``.
42 % ``max_iterations`` -- (optional; default: intmax) the maximum
43 % number of iterations we will perform.
47 % ``x`` -- An n-by-1 vector; the approximate solution to the system.
49 % ``iterations`` -- The number of iterations taken.
51 % ``residual_norms`` -- An n-by-iterations vector of the residual
52 % (infinity)norms at each iteration. If not
53 % requested, they will not be computed to
62 max_iterations = intmax();
65 M_of_A = @(A) (1/omega)*diag(diag(A)) + tril(A,-1);
68 [x, iterations, residual_norms] = ...
69 classical_iteration(A, b, x0, M_of_A, tolerance, max_iterations);
72 classical_iteration(A, b, x0, M_of_A, tolerance, max_iterations);