- 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
11 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
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 Commenti
Risposte (2)
Bruno Luong
il 22 Nov 2020
Modificato: Bruno Luong
il 22 Nov 2020
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 Commenti
Asad (Mehrzad) Khoddam
il 22 Nov 2020
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 Commenti
Vedere anche
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!