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

半世苍凉 提交于 2019-12-30 07:06:07

问题


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!


回答1:


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



回答2:


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



来源:https://stackoverflow.com/questions/4400203/calculating-eigenvectors-in-c-sharp-using-advanced-matrix-library-in-c-net

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!