簡體   English   中英

如何使用 Math.Net 連接矩陣。 如何使用 Math.Net 調用特定的行或列?

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM