matlab precision error in comparison with fortran's code
显示 更早的评论
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 个评论
Walter Roberson
2014-3-3
what value are you using for digits() ?
Is it possible that Fortran is the one that is being less precise?
James Tursa
2014-3-3
How do you know that the inputs are "exactly" the same between MATLAB and Fortran? Did you write out a binary file on one side and read it in on the other side? Did you pass inputs directly via mex function? Or what? What does your Fortran code look like?
Strat Mpi
2014-3-4
Strat Mpi
2014-3-4
James Tursa
2014-3-4
"... 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.
采纳的回答
更多回答(1 个)
Walter Roberson
2014-3-3
0 个投票
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
类别
在 帮助中心 和 File Exchange 中查找有关 Fortran with MATLAB 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!