## Author: meral <meral@DESKTOP-7JLIIHR>
## Created: 2021-06-13

function retval = jacobi_seidel (a,b,x,lamd)
    n=length(a);
    imax=500;
    es=1.0e-20;
    dummy=0;
    ea=1e-1;
    sum=0;
    old=0;
    iter=0;
    sentinel=0;
    for i=1:n
        dummy=a(i,i);
        for j=1:n 
            a(i,j)/=dummy;
        endfor
        b(i)/=dummy;
    endfor
    for i=1:n
        sum=b(i);
        for j=1:n
             if i!=j
               sum-=a(i,j)*x(j);
             endif
        endfor     
        x(i)=sum;
    iter=iter+1;
    endfor
    while iter<imax
      sentinel=1;
      for i=1:n
          old=x(i);
          sum=b(i);
          for j=1:n
              if i!=j 
                  sum=sum-a(i,j)*x(j);
              endif
          endfor
          x(i)=lamd*sum+(1.0-lamd)*old;
          if sentinel==1 && x(i)!=0.0
            ea=abs((x(i)-old)/x(i))*100.0;
          endif
          if ea<es 
            retval=x;   
          endif
      endfor
      iter=iter+1;
    endwhile
retval=x;  
endfunction
