So I am running a matlab code for the Gauss-Seidel method and I keep getting returned the values for x1, x2 and x3 being NaN where it converges and I should be getting values. Could someone show me what I am missing? my code is this: C=[1 -(1/3) -2,0 5 1, -6 1 2]; D=[5,10,-10]; %% Part 2: Gauss-Seidel n=1; %index start tol=100; %initial value for tolerance Tol=1e-6; %desired end tolerance x1(1)=1; %initial guesses x2(1)=1; x3(1)=1; while tol>Tol x1(n+1)=(1/1)*(-(-1/3)*x2(n)-(-2)*x3(n)+5); x2(n+1)=(1/5)*(-0*x1(n+1)-1*x3(n)+10); x3(n+1)=(1/2)*(-(-6)*x1(n+1)-1*x2(n+1)-10); tol1=abs(x1(n+1)-x1(n)); tol2=abs(x2(n+1)-x2(n)); tol3=abs(x3(n+1)-x3(n)); tol=max([tol1;tol2;tol3]) n=n+1; end n-1 x1(end) x2(end) x3(end) This is what I am getting: ans = 395 ans = NaN ans = NaN ans = NaN >> I would really appreciate the help, thank you. Solution Its to be noted that gauss -siedel method converges only if absolute value of largest coefficient is greater than some of absolute values of remaining coefficients. so, its not applicable to the above equations.