File Exchange

image thumbnail

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.

24 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 (2021). SOR Method (https://www.mathworks.com/matlabcentral/fileexchange/66570-sor-method), MATLAB Central File Exchange. Retrieved .

Comments and Ratings (4)

Newton Solomon

@Aaron gamez : B is the solution vector of a system of equations (matrix A), i.e. Ax=B, where x is the unknown vector

Aaron gamez

Hello Huy Ho, can you explain me what is b in this code? Thanks you!

nouna nouni

didn't work for me help SOS

J

MATLAB Release Compatibility
Created with R2017a
Compatible with any release
Platform Compatibility
Windows macOS Linux
Categories
Tags Add Tags

Community Treasure Hunt

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

Start Hunting!