**Problem:**Develop a MATLAB code to solve the following system of algebraic equations using the Successive-over-Relaxation Method.

Solution:

**Successive over Relaxation Method:**This method is just the modification of the Gauss-Seidel method with an addition relaxation factor 𝛚. This method gives convergent solution as there is an option for under relaxation when 𝛚 is less than one. For different 𝛚, the following program can determine the solution. However, when 𝛚 is

*0.05*, the relatively better results are obtained.

**MATLAB Program for**

**Successive Over Relaxation (SOR) Method**

function x = sor(a,b,x0,e,N,w)

% a - (nxn) matrix

% b - column vector of length n

% x0 - initial solution

% e - error definition

% N - no. of iterations

% w – relaxation factor

format long;

m=size(a,1);

n=length(b);

p=length(x0);

q=length(e);

if (m ~= n)

error('a and b do not have the same number of rows')

end

y0=x0;

for i=1:m

[~,f]=max(abs(a(1:m,i:i)));

% disp(f);

a([i,f],1:n)=a([f,i],1:n);

end

for t=1:m

if a(t,t)==0

[~,g]=max(abs(a(1:m,t:t)));

a([t,g],1:n)=a([g,t],1:n);

end

end

% disp(a);

c=1;

while(c<N)

for j=1:m

for k=1:p

Z(1,k)=(a(j,1:n)*y0(1:p,1));

end

Y(j:j,1)=sum(Z(1,k));

% disp(Y);

R(j:j,1)=b(j:j,1)-Y(j:j,1);

% disp (R);

x(j:j,1)=y0(j:j,1)+((R(j:j,1)*w)/a(j:j,j:j));

y0(j:j,1)= x(j:j,1);

% disp (y0);

% disp (x);

end

if (abs(x(1:p,1)-x0(1:p,1)) < e(1:q,1))

break;

end

disp (x);

disp(abs(x(1:p,1)-x0(1:p,1)));

x0=y0;

c=c+1;

end

x=x(1:p,1);

end

__Program Outputs:__

ans =

2.322822494693882

0.675693020694401

2.160169880982512

-0.350429027969758

-0.428941223493063

-0.394923172868219

Error Percentage: 2.2%, 1.5%, 1.4%, 2.6%, 0.9% and 5.8%.

## No comments:

## Post a Comment