Successive Over-Relaxation (SoR) Method in MATLAB
Successive Over-Relaxation Method, also known as SOR method, is popular iterative method of linear algebra to solve linear system of equations. This method is the generalization of improvement on Gauss Seidel Method. Being extrapolated from Gauss Seidel Method, this method converges the solution faster than other iterative methods.
In this tutorial, we’re going to write a program for Successive Over-Relaxation – SoR method in MATLAB, and go through its mathematical derivation and theoretical background.
Derivation of SOR Method:
Consider the following sets of liner equations:
Express these equations in the form: Ax = b
Now, decompose matrix A into Diagonal component matrix D, Lower triangular matrix L, and upper triangular matrix U, such that:
Rewrite the system linear equation as:
( D + ωL ) x = ωb – [ ωU + ( ω – 1 ) D ] x
Where, ω is the relaxation factor and ω > 1
During the iteration process, the left hand side of the equation is solved by using the previous value for x on right hand side.
The iteration equation is expressed analytically as:
x (k+1) = ( D + ωL ) -1 (ωb – [ωU + (ω – 1 ) D ] x (k) ) = Lω (k) + c
Where, x (k) is the k th approximation for x and x(k+1) is (k+1) th approximation for x.
Taking the advantage of triangular matrix form of ( D + ωL), the (k+1) th can be evaluated sequentially by using forward substitution. The expression obtained for x (k+1) is:
SOR Method in MATLAB Code:
%for SOR method function x = SOR( A ,B ) disp ( ' Enter system of equations in the form of AX=B') % Calling matrix A A = input ( ' Enter matrix A : \n') % check for matrix A % it should be a square matrix [na , ma ] = size (A); if na ~= ma disp('ERROR:matrix A should be a square matrix') return end % calling matrix B B = input ( ' Enter matrix B : ') % check for matrix B [nb , mb ] = size (B); if nb ~= na || mb~=1 disp( 'ERROR:input error..pls re-enter data') return end w=input('Enter the relaxation parameter '); % A = D + L + U D = diag(diag(A)); L = tril(A)- D; U = triu(A)- D; % check for convergence of system e= max(eig(inv( D+w*L) * ( D*(1-w) - w*U))); if abs(e) >= 1 disp ('Since the modulus of largest eigen value of iterative matrix is not less than 1') disp ('This process is not convergent. Please try some other process.') return end % initial guess for X. % default guess is [ 1 1 . 1]' r = input ( 'Any initial guess for X? (y/n): ','s'); switch r case 'y' % asking for initial guess X0 = input('pls enter initial guess for X :\n') % check for intial guess [nx, mx] = size(X0); if nx ~= na || mx ~= 1 disp( 'ERROR: pls check input') return end otherwise X0 = ones(na,1); end %allowed error in final answer t = input ( 'enter the error allowed in final ans: '); tol = t*ones(na,1); k= 1; X( : , 1 ) = X0; err= 1000000000*rand(na,1); %intial error assumtion for looping while sum(abs(err) >= tol) ~= zeros(na,1) X ( : ,k+ 1 ) = inv(D+w*L) * ( D*(1-w) - w*U)*X( : ,k) + inv(D+ w*L)*B;% SOR formula err = X( :,k+1) - X( :, k);% finding error k = k + 1; end fprintf (' The final ans obtaibed after %d itaration which is \n', k) X( : ,k)The above code for Successive Over-Relaxation method in Matlab for solving linear system of equation is a three input program. Here, matrix A, matrix B, and relaxation parameter ω are the input to the program. The user defined function in the program proceeds with input arguments A and B and gives output X.
When the program is executed in MATLAB workspace, it asks for the value of coefficient matrix A and checks if it is square matrix or not. After getting valid input for A, another input matrix B is required to be entered to the program which must be a column matrix. Finally, the relaxation parameter is given as input and solution of linear equation comes as output.
While giving input to the program, the standard MATLAB syntaxes must be obeyed. Here’s a sample output of the MATLAB program for SOR method:
In this output of the Matlab program, 2x + y – z = 8, -3x – y + 2z = -11, and -2x + y +2z = -3 have been tried to be solved. But, the largest Eigen value of iterative matrix is not less than 1. As a result of which, the problem here is not suitable for SOR method.
You Might Also Like Simplex Method MATLAB Program Newton’s Interpolation in MATLAB (Forward and Backward) LU Factorization Method in MATLAB Lagrange Interpolation in MATLAB Gauss-Jordan Method in MATLAB Share This Article What do you think? 2 Comments 2 Comments Leave a Reply Cancel reply Latest Posts Creating a Google Sheet to Track Google Drive Files: Step-by-Step Guide Blog June 23, 2024 Cutting-Edge Artificial Intelligence Project Unveiled in Machine Learning World Machine Learning Projects May 10, 2024 Enhancing Exams with Image Processing: E-Assessment Project Deep Learning Projects May 10, 2024 Cutting-Edge Blockchain Projects for Cryptocurrency Enthusiasts – Project Blockchain Projects May 10, 2024 Artificial Intelligence Marvel: Cutting-Edge Machine Learning Project Machine Learning Projects May 10, 2024 Code with C: Your Ultimate Hub for Programming Tutorials, Projects, and Source Codes” is much more than just a website – it’s a vibrant, buzzing hive of coding knowledge and creativity. Quick Link Top Categories- C Projects
- C++ Projects
- Python Projects
- ASP.NET Projects
- PHP Projects
- VB & VB.NET Projects
We use cookies on our website to give you the most relevant experience by remembering your preferences and repeat visits. By clicking “Accept”, you consent to the use of ALL the cookies.
Privacy & Cookies Policy Privacy OverviewThis website uses cookies to improve your experience while you navigate through the website. Out of these cookies, the cookies that are categorized as necessary are stored on your browser as they are essential for the working of basic functionalities of the website. We also use third-party cookies that help us analyze and understand how you use this website. These cookies will be stored in your browser only with your consent. You also have the option to opt-out of these cookies. But opting out of some of these cookies may have an effect on your browsing experience.
Always EnabledNecessary cookies are absolutely essential for the website to function properly. This category only includes cookies that ensures basic functionalities and security features of the website. These cookies do not store any personal information.
Non-necessaryAny cookies that may not be particularly necessary for the website to function and is used specifically to collect user personal data via analytics, ads, other embedded contents are termed as non-necessary cookies. It is mandatory to procure user consent prior to running these cookies on your website.
Welcome Back!Sign in to your account