0

I have created a Mex-file (.mexw64) from my matlab project using Matlab Coder. The problem is that the output is not the same when I run the mex-file as when I run the project in a normal way. Often the variation in the numbers are really small:

5.4463.. -> 5.4465.. etc.

I'm thinking that there might be a problem related fixed point computations. What should I look for?

Michael Ward
  • 213
  • 5
  • 12
  • You have an m-script file that acts one way when executed and another way when compiled as an executable, is this correct? Where does the fixed-pointing com into play? – macduff Mar 02 '12 at 14:20
  • Hehe. Maybe it doesn't. I do not know why the behaviour is different. What may the reasons be? Thankful for your help. – Michael Ward Mar 02 '12 at 14:37
  • I'm thinking there is no fixed-pointing difference. When we start talking about differences in the 4th decimal place, I'd say it's the difference between interpreted m-script and compiled C code. I'd guess the C code is more correct, but it's just a guess – macduff Mar 02 '12 at 15:36
  • But as the code is written in Matlab and then turned into c-code with Matlab Coder it is the Matlab-code that is _"correct"_ in the sense that I wish to emulate this code exactly. Could it have anything to do with the `extrinsic functions` I have, or is it some sort of internal translation error? – Michael Ward Mar 02 '12 at 15:41
  • I have been printing along the way of the execution and found differencies like these in the prints. 0.449101628450606 -> 0.449101628450607 it is just in the last decimal that the mex-execution is of by 1.. But it would be strange if this rounding error produced so severe differencies as those that occur later.. – Michael Ward Mar 02 '12 at 16:21
  • More information is needed here. Did you mean floating point? Source could help. I used to run molecular dynamics simulations, and using a code that isn't careful, the length of a simulation can be limited by the accumulation of round-off errors. – Prashant Kumar Mar 02 '12 at 19:49
  • 1
    This is why numerical analysis exists. There may be a significant difference in the result when operations are executed in different sequence. (a+b)*c is not always same as a*c + b*c. – Daniyar Mar 02 '12 at 20:33

1 Answers1

0

Expected differences from MATLAB are explained in the documentation. See the section on Floating-point Numerical results:

MATLAB Coder Documentation on expected differences.