# LabVIEW

cancel
Showing results for
Did you mean:

## Re: eigenvalues and vectors

plots.vi and maha_dist.vi are still missing,

also lots of broken wires in pca.vi

one thing i saw immediately .. it's mostly cosmetic, but if you want to have an array [0,1,2,...,n] you just use the 'i' in the for loop, that does exactly what you try to do with  +1 and shift register. to have your array start with 1 instead of 0, either have the +1 in the for loop, or use a "Array Subset" or "Split Array" starting at index 1.

If Tetris has taught me anything, it's errors pile up and accomplishments disappear.
Message 11 of 27
(824 Views)

Message 12 of 27
(819 Views)

Message 13 of 27
(807 Views)

## Re: eigenvalues and vectors

I ran your code "pca.vi".  I assume you know you didn't wire any of the outputs, so you might not know that the first computation (for "Normal") gives Error -20068, "Input parameters has at least one element that is Inf, NaN, DBL_MAX, or DBL_MIN".  The other two computations do give numbers, don't know what to make of them ...

Since you seem to be worried about whether or not you are able to compute Eigenvalues and Eigenvectors from your data, why don't you create a small (10 x 10?  3 x 3?) set of data whose EigenThings you know and see if LabVIEW (and/or Matlab) gives you the expected results.

Bob Schor

Message 14 of 27
(792 Views)

## Re: eigenvalues and vectors

Hmm.  I decided to try what I suggested (take known data and see if LabVIEW computes correctly) myself.  I've not played with these kinds of data analysis functions in LabVIEW (I've not done much with LabVIEW's Matrix types), so it was a "learning experience".

Here's what I did:

• Generated 5000 points with X, Y normally distributed, N(0, 1).
• Scaled X by 4.  Rotated the sample by 30°.
• The largest Eigenvalue should be the variance along the direction of maximum spread, and the corresponding Eigenvector should point in this direction.  This suggests that the Eigenvalues should be 16 (variance of N(0, 4)) and 1, with the Eigenvectors pointing at 30° and 120°.
• Computed Covariance Matrix had main diagonals of 11.8 and 4.6, with off-diagonals of 6.25.
• The computed Eigenvalues were 15.4 and 0.99.  The larger Eigenvector had components of 0.865 and 0.502, reasonably close to cos(30°) and sin(30°).

My conclusion is that LabVIEW's computation is likely to be mathematically correct.  Whether or not you are doing "the math correctly" or not, I'm not sure.  I will tell you that my code has no explicit square-root function in it.  If I had to guess, I'd guess you are not correctly computing the covariance matrix.  [Could you have gotten "correlation" and "covariance" mixed up?  Is that where the square root comes in?].

Bob Schor

Message 15 of 27
(784 Views)

## Re: eigenvalues and vectors

Actually, I have named it cov_mat.vi, but it is actually a correlation matrix.

Message 16 of 27
(791 Views)

## Re: eigenvalues and vectors

@canzie07 wrote:

Actually, I have named it cov_mat.vi, but it is actually a correlation matrix.

Ah, so you deliberately did the wrong math, and got the wrong result.  Problem solved!

Bob Schor

Message 17 of 27
(782 Views)

## Re: eigenvalues and vectors

No. I have to calculate the correlation matrix but by mistake named it cov_mat.vi which you understood as covariance. With this VI, I have got the correct result as gotten by Matlab software. But eigenvalue and vector function used from both the software is giving the different result.

That is my doubt.

Message 18 of 27
(778 Views)

## Re: eigenvalues and vectors

Hi canzie,

both the software is giving the different result.

So after several days I ask again: how much do the results differ?

Best regards,
GerdW

using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 19 of 27
(775 Views)

## Re: eigenvalues and vectors

I haven't calculated the difference but the values are not the same everytime I run the program from both the software.

Message 20 of 27
(764 Views)