Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Calculating EigenVectors in C# using Advanced Matrix Library in C#. NET

Ok guys, I am using the following library: http://www.codeproject.com/KB/recipes/AdvancedMatrixLibrary.aspx

And I wish to calculate the eigenvectors of certain matrices I have. I do not know how to formulate the code.

So far I have attempted:

Matrix MatrixName = new Matrix(n, n);
Matrix vector = new Matrix(n, 0);
Matrix values = new Matrix(n, 0);

Matrix.Eigen(MatrixName[n, n], values, vector);

However it says that the best overloaded method match has some invalid arguments. I know the library works but I just do not know how to formulate my c# code.

Any help would be fantastic!

like image 288
RHodgett Avatar asked Dec 21 '22 20:12

RHodgett


1 Answers

Looking at the Library, the signature of the Eigen method looks like this:

public static void Eigen(Matrix Mat, out Matrix d,out Matrix v)

There are a few errors:

  1. Notice the out keyword next to the d and v parameters. You need to add the out keyword to the call to Eigen.

  2. The code expects a Matrix as the first argument, while you are sending an element. Thus, MatrixName[n, n] needs to change to MatrixName.

  3. You don't need to instantiate the vector and values Matrices, since the Eigen method does this for you and will return the values in the two arguments you send thanks to the out keyword. One thing to note as well is that you will receive the output as follows:

    • values will be a [n+1,1] Matrix

    • vector will be a [n+1,n+1] Matrix

Not as Matrix(n, 0) as you expect from your initial code.

The code will look like this:

Matrix MatrixName = new Matrix(n, n);
Matrix vector;
Matrix values;

Matrix.Eigen(MatrixName, out values, out vector);
like image 120
Waleed Al-Balooshi Avatar answered May 01 '23 02:05

Waleed Al-Balooshi