matlab precision error in comparison with fortran's code
12 views (last 30 days)
Show older comments
Hi everyone
I need your help with the problem am dealing with. I have converted fortran code to matlab and the matlab's result is not exactly the same with fortran's code.
for i = 1 : n - 1;
sumlv = sym(sumlv) + sym(conj(q(i))).*sym(hq(i));
end; i = fix(n);
aa=vpa(sumlv);
cen = rdx.*aa;
--------------------------
The n=2048. The matrices q and hq have exactly the same values with fortran's code.
Matlab's cen= 1.110535470488675 .Fortran's cen= .110535470488684d+01.
When i use the vpa i have cen=1.1105354704886762457328491316803 which still is not the same with fortran's result.Does anyone know what to do with the specific problem?
As i saw in Matlab's code the higher the number of values in metrices the higher the presicion error is occured in comparison with fortran's code.
Thanks in advance
5 Comments
James Tursa
on 4 Mar 2014
"... because I checked ..." doesn't tell me anything. HOW did you check? By comparing the printed digits on the screen of both versions (inadequate)? Or by comparing bit-for-bit the underlying floating point bit patterns (adequate)? Once that is settled, then we can talk about other differences such as compiled Fortran code perhaps holding intermediate results in 80-bit registers but the MATLAB code not doing this, etc.
Accepted Answer
Iain
on 4 Mar 2014
If you want to compare the values to see if they're exactly the same, you can write the values to a binary file, and then read them back in as integers. This will let you compare the binary sequences using both languages, so you can calculate the error.
If the error is at the level of eps(answer), I wouldn't worry too much...
3 Comments
Iain
on 4 Mar 2014
For errors that are close to the machine precision (epsilon) of the system, I wouldn't worry too much.
To determine which is more or less precise, I would suggest that you compare them to "truth". Truth in this case would be doing the sums, by hand, without rounding or any errors. The errors you may be seeing may well be due to simply the order in which the calculations were done, or if fortran internally uses double-extended precision.
More Answers (1)
Walter Roberson
on 3 Mar 2014
Consider using the built-in symbolic dot product function. The following post shows how you would access it: http://www.mathworks.com/matlabcentral/answers/15949
0 Comments
See Also
Categories
Find more on Fortran with MATLAB 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!