The help page of backslash does not print the singularity level.
Reported by Michael BAUDIN
-- Bug description --
The help page of backslash does not print the singularity level.
There are two algorithms behind backslash :
* if the inverse condition number is greater than sqrt(%eps),
a Gaussian elimination with partial pivoting is used,
* if not, a least square solution is computed.
The threshold is not printed in the help of backslash, and its
consequences are not explicit.
The following script shows the behavior of the algorithm,
by using Hilbert matrices of increasing size.
for n = 1 : 12
A = testmatrix("hilb",n);
b = ones(n,1);
x = linsolve(A,-b);
disp ( [ n cond(A) norm(A*x-b) ] )
end
We may critique the threshold level chosen in Scilab :
for matrices with condition numbers from 10^8 to 10^14,
the Gaussian elimination with partial pivoting
would give a more accurate solution than does
the least squares solution.
Matlab uses the more tolerant level %eps level, leading
to reduced forward errors (but the backward error may be
still large).
For example, the following session shows a particular
case where Matlab gives an answer with 7 digits
accurate, but Scilab give no digit.
Matlab :
n = 8;
e = ones(n,1);
A = hilb(n);
b = A*e;
x = A\b;
norm(A*x-b)/norm(b)
norm(x-e)/norm(e)
ans =
1.2558e-016
ans =
1.0147e-007
Scilab:
n = 8;
e = ones(n,1);
A = testmatrix("hilb",n);
b = A*e;
x = A\b;
norm(A*x-b)/norm(b)
norm(x-e)/norm(e)
Warning :
matrix is close to singular or badly scaled. rcond = 2.9522D-11
computing least squares solution. (see lsq).
ans =
0.0000567
ans =
1.0566191
-- Scilab error message --
-- How to reproduce the bug --