[英]How to concatenate matrices with Math.Net. How to call for a particular row or column with Math.Net?
How can I call for a particular row or column?如何调用特定的行或列?
Lets say I have this 8 x 6 matrix and want to call only one row or one column and assign that to a new variable, How to go about this in c#.假设我有这个 8 x 6 矩阵并且只想调用一行或一列并将其分配给一个新变量,如何在 c# 中讨论这个问题。
Here is a piece of the code:这是一段代码:
//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);
Now, how do I get one of these Rows or column and assign to a variable?现在,我如何获得这些行或列之一并分配给一个变量?
Secondly, Lets say I coded it differently and want to combine or concatenate a set of 1x6 matrix as an one 8x6, how can I do such in c#?其次,假设我对它进行了不同的编码,并且想要将一组 1x6 矩阵组合或连接为一个 8x6,我该如何在 c# 中做到这一点? I know how to do it in MATLAB, but getting a lot of errors when trying to rewrite my program in c#.我知道如何在 MATLAB 中执行此操作,但是在尝试在 c# 中重写我的程序时出现很多错误。 Does anyone knows where to find a good documentation or book for MathNet.Numerics other than their website?除了他们的网站,有谁知道在哪里可以找到关于 MathNet.Numerics 的好的文档或书籍?
Here is a potion of the code:下面是一段代码:
//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);
I decided to stick with the 1 x 6 matrices as is then place the equations in an 8 x 6 matrix.我决定坚持使用 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();
Results (Got what I needed, most importantly) see photo Click to view Results结果(得到了我需要的东西,最重要的是)查看照片点击查看结果
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.