atan2 & mod number not converges to correct value???

조회 수: 4 (최근 30일)
Baha411
Baha411 2019년 7월 8일
댓글: Baha411 2019년 7월 8일
Hi All,
I am calculating principle axis values using eigen values and calculating the angles ang1 & ang2 as below.
clear all; clc;
Ix0 = 1.3562e+08;
Iy0 = 3.3113e+06;
Ixy0 = 2.9802e-07;
I = [ Ix0 -Ixy0 ;
-Ixy0 Iy0 ];
[ eig_vec, eig_val ] = eig(I);
I1 = eig_val(1,1);
I2 = eig_val(2,2);
ang1 = atan2( eig_vec(2,1), eig_vec(1,1) );
ang2 = atan2( eig_vec(2,2), eig_vec(1,2) );
ang1_d = ang1*180/pi;
ang2_d = ang2*180/pi;
ang1_ = mod(abs(ang1_d), 90);
ang2_ = mod(abs(ang2_d), 90)
ang2_ =
90.0000
ang2_ = mod(abs(ang2_d), 90) shoud be ~= 0, but it is not. What's wrong in here?

답변 (1개)

Steven Lord
Steven Lord 2019년 7월 8일
First, if you want angles in degrees use atan2d directly.
But as for what you're seeing with ang2_ being 90.0000? Your angle is not exactly ninety but is very slightly less than ninety, small enough that mod(..., 90) returns the number itself but close enough that to four decimal places it is 90.0000. See how far away it is from ninety.
difference = 90-ang2_
The value of difference will not be 0, but it will be a very small number.
  댓글 수: 1
Baha411
Baha411 2019년 7월 8일
Thanks for your answer. Yeah very close
vpa(90-ang2_)
ans =
0.00000000000014210854715202003717422485351562
I use both radian and degrees in my code.
I am trying to determine if the mod 90 of those angles are very close to zero.
For that, is there any other way than this code below?
ang1_01 = mod(abs(ang1_d), 90);
ang1_02 = mod(90-abs(ang1_d), 90);
ang2_01 = mod(abs(ang2_d), 90);
ang2_02 = mod(90-abs(ang2_d), 90);
%%%
if ang1_01<1e-3 || ang1_02<1e-3 || ang2_01<1e-3 || ang2_02<1e-3
disp('yes');
else
disp('no');
end

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

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

태그

제품


릴리스

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by