0
votes

I want to find the rotation matrix between two vectors.

[0;0;1] = R * [0.0023;0.0019;0.9899]

How do I find the 3*3 rotation matrix?

2
@ZizyArcher What do you mean? Both vectors are 3 elements... - Wolfie
@ZizyArcher I'd advise using the words "magnitude" or "norm" when talking about vector lengths in a programming context, otherwise your comments can easily be confusing. The length of a vector here would usually be an attribute of the array's size; in MATLAB the length of a vector is the number of elements. Note also that the example given by the OP could be subject to rounding (1 is pretty close to 0.98), so it would be more useful to note something like "be aware that the magnitude of the vectors is different, if this isn't due to rounding then the rotation matrix is ill-defined". - Wolfie
@Wolfie I see how my poor choice of words led to confusion. I can't seem to edit my comments anymore unfortunately, so I deleted them. Though difference of 0.98 vs 1 is large enough it cannot be due to rounding unless there were many steps. The only possibility is that the last element is actually 0.9999. - Zizy Archer
Also related and a solution to get the actual rotation matrix: math.stackexchange.com/questions/180418/… - Zizy Archer

2 Answers

2
votes

This is a simple rearrangement

% [0;0;1] = R * [0.0023;0.0019;0.9899];
% So ...
% [0;0;1] / [0.0023;0.0019;0.9899] = R
% This is a valid MATLAB command

R = [0;0;1] / [0.0023;0.0019;0.9899];
>> R =
    [ 0    0    0
      0    0    0
      0    0    1.0102 ]

We can validate this result

R * [0.0023;0.0019;0.9899]
>> ans =
    [0; 0; 1]
0
votes

Your problem can be defined as a linear equation, say,

y = mx

where, y and x are matrices. Find m.

Solution:

m = x\y or m = mldivide(x,y)

Notice the backslash. It is not a forward slash / as Wolfie mentioned in his answer. For details see https://www.mathworks.com/help/matlab/ref/mldivide.html

Additional Details:

If x is a singular matrix, use pinv. See https://www.mathworks.com/help/matlab/ref/pinv.html for reference.