Can anybody please kindly explain to me why the members of the output vector produced by the following example are not equal to zero?
mm = 1000;
Clear[i, j, ss, EIG];
ss = ConstantArray[0, {mm, mm}];
%%% "Generating a random sparse matrix (ss)";
For[i = 1, i < (mm) + 1, i++,
For[j = 1, j < (mm) + 1, j++,
If[i == j,
ss[[i,j]] = (RandomReal[{-Mod[{i + j}, 2][[1]],Mod[{i + j}, 3][[1]]}, 1])[[1]];
];
If[Abs[i - j] == 1,
ss[[i,j]] = (RandomReal[{-Mod[{i + j}, 2][[1]],Mod[{i + j}, 3][[1]]}, 1])[[1]]+0.2;
];
If[Abs[i - j] == 2,
ss[[i,j]] = (RandomReal[{-Mod[{i + j}, 2][[1]],Mod[{i + j}, 3][[1]]}, 1])[[1]]-0.1;
];
If[Abs[i - j] == 3,
ss[[i,j]] = (RandomReal[{-Mod[{i + j}, 2][[1]],Mod[{i + j}, 2][[1]]}, 1])[[1]]+0.1;
];
];
];
EIG = Sort[(Select[Cases[(Eigenvalues[ss, -10]), _Real], # > 0 &]),Less];
EIG - Sort[(Select[Cases[(Eigenvalues[ss, -10]), _Real], # > 0 &]),Less]
For instance, one run of this example leaded to this vector:
{8.41341*10^-16, -2.57433*10^-15, -1.9082*10^-16, -8.32667*10^-17}
I am wondering why the output vector members are not zero! You can test this example on your PC. THNAKS.
Chopor by using higher precision (seeSetPrecisionfor example). – sebhofer Mar 11 at 12:22Chopindiscriminately. Since your are truncating the numbers, you are effectively adding in rounding errors, if done to early in the calculation, and can seriously impact the results. So,Chopaway, but do it at the end. – rcollyer Mar 11 at 12:28