在方形二维数组上创建逆矩阵并在datagridview中显示 [英] create Inverse Matrix on square 2-D array and display in datagridview

查看:125
本文介绍了在方形二维数组上创建逆矩阵并在datagridview中显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个二维数组(方形矩阵),我想找到二维数组的逆矩阵,然后使用datagridview控件显示逆矩阵

下面的代码在datagridview控件中显示2d矩阵

I have a 2-D array (square matrix) that i want to find the inverse matrix of the 2d array then display the inverse matrix with using datagridview control

The code below displays the 2d matrix in the datagridview control

Dim myArray(,) As Double
        myArray = New Double(2, 2) {{"0,0", "0,1", "0,3"}, {"1,0", "1,1", "1,3"}, {"2,0", "2,1", "2,3"}}
        Dim myTable As New DataTable


        
        Dim iRows As Integer = myArray.GetLength(0)
        Dim iCols As Integer = myArray.GetLength(1)

        For i As Integer = 1 To iCols
            myTable.Columns.Add()
        Next

        For iRow As Integer = 0 To iRows - 1
            Dim newRow As DataRow = myTable.NewRow
            For iCol As Integer = 0 To iCols - 1
                newRow(iCol) = myArray(iRow, iCol)
            Next
            myTable.Rows.Add(newRow)
        Next

        DataGridView1.DataSource = myTable

推荐答案

这是矩阵求反操作的描述,您可以选择特殊情况下3x3的算法:

http://en.wikipedia.org/wiki/Invertible_matrix#Inversion_of_3.C3.973_matrices [ ^ ].

只需在您的代码中使用它即可.不要忘了矩阵可以是不可逆的.

您可以使用以下在线矩阵计算器检查并测试您的代码: http://www.jimmysie.com/maths/matrixinv. php [ ^ ].

—SA
This is the description of matrix inversion operation and the algorithm for the special case 3x3 you may choose:

http://en.wikipedia.org/wiki/Invertible_matrix#Inversion_of_3.C3.973_matrices[^].

Just use it in your code. Don''t forget that a matrix can be invertable or not.

You can check up and test your code using this online matrix calculator: http://www.jimmysie.com/maths/matrixinv.php[^].

—SA


这篇关于在方形二维数组上创建逆矩阵并在datagridview中显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆