MATLAB solve() can't solve trigonometric matrix for specific values

Viewed 114

I'm experiencing something very strange in MATLAB which I can't figure out.

I have 2 sets of coordinates of a body for which I want to find the Euler angles. I set up the rotation matrix R and the symbolic Cardan angles matrix R_cardan to solve for the angles. For the first set I can simply do solve(R==R_cardan) but when I use the second set it doesn't work. The solution returned is empty.

What could be causing this? Here is test code.

clc;clear;close all;

%% For some reason R2 does not want to give a solution
% Find rotation matrix to transform from origin to local reference frame
ex = [ 0.768  0.024 0.640].';
ey = [-0.424  0.768 0.480].';
ez = [-0.480 -0.640 0.600].';

ex2 = [ 0.612372  0.353553 -0.707107].';
ey2 = [0.280330  0.739199 0.612372].';
ez2 = [0.739199 -0.573223 0.353553].';

R = eye(3)*[ex ey ez]
R2 = eye(3)*[ex2 ey2 ez2]
% Symbolic variables
syms beta alpha gamma

% Set up rotatin matrices
R_alpha = [cos(alpha) -sin(alpha) 0; sin(alpha) cos(alpha) 0; 0 0 1]
R_beta = [cos(beta) 0 sin(beta); 0 1 0; -sin(beta) 0 cos(beta)]
R_gamma  = [1 0 0; 0 cos(gamma) -sin(gamma); 0 sin(gamma) cos(gamma)]

% Find symbolic rotation matrix
R_cardan = R_alpha*R_beta*R_gamma

[alpha, beta, gamma] = find_angles(R,R_cardan)
[alpha, beta, gamma] = find_angles(R2,R_cardan) %fails because solution is empty

function [alpha, beta, gamma] = find_angles(R,R_cardan)

% Solve for the angles
sol = solve(R == R_cardan);
alpha = double(sol.alpha(1));
beta = double(sol.beta(1));
gamma = double(sol.gamma(1));

end

My current solution is to just manually calculate the angles which is fine, but I'm interested in what is wrong with my method above.

1 Answers
Related