Question

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!

Was it helpful?

Solution

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);

OTHER TIPS

You code should look like this:

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

Matrix.Eigen(MatrixName, out values, out vector);

C# out keyword means that method Eigen will create object for you, so you should not do this new Matrix(n, 0);

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top