Precision quandaries: why can I print 64 digits?
Show older comments
I've been testing a Modified Gram-Schmidt algorithm that is part of a larger pipeline:
function [Q, R] = mgs(X)
% [Q, R] = MGS(X) performs Modified Gram-Schmidt on the m x s matrix X.
%%
% Pre-allocate memory for Q and R
[m, s] = size(X);
R = zeros(s,s);
Q = zeros(m,s);
% Modified Gram-Schmidt
R(1,1) = norm(X(:,1));
Q(:,1) = X(:,1)/R(1,1);
for k = 1:s-1
w = X(:,k+1);
for j = 1:k
R(j,k+1) = Q(:,j)'*w;
w = w - Q(:,j)*R(j,k+1);
end
R(k+1,k+1) = norm(w);
Q(:,k+1) = w/R(k+1,k+1);
end
end
Farther down the software pipeline, I measure loss of orthogonality and backward error. My colleague ran our software on her machine and found that for several key examples I have nearly full orthogonality and she has none. I am 100% certain we are using the same X and software (we checked; everything is pushed and pulled through Git).
We found something surprising with the following script that may explain the issue:
% mgs test
X = magic(10); X = X(:,1:2);
[Q, R] = mgs(X);
fprintf('||I - Q''*Q|| = %0.64e\n', norm(eye(2) - Q'*Q)); % loss of orthogonality
fprintf('||Q*R - X|| = %0.64e\n', norm(Q*R - X)); % backward error
% Results on my machine:
% mgs:
% ||I - Q'*Q|| = 4.1017407521273322775592436112613973088682572487422006712876054735e-16
% ||Q*R - X|| = 1.7763568394002504646778106689453125000000000000000000000000000000e-15
The same script on her machine prints trailing 0's after the 16th digit for both quantities.
I had assumed that Matlab computed in double precision regardless of the machine, but it would seem that Matlab is somehow utilizing higher precision on my machine than on my colleague's. Or is there another explanation for why I can print 64 digits of precision?
My specs: Matlab 2019a, Windows 10 64-bit, Intel Core i7-8850U CPU @ 1.80GHz, 16GB RAM, Thinkpad X1 Carbon Gen 6
Colleague's: Matlab 2017a, Windows 7 (don't know the rest but her Thinkpad is about 6 years older than mine, so likely lacking some features that mine has)
Accepted Answer
More Answers (0)
Categories
Find more on Logical in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!