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开发者_JAVA技巧 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!
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:
Notice the
out
keyword next to the d and v parameters. You need to add the out keyword to the call to Eigen.The code expects a Matrix as the first argument, while you are sending an element. Thus,
MatrixName[n, n]
needs to change toMatrixName
.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);
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);
精彩评论