- the approach is wrong
- your code has plenty of bugs*
- you need to learn how to debug
- you need to pratice MATLAB onramp
Find angle of rotation matrix in MATLAB
10 次查看(过去 30 天)
显示 更早的评论
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
0 个评论
回答(2 个)
Bruno Luong
2020-11-22
编辑:Bruno Luong
2020-11-22
Yes
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
0 个评论
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))
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Time-Frequency Analysis 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!