This is a small and simple program to solve the linear system Au=F when A is a diagonally dominant matrix. Although the program is quite simple, I didn't find it in this page, so I decided to post it.
This program may be useful to people programing solving Partial Differential Equations via Finite Differences. This method may be more efficient than Gauss elimination for large matrices, usually found for 2D and 3D problems.
[u, it] = sor(A,F) finds the solution of the linear system applying successive
under/over relaxation technique. In this case the parameter w, the initial guess u0, the stopping criterion dtol and the maximum number of iterations
itmax are to default values: w = 1.5, u0 = F.*0+1, dtol = 1e-3, itmax = 1000.
The parameter w can theoretically take values between 0 - 2. However, the number of iterations may be reduced if is taken near 1.5. Using w = 1 will be equivalent to use Gauss-Seidel method.
u0 is the initial guess used by SOR to find the solution. The better the initial guess the faster the solution is found. However, if the matrix A is strictly diagonally dominant, the method converges to the solution no matter the initial guess (see
Lecture 6 "Iterative Techniques").
As stated before the matrix A should be diagonally dominant. This program DOESN'T check this property; you will just get a NaN vector or something similar as an answer.
Finally the program will stop when abs(u-ui)/abs(ui) < dtol, where u and
ui are the solution and initial guess used for a particular iteration.