Different results when running the same MATLAB program on different version of MATLAB
Show older comments
Hello, I would like to ask a question. Please use the following MATLAB program,
N = 256;
L = 50;
F = dftmtx(N);
RowsLeft = sort(setdiff(1:N, 20)); % to delete the 20th component from 1:N
B = F(RowsLeft,1:L);
C_matrix = abs(B'*B);
C_matrix = triu(C_matrix,1);
CDSValue = max(max(C_matrix)); When I run it on MATLAB R2011a, I get 1.000000000000009; however, when I run it on MATLAB R2009b, I get 1.000000000000011.
Now I would like to decide which component to delete so that the resulting matrix has the smallest CDSValue. Running on MATLAB R2011a, I will choose the 20th component, but on MATLAB R2009b, I will choose the 22th component. How can I avoid the difference?
Many thanks.
1 Comment
Friedrich
on 10 May 2012
If you need that amount of precision consider writing a mex file (so C/C++ code) which does all the computation. And in that mex file you use some special library for the precision , e.g.
http://www.ginac.de/CLN/
Answers (3)
Sean de Wolski
on 10 May 2012
2 votes
Are they on the same computer?
I would recommend not relying on something on the order of EPS. ( doc eps for more info).
Daniel Shub
on 10 May 2012
That is pretty dang close. In fact, if I counted the zeros correctly, the difference is on the order of
eps(1)
Basically as close as you can get with double precision floating point numbers.
Daniel Shub
on 10 May 2012
Looking at dftmtx in r2011a
type dftmtx
reveals that it has been changed on 2010/11/08. There is no change log and I do not have access to r2009b to do the comparison, but a slight change in the algorithm could easily result in a change in the output on the order of eps.
The bigger problem is that your algorithm is "broken". The problem is essentially FAQ 6.1. Basically you have at least 2 components that have the same magnitude (the 20th and 22nd). You need to look at all the components that have values "near the maximum" and then come up with a rule for throwing one out. Maybe what you want is
C_max = max(max(C_matrix));
tol = 5*eps(C_max);
thres = C_max-tol;
CDSValue = C_matrix(find(C_matrix > thres, 1, 'first'));
Categories
Find more on Number Theory in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!