MATLAB Answers

Find angle of rotation matrix in MATLAB

조회 수: 14(최근 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))

제품

Community Treasure Hunt

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

Start Hunting!

Translated by