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 Kommentare

what value are you using for digits() ?
Is it possible that Fortran is the one that is being less precise?
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?
M.Walter Roberson i use the default 15 value digits.As far as if fortran is less precise this is a question i asked to myself and i do not know any way to confirm which result is more accurate.
M.James Tursa i know the inputs are exactly the same because i checked it while debugging. Before the "sumlv = sym(sumlv) + sym(conj(q(i))).*sym(hq(i));" is executed i checked all the values of q(i) and hq(i) in fortran and matlab code.I did not use the mex function.I converted fortran code to matlab. The fortran code looks like do i=1,n-1 sum=sum+dconjg(q(i))*hq(i) enddo cen=rdx*sum. The precision problem is in the sum value.Matlab's sum=8.884283763909400e+00. Fortran's sum=8.884283763909473. The q(i), hq(i) have the same values in both fortran and matlab so i assume that there is a precision issue in the result.
"... 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.

Melden Sie sich an, um zu kommentieren.

 Akzeptierte Antwort

Iain
Iain am 4 Mär. 2014

0 Stimmen

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 Kommentare

I did write the values to a binary file as you said and the result is still the same.The values have the same values while debugging.As i see it there is a computation error because the values are the same so something is going on with the way matlab does the calculation.The point is which result is more accurate fortran's or Matlab's?
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.
I think this is the best way for my case. Thank you very much for your answer

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

Walter Roberson
Walter Roberson am 3 Mär. 2014

0 Stimmen

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

Kategorien

Mehr zu Fortran with MATLAB finden Sie in Hilfe-Center und File Exchange

Gefragt:

am 3 Mär. 2014

Kommentiert:

am 4 Mär. 2014

Community Treasure Hunt

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

Start Hunting!

Translated by