# made a code in matlab which includes functions like rand, eig, cov and many more. I want to convert the same to HDL, but cannot due to those functions.

8 views (last 30 days)
Sukhmani Kaur Thethi on 15 Sep 2016
Commented: Walter Roberson on 17 Sep 2016
hello, Can anyone tell me how to find out eigen values and eigen vectors of large matrix of order 10x10 or more, without using the function 'eig', so that it becomes convertible to HDL using HDL converter?

John D'Errico on 16 Sep 2016
Edited: John D'Errico on 16 Sep 2016
10x10 is not a large problem. :) In fact, 10 is pretty small. That does not mean it is trivial for any general matrix, and the simplest solution may depend on some characteristics of your matrix. Is it real and symmetric for example? Is it positive definite?
You can reduce an eigenvalue computation into one of finding the roots of a polynomial. Or you can use the power method on some matrices. (Be careful if an eigenvalue has degree greater than 1, etc.)
And tools like cov are easily written as not much more than subtracting a mean followed by a matrix multiplication.
Sukhmani Kaur Thethi on 16 Sep 2016
the matrix is a random matrix, so no particular characteristic fits into the scenario?

Tim McBrayer on 16 Sep 2016
You will need to decompose the computation of eigenvectors to more basic operations and organize these in a way that meets your hardware requirements for size and speed. There are a huge number of ways to accomplish this, which is one reason why eig() is not directly supported by HDL Coder.
Sukhmani Kaur Thethi on 16 Sep 2016
Sir, can you please suggest me any one way to accomplish that?

Walter Roberson on 17 Sep 2016
It is possible to generate the characteristic polynomial of the 10 x 10 matrix in a symbolic form. It would be quite large, but it is possible.
You would then be left trying to find the roots of that 10 degree polynomial. There is no algebraic solution for finding the roots of a general polynomial of degree 5 or higher. You could resort to using roots() on that long polynomial, but roots() invokes eig...
So, you are pretty much going to need to work numerically using some algorithm or other. https://www.mathworks.com/moler/eigs.pdf
Sukhmani Kaur Thethi on 17 Sep 2016
sir, actually this is the minimum matrix dimension. I need to work on bigger matrix dimensions. will the QR method work then? will I get all the eigen values and eigen vectors using that method?
Walter Roberson on 17 Sep 2016
It looks to me as if SVD might make more sense then QR for you.
However, an important question here is whether those random matrices you are producing are symmetric or not. If they are not, then complex eigenvalues are to be expected, which complicates the algorithm and the generated HDL.
Checking, I see that code generation is supported for eig(), at least at the MATLAB level.
What is it that you are doing, that eigenvalues of random matrices makes sense?

### Categories

Find more on Speed and Area Optimization in Help Center and File Exchange

### Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!