[英]How to concatenate matrices with Math.Net. How to call for a particular row or column with Math.Net?
如何调用特定的行或列?
假设我有这个 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 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();
结果(得到了我需要的东西,最重要的是)查看照片点击查看结果
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.