From: "M. Edward (Ed) Borasky" Date: 2006-02-02T00:30:51+09:00 Subject: Re: Is this a floating point precision problem? I don't know what Ruby is doing here, but the R language gives a much different result for the matrix. Your input matrix: > m1 [,1] [,2] [,3] [1,] -0.01082270 -0.22493468 -0.9743137 [2,] 0.04682478 0.97318791 -0.2251949 [3,] -0.99884449 0.04805924 0.0000000 R's inverse, computed using the routine "ginv" > library(MASS) > m3<-ginv(m1) > m3 [,1] [,2] [,3] [1,] -0.01082270 0.04682478 -9.988445e-01 [2,] -0.22493468 0.97318791 4.805924e-02 [3,] -0.97431374 -0.22519489 6.223320e-17 Multiplication check: > m1%*%m3 [,1] [,2] [,3] [1,] 1.000000e+00 -1.509074e-16 -8.675039e-17 [2,] -1.865234e-16 1.000000e-00 -1.023683e-17 [3,] 6.958291e-17 -1.558541e-18 1.000000e+00 So ... either the Ruby matrix inverter is broken or you matrix is ill-conditioned enough that the Ruby matrix inverter can't handle it. I don't have a condition number checker handy, but I can do a singular value decomposition and look at the numerical rank. > svd(m1) $d [1] 1 1 1 $u [,1] [,2] [,3] [1,] -0.01082270 -0.22493468 -9.743137e-01 [2,] 0.04682478 0.97318791 -2.251949e-01 [3,] -0.99884449 0.04805924 6.223320e-17 $v [,1] [,2] [,3] [1,] 1 0 0 [2,] 0 1 0 [3,] 0 0 1 Hmmm ... no zero or small singular values ("$d") so ... looks off the top of my head like a nice rank 3 well conditioned matrix. So ... best have a look at the Ruby matrix inverter. Todd S. wrote: > I'm using the Matrix module (matrix.rb) to help place a vertex into > local coordinates and then back into world coordinates. Under certain > situations the transformation to and from local space corrupts the > data... > > This matrix... > -0.0108226964530337 -0.224934679233174 -0.974313737622412 > 0.0468247818757306 0.973187905351297 -0.225194894880513 > -0.998844486916645 0.0480592442327619 0.0 > > will invert to this... > 64.0 0.0 > -0.998844486916645 > 0.0 1.0 > 0.0480592442327619 > -0.974313737622412 -0.225194894880513 -2.40312135813741e-18 > > > starting with vertex: 0.015525, -0.28474399, 0.53221899 > multiplyng by the inverse matrix and then back again by the matrix > itself will not yield the same number as it should but instead > returns... 0.00555723611485535, -0.24161810434515, -0.4739174731596 > > So am I seeing strange behavior due to the extreamly small (e-18) number > in the matrix? > > If so, how can I set the precision so that I don't see this error? > > -- M. Edward (Ed) Borasky http://linuxcapacityplanning.com