3

I have rotation matrix which is not orthogonal. Whats wrong. I can't get it. Exterior=[-6.6861,12.6118,-8.0660,[-0.4467,-0.3168,0.2380]*pi/180];%# deg 2 rad %#data

ax=Exterior(4);
by=Exterior(5);
cz=Exterior(6);
%#Rotation in X

 Rx = [1  0        0
        0  cos(ax)  -sin(ax)
        0  sin(ax)  cos(ax)];


%#Rotation in Y    
Ry = [cos(by)  0  sin(by)
        0        1  0
        -sin(by) 0  cos(by)];


%#Rotation in Z        
Rz = [cos(cz) -sin(cz) 0
        sin(cz) cos(cz)  0
        0       0        1];
R=Rx*Ry*Rz;

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% R =

  0.99998   -0.0041538   -0.0055292
0.0041969      0.99996    0.0077962
0.0054966   -0.0078192      0.99995

Orthogonality check

Inv(R)-R'=

 2.2204e-016  2.6021e-018  8.6736e-019
            0  1.1102e-016 -1.7347e-018
 -2.6021e-018  3.4694e-018  2.2204e-016

R*R'=

 2.2204e-016  2.6021e-018  8.6736e-019
            0  1.1102e-016 -1.7347e-018
 -2.6021e-018  3.4694e-018  2.2204e-016

Why there is different signs.???????

Any mistake??

Phonon
  • 12,549
  • 13
  • 64
  • 114
Shahgee
  • 3,303
  • 8
  • 49
  • 81

2 Answers2

11

Looks like the numbers in your orthogonality check are just due to rounding errors... They're really quite tiny.

There is an error in the question, pointed out by @ChisA. The OP pasted the same matrix for inv(R)-R' and R*R'

If we reconstruct the input file:

Exterior = [-6.681,12.6118,-8.0660,[-0.4467,-03168,0.2380]*pi/180]

ax = Exterior(4)
by = Exterior(5)
cz = Exterior(6)

Rx = [1 0 0 ; 0 cos(ax) -sin(ax) ; 0 sin(ax) cos(ax)]
Ry = [cos(by) 0 sin(by) ; 0 1 0 ;  -sin(by) 0 cos(by)]
Rz = [cos(cz) -sin(cz) 0 ; sin(cz) cos(cz) 0 ; 0 0 1]

R = Rx*Ry*Rz

inv(R)-R'

R*R'

And run in through Octave (I don't have MATLAB):

Exterior =

  -6.6810e+00   1.2612e+01  -8.0660e+00  -7.7964e-03  -5.5292e+01   4.1539e-03

ax = -0.0077964
by = -55.292
cz =  0.0041539
Rx =

   1.00000   0.00000   0.00000
   0.00000   0.99997   0.00780
   0.00000  -0.00780   0.99997

Ry =

   0.30902   0.00000   0.95106
   0.00000   1.00000   0.00000
  -0.95106   0.00000   0.30902

Rz =

   0.99999  -0.00415   0.00000
   0.00415   0.99999   0.00000
   0.00000   0.00000   1.00000

R =

   0.3090143  -0.0012836   0.9510565
  -0.0032609   0.9999918   0.0024092
  -0.9510518  -0.0038458   0.3090076

ans =

  -5.5511e-17   1.3010e-18   1.1102e-16
   2.1684e-19   0.0000e+00  -4.3368e-19
  -1.1102e-16  -4.3368e-19  -5.5511e-17

ans =

   1.0000e+00  -1.9651e-19  -4.6621e-18
  -1.9651e-19   1.0000e+00   8.4296e-19
  -4.6621e-18   8.4296e-19   1.0000e+00

Notice the R*R' is very close to I and inv(R)-R' is very close to 0. Notice also that I get different small values than the OP. Because I am using a different piece of software the rounding errors will be different. So you should never rely on an exact comparison between two floating point numbers. You always should include some tolerance.

I hope this makes things a little clearer. See the comment by @gnovice below for links to more detailed information about rounding errors.

idz
  • 12,825
  • 1
  • 29
  • 40
  • But, I think, they must have same sign. – Shahgee May 18 '11 at 09:44
  • 2
    I don't know of any reason why they would have the same sign. – idz May 18 '11 at 10:01
  • 4
    @shahbaba: When working with [double precision](http://en.wikipedia.org/wiki/Double_precision_floating-point_format) numbers, errors on the order of the sixteenth significant digit are definitely floating-point round-off errors, and these can occur in either direction (positive or negative). For more information, check out [this related question](http://stackoverflow.com/q/686439/52738), [this paper](http://download.oracle.com/docs/cd/E19957-01/806-3568/ncg_goldberg.html), and [this MATLAB documentation](http://www.mathworks.com/help/techdoc/ref/eps.html). – gnovice May 18 '11 at 14:10
1

I don't understand why R*R' should be nearly zero. It should be the 3x3 identity matrix.

You might have a copy and paste error on your original question.

Chris A.
  • 6,817
  • 2
  • 25
  • 43
  • You're absolutely correct. I was so focused on the rounding error I did not even notice that. I will update it with output and that information. You have a keen eye! (+1) – idz May 18 '11 at 21:59