使用 C# 中的高级矩阵库计算 C# 中的特征向量。网

发布于 2024-10-07 11:07:31 字数 498 浏览 0 评论 0原文

好的,我正在使用以下库: 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

所有深爱都是秘密 2024-10-14 11:07:31

查看库,Eigen 方法的签名如下所示:

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

有一些错误:

  1. 注意 d 和 v 参数旁边的 out 关键字。您需要将 out 关键字添加到对 Eigen 的调用中。

  2. 当您发送元素时,代码需要一个 Matrix 作为第一个参数。因此,MatrixName[n, n]需要更改为MatrixName

  3. 您不需要实例化向量和值矩阵,因为 Eigen 方法会为您执行此操作,并且将通过 out 关键字返回您发送的两个参数中的值。还需要注意的一件事是,您将收到如下输出:

    • 值将是一个 [n+1,1] 矩阵

    • 向量将是一个 [n+1,n+1] 矩阵

而不是您在初始代码中所期望的 Matrix(n, 0) 。

代码如下所示:

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

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

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);
狠疯拽 2024-10-14 11:07:31

您的代码应如下所示:

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

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

C# out 关键字意味着方法 Eigen 将为您创建对象,因此您不应该执行此 new Matrix(n, 0) ;

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文