필터 지우기
필터 지우기

Numerical instability of acos

조회 수: 7 (최근 30일)
Harvey Rael
Harvey Rael 2018년 8월 3일
편집: James Tursa 2018년 8월 3일
Hi,
I have a bunch of vectors that I wish to calculate the angle between in a 2-D case, but I am finding that where I know the angle should be greater than 180(or begin again after 360) it is giving me funny values. I have read that there is some numerical instability in acos. Was hoping that someone could provide a more stable version that won't require too much post calculation manipulation? (as I have 180x40 angles to calculate)
Thanks
  댓글 수: 3
Harvey Rael
Harvey Rael 2018년 8월 3일
I can't show any code as it would require sending over a lot of files and functions as I am plotting planetary motion, but I can assure you that acosd is formulated well. I checked the answers for the first 30 or so angles on a calculator and they worked out fine. There's just these random errors
David Goodmanson
David Goodmanson 2018년 8월 3일
Hello Harvey,
Since you are calling acosd and/or acos into question, could you provide an example value or vector of values where the results of acosd are 'unstable'?
For physical values -1<=x<=1, the range of acosd(x) is 0<=theta<=180. With its single input x, acosd is incapable of returning angles not in that range. Unlike atan2d, with its two inputs and larger range -180<=theta<=180.

댓글을 달려면 로그인하십시오.

답변 (1개)

James Tursa
James Tursa 2018년 8월 3일
편집: James Tursa 2018년 8월 3일
Since you don't show us any code so that we can see where these "funny" values might be coming from, I can only point you to this thread which gives some insight into small angle issues:
However, I still suspect that it may be the formulation of the acos argument itself that is having cancellation error or the like that is causing your problems. But we can't advise without seeing the relevant code.

태그

제품


릴리스

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by