【问题标题】:How to access matrix elements in C#如何在 C# 中访问矩阵元素
【发布时间】:2022-10-24 08:25:41
【问题描述】:

使用 MathNet.Numerics.LinearAlgebra.Complex 创建具有复杂条目的 3 x 3 密集矩阵。有没有办法直接访问条目以进行进一步的非矩阵计算?我已经能够从矩阵生成一个数组,但首先必须转置矩阵,然后生成数组,否则条目不会对齐。

因此,我在徘徊如何直接访问矩阵条目。

谷歌搜索我的查询提出了一些建议,但无法得到明确的答案。

【问题讨论】:

  • 你读过documentation吗?
  • 请出示您的代码
  • 我阅读了文档(感谢链接 - 不知道)但有一个查询。见下文。

标签: c# matrix


【解决方案1】:

我已阅读文档并尝试使用它,但遇到错误:

我的(基本)理解是引用命名空间中的所有方法都可以在我的代码中使用,即在调用方法时不需要为命名空间添加前缀。

我的代码如下:

using static System.Math;
using System.Numerics;
using MathNet.Numerics.LinearAlgebra.Complex;
using MathNet.Numerics.Data.Text;

namespace TLCalcs
{
   public class TLCalcsBase 
   {
       private DenseMatrix MatrixA;
       private DenseMatrix MatrixB;
       private DenseMatrix MatrixF;
       private Complex Z1;    

       // method here where MatrixB and MatrixF calculated

       var MatrixA = MatrixB * MatrixF;
       Complex Z1 = MatrixA.[0, 0]; // I get an CS1001 "identifier required" 
                                    // here at the dot between the A of MatrixA 
                                    // and the opening square bracket. I assume 
                                    // a reference problem but the Math.Net 
                                    // literature is not great on this or I am 
                                    // just confused 
    }

  }

提前感谢您的任何帮助。

【讨论】:

  • 请使用您问题上的编辑链接添加其他信息。 Post Answer 按钮应仅用于问题的完整答案。 - From Review
猜你喜欢
  • 1970-01-01
  • 2013-02-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-05-12
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多