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

1 Ansicht (letzte 30 Tage)
Baha411
Baha411 am 8 Jul. 2019
Kommentiert: Baha411 am 8 Jul. 2019
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?

Antworten (1)

Steven Lord
Steven Lord am 8 Jul. 2019
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 Kommentar
Baha411
Baha411 am 8 Jul. 2019
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

Melden Sie sich an, um zu kommentieren.

Tags

Produkte


Version

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by