SOR Method
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 (2023). SOR Method (https://www.mathworks.com/matlabcentral/fileexchange/66570-sor-method), MATLAB Central File Exchange. Retrieved .
MATLAB Release Compatibility
Platform Compatibility
Windows macOS LinuxCategories
- MATLAB > Mathematics > Linear Algebra >
Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Discover Live Editor
Create scripts with code, output, and formatted text in a single executable document.
Version | Published | Release Notes | |
---|---|---|---|
1.0.0.0 |