LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Something is up with matrix math

Solved!
Go to solution

I am multiplying two matrix against each other. I am getting strange results and I am hoping that someone can tell me why. When I multiply Sigma_reg and Sigma_inv i get this result:

aeastet_0-1761585666405.png

 

When I probe I do see all of the decimals. but the result is 1 with no following decimals:

aeastet_0-1761585974793.png

 

 

The strange thing is that I when I just multiply these two numbers I get this value. This is what I expect to see when index 0 is multiplied by index zero:

aeastet_1-1761585730853.png

I am missing my decimals. I always get a one. Any thoughts?

 

Tim
GHSP
0 Kudos
Message 1 of 25
(567 Views)

I would start with attaching your code containing your shown default values.

 

(What datatypes are there  (2D array, matrix?) and what functions are you using?)

Message 2 of 25
(558 Views)

Why does Sigma_inv show '-0' in the bottom row? Is there actually data there that's not being fully shown?

 

Works fine for me:

JePe1_0-1761586377030.png

JePe1_1-1761586391171.png

 

 

0 Kudos
Message 3 of 25
(557 Views)

Here is my VI

Tim
GHSP
0 Kudos
Message 4 of 25
(547 Views)

Here is a simple version

Tim
GHSP
0 Kudos
Message 5 of 25
(520 Views)

First of all, you need to be careful. An element-by-element multiplication (your loop stack!) of two matrices is only the same as AxB if both matrices are diagonal.

The inverse of a diagonal matrix is a diagonal matrix with the diagonal containing the inverse of each original element.

 

 

In general, a matrix inverse is  a complicated process, and numerical instabilities can sneak in. If you know your matrix is diagonal, do as follows:

 

altenbach_0-1761588257692.png

 

While A-B is zero her, that -0 in your case is suspicious.

 

I am pretty sure that LabVIEW is using well known libraries (e.g. MKL) for matrix inversion, so there is really nothing they can do.

 

 

 

Message 6 of 25
(512 Views)

I did try multiplying the two using multiply matrix and got the same result. I only added the for loop after I got an unexpected result. I will try try your method. The issue is that it seems that the numbers are coming out other than double. Did you look at my simple version when I used number to multiply and the results of index 0 for both arrays to get the answer. There is something wrong with that.

Tim
GHSP
0 Kudos
Message 7 of 25
(500 Views)

OK I built it your way and I am still not seeing the decimals from the multiply. Am I doing something wrong?

Tim
GHSP
0 Kudos
Message 8 of 25
(495 Views)

The example image in your first post where you're getting 1.000000778040 is because you're missing a lot of the decimals from the true values. LabVIEW truncates to 6 sig figs by default. Crank the number of sig figs way up and you can see the true values do indeed equal 1.0:

 

JePe1_0-1761589704640.png

0 Kudos
Message 9 of 25
(487 Views)

In the x*y I never see my decimals. You are not seeing them either. Look at the difference between the first x*y and x*y 2. Why are they not the same?

 

Tim
GHSP
0 Kudos
Message 10 of 25
(481 Views)