mex c file and .m file gives slightly, but not neglegible, different returns!
1 次查看(过去 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!