Find angle of rotation matrix in MATLAB

21 ビュー (過去 30 日間)
Kevin Maresca
Kevin Maresca 2020 年 11 月 22 日
回答済み: Asad (Mehrzad) Khoddam 2020 年 11 月 22 日
Hey everyone,
I'll preface by letting you know that I am a novice at MATLAB so I'm sure the code will need plenty of help.
I'd like to find the angle at which a matrix needs to be rotated about the y-axis to reach given coordinates. 'I' is the given matrix, I'd like to rotate it by 't' to get 'Iwant'. I'd also like to print out which value of 't' got the desired matrix.
As far as I can tell, the while loop runs forever. What am I doing wrong? Is this a completely wrong approach?
Thank you.
I = [11755 0 4821; 0 15000 0; 4821 0 23245]
Iwant = [10000 0 0; 0 15000 0; 0 0 25000]
t = 0;
while t < 3.14
R = [cos(t) 0 sin(t); 0 1 0; -sin(t) 0 cos(t)];
I1 = R*I*R';
if I1 == Iwant
fprintf(t)
break
t = t+0.2;
end
end

回答 (2 件)

Bruno Luong
Bruno Luong 2020 年 11 月 22 日
編集済み: Bruno Luong 2020 年 11 月 22 日
Yes
  • the approach is wrong
  • your code has plenty of bugs*
  • you need to learn how to debug
  • you need to pratice MATLAB onramp
On (*) is fixed
I = [11755 0 4821; 0 15000 0; 4821 0 23245]
Iwant = [10000 0 0; 0 15000 0; 0 0 25000]
t = 0;
while t < 2*pi
R = [cos(t) 0 sin(t); 0 1 0; -sin(t) 0 cos(t)];
I1 = R*I*R';
if norm(I1-Iwant,'Inf') < 10
fprintf('t=%g\n', t)
break
end
t = t+1e-3;
end

Asad (Mehrzad) Khoddam
Asad (Mehrzad) Khoddam 2020 年 11 月 22 日
I = [11755 0 4821; 0 15000 0; 4821 0 23245];
Iwant = [10000 0 0; 0 15000 0; 0 0 25000];
t = 0;
i=1;
tList = 0:.02:3.14;
dList = NaN(size(tList));
for t = tList
R = [cos(t) 0 sin(t); 0 1 0; -sin(t) 0 cos(t)];
I1 = R*I*R';
d = I1-Iwant;
dList(i)= sum(d(:).^2);
i = i+1;
end
[~, index] = min(abs(dList));
disp(tList(index))

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by