mex c file and .m file gives slightly, but not neglegible, different returns!
2 ビュー (過去 30 日間)
古いコメントを表示
I have a MALTAB script doing some iterative algorithm give a return. This .m file was also coded as a mex c file which gives same return. Both returns is a 28374 X 1 vector, the data type is double in mex c file.
I ran these two files, and the returns are slightly different! And the difference amplifies as number of the iteration increases. For example, at 2nd iteration, the error is about 25; but at 5th iteration, the error goes up to about 500;
I also looked at the returns by plotting them. They look similar, apparently have similar pattern/shape. But they are just not the same, obviously.
I have spent much time double checking my code, especially for the mex c code, but I did not spot anything wrong yet.
I am using my windows 7 laptop to run the program on a Ubuntu remotely.
I have no idea what could be the cause of the problem. Anyone has any similar experience? Big edien? little endien? Any pointer is appreciated !
Nick
採用された回答
Jan
2012 年 3 月 24 日
This is a usual effect of the limited floating point precision. Even for a simple addition of three doubles the order matters:
(a + b) + c ~= a + (b + c) % in general
Trigonometric functions, e.g. ACOS and LOG10 reply slightly different results also, if the arguments are inside intervals of numerical instabilities.
The growing of the difference with the number of iterations mean, that the method is instable.
その他の回答 (0 件)
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!