disp ('                This is the code of Gauss - Seidal  method.Is writen by Ali Ashouri')
disp (' ')
disp (' ')
n=input('   enter (n) the number of array of matrix (n*n)  :');
x=cell(1,n);
y=cell(1,n);
m=cell(1,n);
for i=1:n
    x(1,i)={0};
    y(1,i)={1};
    m(1,i)={0};
end;
u=input('  enter the error : ');
disp('     enter the data of matrix: from left to right then up to down ');
a=cell(n,n+1);
for i=1:n
    for j=1:n+1
        b=input('the number : ');
        a(i,j)={b};
    end;
end;
disp(a)
tic
for i=1:n
    g=cell2mat(a(i,i));
    if g==0
    else
        for j=1:n+1
            a(i,j)={(cell2mat(a(i,j))/g)};
        end;
    end;
end;
c=0;
while c<100000
    c=c+1;
    r=1;
    for l=1:n
            r=r*(abs(cell2mat(x(1,l))-cell2mat(y(1,l)))<u);
    end;
    if r==1
        break;
    end;
    for i=1:n
        g=cell2mat(a(i,n+1));
        x(1,i)={cell2mat(y(1,i))};
        for l=1:n
            m(1,l)={0};
        end;
        for j=1:n
            if i==j
            else
                q=cell2mat(m(1,i));
                o=cell2mat(a(i,j));
                k=cell2mat(y(1,j));
                m(1,i)={q+(o)*(k)};
            end;
        end;
        y(1,i)={g-cell2mat(m(1,i))};
    end;
end;
for i=1:n;
    q=cell2mat(x(1,i));
    disp(['     x_',num2str(i),'  =  ',num2str(q)]);
end;
disp(['      the number of stage is   : ',num2str(c)]);
toc