Different results when running the same MATLAB program on different version of MATLAB

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

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/

Sign in to comment.

Answers (3)

Are they on the same computer?
I would recommend not relying on something on the order of EPS. ( doc eps for more info).

2 Comments

For different computer, with the same version of MATLAB installed, the results are the same. However, for different version of MATLAB, the results are different.

Sign in to comment.

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.
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'));

1 Comment

When I run the program,
N = 256;
L = 50;
F = dftmtx(N);
RowsLeft = sort(setdiff(1:N, 20)); % delelte the 20th component
B = F(RowsLeft,1:L);
C_matrix = abs(B'*B);
C_matrix = triu(C_matrix,1);
C_max = max(max(C_matrix));
tol = 5*eps(C_max);
thres = C_max-tol;
CDSValue = C_matrix(find(C_matrix > thres, 1, 'first'));
On MATLAB R2011a,
CDSValue = 1.000000000000009 if delete the 20th component
CDSValue = 1.000000000000012 if delete the 22th component
But on MATLAB R2009b,
CDSValue = 1.000000000000011 if delete the 20th component
CDSValue = 1.000000000000008 if delete the 22th component
Thanks

Sign in to comment.

Products

Asked:

on 10 May 2012

Community Treasure Hunt

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

Start Hunting!