使用 C# 中的高级矩阵库计算 C# 中的特征向量。网
好的,我正在使用以下库: http://www.codeproject.com/KB /recipes/AdvancedMatrixLibrary.aspx
我希望计算我拥有的某些矩阵的特征向量。我不知道如何制定代码。
到目前为止,我已经尝试过:
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);
但是它说最佳重载方法匹配有一些无效参数。我知道该库可以工作,但我只是不知道如何编写我的 C# 代码。
任何帮助都会很棒!
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!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
查看库,Eigen 方法的签名如下所示:
有一些错误:
注意 d 和 v 参数旁边的
out
关键字。您需要将 out 关键字添加到对 Eigen 的调用中。当您发送元素时,代码需要一个 Matrix 作为第一个参数。因此,
MatrixName[n, n]
需要更改为MatrixName
。您不需要实例化向量和值矩阵,因为 Eigen 方法会为您执行此操作,并且将通过 out 关键字返回您发送的两个参数中的值。还需要注意的一件事是,您将收到如下输出:
值将是一个 [n+1,1] 矩阵
向量将是一个 [n+1,n+1] 矩阵
而不是您在初始代码中所期望的 Matrix(n, 0) 。
代码如下所示:
Looking at the Library, the signature of the Eigen method looks like this:
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:
您的代码应如下所示:
C#
out
关键字意味着方法Eigen
将为您创建对象,因此您不应该执行此new Matrix(n, 0) ;
You code should look like this:
C#
out
keyword means that methodEigen
will create object for you, so you should not do thisnew Matrix(n, 0);