简体   繁体   中英

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#.

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#? I know how to do it in MATLAB, but getting a lot of errors when trying to rewrite my program in c#. Does anyone knows where to find a good documentation or book for MathNet.Numerics other than their website?

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.

//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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM