LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Something is up with matrix math

Solved!
Go to solution
Solution
Accepted by topic author aeastet

there are no digits, the difference is between -0 and +0.

 

 

Message 11 of 25
(379 Views)

When I am multiplying the matrix I should get a matrix that includes the right values. When I do the multiply I see this:

aeastet_1-1761590807240.png

 

This multiply is wrong using matrix math:

aeastet_0-1761590780806.png

 

The matrix should look like this:

aeastet_2-1761590928138.png

Why to I not see the significant values when doing matrix math? Please look at these closely. 

When I do the subtraction I should get this result not zero:

aeastet_3-1761591010335.png

 

 

Tim
GHSP
0 Kudos
Message 12 of 25
(369 Views)
Solution
Accepted by topic author aeastet

So why are you even use matrix operations if all you really need are 1D array operation on the diagonal?

 

altenbach_0-1761600847960.png

 

 

 

Message 13 of 25
(362 Views)

In the picture I posted I was showing the full values (left) and the truncated values (right), to show the difference in the math. Apologies if that wasn't clear.

 

Attached is the Simple example with everything expanded to 16 digits. You can see that the matrix data has all the extra digits as well, and once enough digits are copied over the x*y and x*y2 indicators do match.

 

JePe1_0-1761592246469.png

 

I still don't understand the -0 row; must be noise from the underlying library, but it doesn't see to throw off the expected result: the matrix times its inverse is all 1's.

Message 14 of 25
(350 Views)

LabVIEW is the only place where I am not seeing this as a result of matrix multiplying Sigma_reg and Sigma_ inv. For LabVIEW I only get 1.000000000000000000000. Noone is answering this question.

 

aeastet_0-1761595431299.png

 

The LabVIEW result:

aeastet_0-1761595733629.png


How can I make my question more clear?

 

 

Tim
GHSP
0 Kudos
Message 15 of 25
(326 Views)
Solution
Accepted by topic author aeastet

The matrix math is returning correct values
For A^-1 * A, we expect to get a diagonal matrix, and the matrix product returned by A x B.vi is:

dsbNI_0-1761594812708.png


This matrix includes all the right values as JePe1 has shown.

When you do the multiplication of elements, I think you may be copying "0.00598466" into Numeric and "167.094" into Numeric 2. The product:
0.00598466 * 167.094 = 1.000000778040
This product shows the errors you get when rounding intermediate results.

If you were to include the full (DBL) precision of the elements, you would instead see the following:

0.005984663470026351 * 167.0937731099518 = 1.000000000000000
This product is correct. It is not missing significant digits.

You are expecting to see a difference matrix match that of Mathematica. Please be wary when trying to compare floating point numbers exactly. It looks like several of the difference matrix elements are limited by machine epsilon. That doesn't make the right answer wrong, but it may mean that you need to apply a tolerance when comparing numbers. Integers can be compared exactly, but floating-point numbers must be compared to within tolerance (even more so when comparing across different computer architectures and software implementations). If you copy the full precision values to Mathematica, I bet you will see better agreement on numeric and matrix products.

Does Mathematica allow you to view more significant digits? Yes, you can use NumberForm function to specify the number of significant digits displayed.

 

Doug
Enthusiast for LabVIEW, DAQmx, and Sound and Vibration
Message 16 of 25
(325 Views)

Yep, Doug from NI gave (what I believe is) the correct answer.  If you multiply 0.00598466 by 167.094 and display it in an "ordinary" Dbl Indicator, you will (probably) get the answer "1".  But now change the Display Style to show, say, 15 significant digits, and you will get something like "0.999999999974", or "not quite".  The more manipulation you do with this "not quite right" quantity, the more chances there are for this "small difference" to grow.  One easy way to see this is to take the Product of the Numeric and its reciprocal and pass it through the "Decrement" function -- you should get 0, but you'll instead get (at least on my PC) -2.56466E-11 (to 6 significant digits, more are present but the display format is only showing 6 digits of precision).

 

Bob Schor

0 Kudos
Message 17 of 25
(309 Views)

@aeastet wrote:

Here is a simple version


I'll answer your question specifically- the posters above are correct. Your issue is a copy/paste error.

 

Simple steps to fix your example VI:

 

1. Right click an element of Sigma_inv, select Display format, and set "Digits" to 15. Expand the control to make room for the new digits.

2. Do the same for Sigma_reg.

3. Copy/paste element 0,0 from Sigma_reg and Sigma_inv into Numeric and Numeric 2. Rerun your VI. Now, x*y 2 is exactly 1, even though Numeric and Numeric 2 didn't visibly change.

 

The problem is that copy/pasting from the indicator copies the text, not the value. So, if you have only 6 digits displayed when you copy, you only get 6 digits in the clipboard. Your error shows up at the 7th place in your original code, and you're only getting 6 digits of precision from your copy/paste.

 

For bonus points, after doing the above- copy the value from "Numeric 2" and paste it back again. Rerun, and you'll see the result changes. 

0 Kudos
Message 18 of 25
(297 Views)

I am showing 20 digits. It is not a display issue. I have been doing this a really long time. I am not going to get caught on something that simple. Did anyone actually look at what I am doing in my code? 

 

 

Tim
GHSP
0 Kudos
Message 19 of 25
(250 Views)

What version of LabVIEW are you using? Is the data source of the original A matrix the same for Mathematica and for LabVIEW?

Doug
Enthusiast for LabVIEW, DAQmx, and Sound and Vibration
0 Kudos
Message 20 of 25
(243 Views)