SOR Method

Version 1.0.0.0 (322 Bytes) by Huy Ho
Input a square matrix. Decomposing the matrix into diagonal, lower and upper triangle matrix.
794 Downloads
Updated 21 Mar 2018

View License

function [x] = SOR_HW(A,b,x_0,omega)% Input a square matrix A, b, initial x and value of omega
format long;
N = 1000; %number of iteration
n = length(A);
tol = 0.0001;
x =zeros(n,1);
%Decomposing the Square matrix A into three matrices: diagonal matrix (D); strictly lower triangular matrix (L); strictly upper triangular matrix(U)
D = diag(diag(A));
L =-tril(A,-1);
U = -triu(A,1);
a = (D-omega*L);
for i=1:N
x = a\(((1-omega)*D + omega*U)*x_0) + omega*(a\b);
if norm(x-x_0)<tol
break;
end
x_0=x;
end
end

Cite As

Huy Ho (2024). SOR Method (https://www.mathworks.com/matlabcentral/fileexchange/66570-sor-method), MATLAB Central File Exchange. Retrieved .

MATLAB Release Compatibility
Created with R2017a
Compatible with any release
Platform Compatibility
Windows macOS Linux
Categories
Find more on Linear Algebra in Help Center and MATLAB Answers
Tags Add Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!
Version Published Release Notes
1.0.0.0