如何使用 Math.Net 连接矩阵。如何使用 Math.Net 调用特定的行或列?

Posted

技术标签:

【中文标题】如何使用 Math.Net 连接矩阵。如何使用 Math.Net 调用特定的行或列?【英文标题】:How to concatenate matrices with Math.Net. How to call for a particular row or column with Math.Net? 【发布时间】:2022-01-16 10:20:15 【问题描述】:

如何调用特定的行或列?

假设我有这个 8 x 6 矩阵并且只想调用一行或一列并将其分配给一个新变量,如何在 c# 中解决这个问题。

这是一段代码:

//The Eight Solutions as one matrix
            Matrix<double> eightsols = DenseMatrix.OfArray(new double[,]
            
            theta1_1 * Degrees, theta2_1 * Degrees,  theta3_1 * Degrees, theta4_1 * Degrees, theta5_1 * Degrees, theta6_1 * Degrees,
            theta1_1 * Degrees, theta2_2 * Degrees,  theta3_2 * Degrees, theta4_2 * Degrees, theta5_2 * Degrees, theta6_2 * Degrees,
            theta1_2 * Degrees, theta2_3 * Degrees,  theta3_1 * Degrees, theta4_3 * Degrees, theta5_3 * Degrees, theta6_3 * Degrees,
            theta1_2 * Degrees, theta2_4 * Degrees,  theta3_2 * Degrees, theta4_4 * Degrees, theta5_4 * Degrees, theta6_4 * Degrees,
            theta1_1 * Degrees, theta2_1 * Degrees,  theta3_1 * Degrees, (theta4_1*Degrees) + Math.PI, -theta5_1 * Degrees, (theta6_1*Degrees) + Math.PI,
            theta1_1 * Degrees, theta2_2 * Degrees,  theta3_2 * Degrees, (theta4_2*Degrees) + Math.PI, -theta5_2 * Degrees, (theta6_2*Degrees) + Math.PI,
            theta1_2 * Degrees, theta2_3 * Degrees,  theta3_1 * Degrees, (theta4_3*Degrees) + Math.PI, -theta5_3 * Degrees, (theta6_3*Degrees) + Math.PI,
            theta1_2 * Degrees, theta2_4 * Degrees,  theta3_2 * Degrees, (theta4_4*Degrees) + Math.PI, -theta5_4 * Degrees, (theta6_4*Degrees) + Math.PI
            );
            Console.WriteLine("eightsols: " + eightsols);

现在,我如何获取这些行或列之一并分配给变量?

其次,假设我对它进行了不同的编码,并希望将一组 1x6 矩阵组合或连接为一个 8x6,我该如何在 c# 中做到这一点?我知道如何在 MATLAB 中做到这一点,但是在尝试用 c# 重写我的程序时遇到很多错误。 除了他们的网站,还有谁知道在哪里可以找到关于 MathNet.Numerics 的优秀文档或书籍?

这里是一瓶药水:

//Solutions 1 to 4
            Matrix<double> Sol1 = DenseMatrix.OfArray(new double[,]
             
             theta1_1 * Degrees, theta2_1 * Degrees,  theta3_1 * Degrees, theta4_1 * Degrees, theta5_1 * Degrees, theta6_1 * Degrees 
             );
            Console.WriteLine("\nSol1: " + Sol1);

            Matrix<double> Sol2 = DenseMatrix.OfArray(new double[,]
             
             theta1_1 * Degrees, theta2_2 * Degrees,  theta3_2 * Degrees, theta4_2 * Degrees, theta5_2 * Degrees, theta6_2 * Degrees 
             );
            Console.WriteLine("\nSol2: " + Sol2);

【问题讨论】:

【参考方案1】:

我决定坚持使用 1 x 6 矩阵,然后将方程放入 8 x 6 矩阵中。

//Inverse kinematics solutions test 
//Solutions 1 to 4
Matrix<double> Sol1 = DenseMatrix.OfArray(new double[,]

    theta1_1 * Degrees, theta2_1 * Degrees,  theta3_1 * Degrees, theta4_1 * Degrees, theta5_1 * Degrees, theta6_1 * Degrees 
);
Console.WriteLine("\nSol1: " + Sol1);

Matrix<double> Sol2 = DenseMatrix.OfArray(new double[,]

    theta1_1 * Degrees, theta2_2 * Degrees,  theta3_2 * Degrees, theta4_2 * Degrees, theta5_2 * Degrees, theta6_2 * Degrees 
);
Console.WriteLine("\nSol2: " + Sol2);

Matrix<double> Sol3 = DenseMatrix.OfArray(new double[,]

    theta1_2 * Degrees, theta2_3 * Degrees,  theta3_1 * Degrees, theta4_3 * Degrees, theta5_3 * Degrees, theta6_3 * Degrees 
);
Console.WriteLine("\nSol3: " + Sol3);

Matrix<double> Sol4 = DenseMatrix.OfArray(new double[,]

    theta1_2 * Degrees, theta2_4 * Degrees,  theta3_2 * Degrees, theta4_4 * Degrees, theta5_4 * Degrees, theta6_4 * Degrees 
);
Console.WriteLine("\nSol4: " + Sol4);

// Solutions 5 to 8
Matrix<double> Sol5 = DenseMatrix.OfArray(new double[,]

    theta1_1 * Degrees, theta2_1 * Degrees,  theta3_1 * Degrees, (theta4_1*Degrees) + Math.PI, -theta5_1 * Degrees, (theta6_1*Degrees) + Math.PI
);
Console.WriteLine("\nSol5: " + Sol5);

Matrix<double> Sol6 = DenseMatrix.OfArray(new double[,]

    theta1_1 * Degrees, theta2_2 * Degrees,  theta3_2 * Degrees, (theta4_2*Degrees) + Math.PI, -theta5_2 * Degrees, (theta6_2*Degrees) + Math.PI
);
Console.WriteLine("\nSol6: " + Sol6);

Matrix<double> Sol7 = DenseMatrix.OfArray(new double[,]

    theta1_2 * Degrees, theta2_3 * Degrees,  theta3_1 * Degrees, (theta4_3*Degrees) + Math.PI, -theta5_3 * Degrees, (theta6_3*Degrees) + Math.PI
);
Console.WriteLine("\nSol7: " + Sol7);

Matrix<double> Sol8 = DenseMatrix.OfArray(new double[,]

    theta1_2 * Degrees, theta2_4 * Degrees,  theta3_2 * Degrees, (theta4_4*Degrees) + Math.PI, -theta5_4 * Degrees, (theta6_4*Degrees) + Math.PI
);
Console.WriteLine("\nSol8: " + Sol8);

//The Eight Solutions as one matrix
Matrix<double> eightsols = DenseMatrix.OfArray(new double[,]

    theta1_1 * Degrees, theta2_1 * Degrees,  theta3_1 * Degrees, theta4_1 * Degrees, theta5_1 * Degrees, theta6_1 * Degrees,
    theta1_1 * Degrees, theta2_2 * Degrees,  theta3_2 * Degrees, theta4_2 * Degrees, theta5_2 * Degrees, theta6_2 * Degrees,
    theta1_2 * Degrees, theta2_3 * Degrees,  theta3_1 * Degrees, theta4_3 * Degrees, theta5_3 * Degrees, theta6_3 * Degrees,
    theta1_2 * Degrees, theta2_4 * Degrees,  theta3_2 * Degrees, theta4_4 * Degrees, theta5_4 * Degrees, theta6_4 * Degrees,
    theta1_1 * Degrees, theta2_1 * Degrees,  theta3_1 * Degrees, (theta4_1*Degrees) + Math.PI, -theta5_1 * Degrees, (theta6_1*Degrees) + Math.PI,
    theta1_1 * Degrees, theta2_2 * Degrees,  theta3_2 * Degrees, (theta4_2*Degrees) + Math.PI, -theta5_2 * Degrees, (theta6_2*Degrees) + Math.PI,
    theta1_2 * Degrees, theta2_3 * Degrees,  theta3_1 * Degrees, (theta4_3*Degrees) + Math.PI, -theta5_3 * Degrees, (theta6_3*Degrees) + Math.PI,
    theta1_2 * Degrees, theta2_4 * Degrees,  theta3_2 * Degrees, (theta4_4*Degrees) + Math.PI, -theta5_4 * Degrees, (theta6_4*Degrees) + Math.PI
);
Console.WriteLine("eightsols: " + eightsols);

Console.ReadLine();

结果(得到了我需要的东西,最重要的是)查看照片 Click to view Results

【讨论】:

以上是关于如何使用 Math.Net 连接矩阵。如何使用 Math.Net 调用特定的行或列?的主要内容,如果未能解决你的问题,请参考以下文章

如何使用相关系数矩阵进行聚类?

如何使用 sklearn 获得所有三个 SVD 矩阵?

如何在 Netezza 中执行矩阵运算?

如何在 MATLAB 中使用 2-D 掩码索引 3-D 矩阵?

在R中如何删除包含负数的矩阵的所有列?

如何在不使用附加包的情况下绘制二进制矩阵?