LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Unexpected Behavior with Matrix Multiplication

Solved!
Go to solution

I'm experiencing some strange results with the matrix multiplication VI.

 

Specifically, I'm trying to test the validity of a rotation matrix by checking that the inverse is equal to the transpose, ie. that R x R' = I. However, when I multiply a 3x3 matrix by its inverse, the result is a matrix with 1 on the diagonal and non-zero elsewhere. 

 

This is my first time doing linear algebra in LabVIEW, so I'm prepared to have made a foolish mistake, but I've attached a screenshot that seems pretty clear cut. Any ideas as to what's going on here?

0 Kudos
Message 1 of 8
(2,779 Views)

@Woodwings wrote:

I'm experiencing some strange results with the matrix multiplication VI.

 . However, when I multiply a 3x3 matrix by its inverse, the result is a matrix with 1 on the diagonal and non-zero elsewhere. 



Yes.  That is what it is supposed to do.  http://www.mathwords.com/i/inverse_of_a_matrix.htm   Yes R x R' = I

 

Multiplying a matrix by its inverse isn't the same thing as seeing if its inverse is equal to its transpose.  That is seeing if for matrix R that R(T) = R'   Where R(T) means transpose of R since this editor doesn't do superscripts.

0 Kudos
Message 2 of 8
(2,760 Views)

To expand slightly on RavensFan's excellent answer, a matrix of all 1's is its own Transpose, but has no inverse.

 

You do realize, I hope, that computers approximate numeric quantities.  If you have a matrix and take its inverse, it it highly likely that you will have elements of the inverse that cannot be exactly represented in 59 binary digits (a.k.a. "bits"), so when you use them in a multiplication/addition problem whose answer is theoretically 0, you might, and probably will, get some non-zero answer.

 

To see if a Matrix equals its Transpose, you only need to do a Matrix Transpose and a Compare if Equal, no computation to speak of.

 

Bob Schor

Message 3 of 8
(2,749 Views)
Solution
Accepted by topic author Woodwings

You might be confused because you are looking are not seeing the whole floating point number. For example, if you see 2.22 and think that's not right because it should be zero, try expanding the indicator and it might actually be 2.22045E-16 which is very close to 0. If you right click and go to display format, you can change how it is displayed.

Message 4 of 8
(2,738 Views)

This is exactly what happened, thank you. My off-axis values turned out to be eighteen orders of magnitude smaller than I first thought - not a problem at all. Thank you for the tip!

 

 

0 Kudos
Message 5 of 8
(2,692 Views)

@Bob_Schor wrote:

...

You do realize, I hope, that computers approximate numeric quantities.  If you have a matrix and take its inverse, it it highly likely that you will have elements of the inverse that cannot be exactly represented in 59 binary digits (a.k.a. "bits"), so when you use them in a multiplication/addition problem whose answer is theoretically 0, you might, and probably will, get some non-zero answer.

 

To see if a Matrix equals its Transpose, you only need to do a Matrix Transpose and a Compare if Equal, no computation to speak of.

 



As you correctly surmised, it turned out to be an approximation error. I saw values up to 6.2 off-axis, but didn't think to expand the indicator; if I had, I would have seen an E-18 at the end. 

And thank you, I was not aware of the Compare if Equal function.

0 Kudos
Message 6 of 8
(2,688 Views)


 wrote:

 

Yes.  That is what it is supposed to do.  http://www.mathwords.com/i/inverse_of_a_matrix.htm   Yes R x R' = I

 

Multiplying a matrix by its inverse isn't the same thing as seeing if its inverse is equal to its transpose.  That is seeing if for matrix R that R(T) = R'   Where R(T) means transpose of R since this editor doesn't do superscripts.


Thank you for the answer. It turned out that my mistake was not in the math but in the editor: I didn't expanding the indicator enough to see the full magnitude of the off-axis values - they were numerical errors on the order of -2E-16 or 6E-18, but I only saw the scary 6 at the start.

 

I now see I was not very explicit in my initial question. For the sake or leaving a clear record of my mistakes:

- A valid 3D rotation matrix will always have the properties that det(R) = 1, and R(T) = R'.

- To test the validity of a supposed rotation matrix, I therefore obtained R(T) and computed R x R(T). As you pointed out, R x R' = I by definition, so if I found that R x R(T) = I it would be safe to conclude that R(T) = R'.

- I found that the result of R x R(T) had large off-axis values, then tested R x R' and got different, but similarly large, non-zero values off-axis. This is where I made my mistake - the off axis values where in fact very small, but I misread them.

 

0 Kudos
Message 7 of 8
(2,680 Views)

My apologies -- I saw it the first time I read your post, but by the time I made my comment, I forgot you specified that R was a rotation matrix.  It is certainly simpler to compute the transpose than a matrix!

 

What's more fun than a rotation matrix?  (My answer -- a rotation vector -- 1/3 the number of components, no "redundancy", and interesting math properties).

 

Bob Schor

0 Kudos
Message 8 of 8
(2,664 Views)