Function returns different outputs with same inputs
Show older comments
Hello everyone,
Context (not relevant for Problem):
For a school project, im playing around with "rotation matrix" and "Quaternions", i already calculated the Quaternions with a different methode, and now i want to compare the results i get from rotationsmatrix2quaterionen(numeric_result) with the ones i calculated earlier. The function seems to work, rr is nearly zero (not exactly because of numeric imprecision)
Problem:
I don't understand why 'rr' and 'gh' give me different results. The calculation should be the same both times, only that one time at first i write the output in a seperate array.
I assume i made some stupid mistake, but i can't find it.
numeric_result = [
0.8138 -0.4063 0.4155 10.0000;
0.4698 0.8808 -0.0590 12.5000;
-0.3420 0.2432 0.9077 64.0000;
0 0 0 1.0000]
e0 = 0.9490
e1 = 0.0796
e2 = 0.1996
e3 = 0.2308
[e0_, e1_, e2_, e3_] = rotationsmatrix2quaterionen(numeric_result)
rr=[e0, e1, e2, e3]-[e0_, e1_, e2_, e3_]
% Output:
% rr = 1×4
% 1.0e-04 *
%
% 0.1370 -0.1127 0.4496 0.0109
gh=[e0, e1, e2, e3]-rotationsmatrix2quaterionen(numeric_result)
% Output:
% gh = 1×4
% 0.0000 -0.8694 -0.7494 -0.7182
function [e0, e1, e2, e3] = rotationsmatrix2quaterionen(RotMat)
% e = e0 + e1*i + e2*j + e3*k
R=RotMat;
e0 = 0.5*sqrt(1+R(1,1)+R(2,2)+R(3,3));
e1 = (R(3,2)-R(2,3)) / (4*e0);
e2 = (R(1,3)-R(3,1)) / (4*e0);
e3 = (R(2,1)-R(1,2)) / (4*e0);
end
Accepted Answer
More Answers (0)
Categories
Find more on Call Python from MATLAB in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!