Obtained true when false

I am trying to implement the Jacobi (j) and Gauss-Seidel (gs) method on Matlab. In order to those methods to work I need to check the norms of their matrices Cj and Cgs, and if they are greater than 1 there's the need of the evaluation of the spectral radius:
rj = [norm(Cj,1) norm(Cj,2) norm(Cj,"inf") max(abs(eig(Cj)))];
rgs = [norm(Cgs,1) norm(Cgs,2) norm(Cgs,"inf") max(abs(eig(Cgs)))];
then I check if any of those is less than 1:
for i=1:4
if rj(i)<1 && rgs(i)<1 %if they both work, prefer gs
[x,k]=Gauss_Seidel(A,b,kmax,tol);
break;
elseif rgs(i)<1
[x,k]=Gauss_Seidel(A,b,kmax,tol);
break;
elseif rj(i)<1
[x,k]=Jacobi(A,b,kmax,tol);
break;
the point is that I get these two arrays for rj and rgs and theese answers for the check:
why the last component is considered to be lesser than 1?

Risposte (1)

Torsten
Torsten il 9 Apr 2023
Spostato: Matt J il 9 Apr 2023

1 voto

In the output, the number is rounded to 1.00000... . But this does not mean that the original number cannot be < 1.

Prodotti

Release

R2023a

Spostato:

il 9 Apr 2023

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by