0

Hello,
I have a problem with the atan2 function.
I have 2 programs, one in C and one in Matlab. Both have an identical implementation.
My problem is that I am getting occasionally different values from the atan2 function in C and Matlab.
For instance:
x=0.29695007709080329
y= -0.96764419257510348
Matlab atan2= 2.8438364863237604
C atan2= 2.8438364863237608
So only the last digit is different (and not in all cases), but unfortunately, I would need the values to be identical.
Do you have any ideas it might be like this and how can I solve it?
Thank you.

2
Contributors
6
Replies
8
Views
6 Years
Discussion Span
Last Post by CD1
0

Solved the problem (more or less).
It seems that the retun values of the two functions differ a little.
So one solution is to make a mex function (c function that can be executed in matlab) that implements the atan2 funtion.
Now the output is the same.

0

It seems like I actually haven't solved the problem. The values are still sometimes different and I have no clue why.
I have even set the same compiler for the mex files and the C program, and still the values are a little different.
Does anyone have any idea why?
Thank you

0

Matlab likely guarantees a higher precision than C, and what you're seeing is the round-off errors creeping into the C algorithm.

0

Is there any way to set them to return the same values, maybe set the precision in matlab?

0

You can round to something like six digits in both languages, that would probably be more than sufficient.

0

Thx for the answer. I will give it a try, see what happens.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.