How can I find eigenvectors of a matrix in Simulink?
Show older comments
Hi,
I need to go from Euler angles to one vector describing the axis of rotation and the magnitude of rotation about that axis (angle in radians). To solve this I need to find the real eigenvector of the rotation matrix (3 by 3 matrix). The angle is the trace of the matrix. ( Rotation Matrix)
I am currently using this code which I have put in a Matlab Function Block in Simulink:
function rot = fcn(R)
% Takes in rotation matrix (R) and returns one vector where the three first elements
% denote the axis of rotation and the last element is the angle of rotation
% about the axis.
rot = zeros(4,1);
[V,~] = eig (R);
for i = 1:3
if isreal(V(:,i))
rot(1:3,1) = V(:,i);
rot(4,1) = trace(R);
end
end
end
When running the Simulink model, the output is always
rot = [0;0;0;0]
The transformation matrix changes all the time, but at one point it is
R =
0.9998 0.0002 -0.0181
-0.0005 0.9998 -0.0189
0.0181 0.0189 0.9997
Running the code through the command window gives
rot =
0.7232
-0.6905
-0.0130
2.9993
which is the correct eigenvector.
I looked at this page: Functions and Objects Supported for C and C++ Code Generation — Alphabetical List. It only seems like the difference for the eig function should be the normalization of the eigenvectors.
Thank you, Erlend
Accepted Answer
More Answers (0)
Categories
Find more on Simulink in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!