官术网_书友最值得收藏!

Matrix of minors

Each element of a matrix has a minor. The minor is the determinant of a smaller matrix cut from the original matrix. We can find a matrix of minors by finding the minor for each element of a matrix.

To find the minor of element i, j in a 3 X 3 matrix M, remove row i and column j of the matrix. The determinant of the resulting 2 X 2 matrix is the minor of element Matrix of minors.

We can find the minor of a 2 X 2 matrix in a similar fashion. To find the minor of element i, j, remove row i and column j. The remaining scalar is the determinant. In the case of a 2 X 2 matrix, this determinant is the minor.

Getting ready

We're going to implement a helper function, Cut. The purpose of this function is to cut a 2 X 2 matrix from a 3 X 3 by eliminating one row and one column. Once we have the Cut function, implementing the Minor for a 3 X 3 matrix is straightforward: loop through the matrix, for every element assign the determinant of a 2 X 2 acquired by cutting the elements row and column from the original matrix.

How to do it…

Follow these steps to implement the minor function for two and three dimensional square matrices. We also create a generic function to remove a row and column from a three dimensional matrix:

  1. Add the declaration for both the Cut and Minor functions to matrices.h:
    mat2 Cut(const mat3& mat, int row, int col);
    mat2 Minor(const mat2& mat);
    mat3 Minor(const mat3& mat);
  2. Implement the Cut function in matrices.cpp. This function will loop over the provided mat3, skipping the specified row and column. Anything not skipped is going to be copied into a mat2:
    mat2 Cut(const mat3& mat, int row, int col) {
        mat2 result;
        int index = 0;
    
        for (int i = 0; i < 3; ++i) {
            for (int j = 0; j < 3; ++j) {
                if (i == row || j == col) {
                    continue;
                }
                int target = index++;
                int source = 3 * i + j;
                result.asArray[target] = mat.asArray[source];
            }
        }
    
        return result;
    }
  3. Implement the Minor function for mat3 in matrices.cpp:
    mat3 Minor(const mat3& mat) {
        mat3 result;
    
        for (int i = 0; i < 3; ++i) {
            for (int j = 0; j < 3; ++j) {
                result[i][j] = Determinant(Cut(mat, i, j));
            }
        }
     
        return result;
    }
  4. Implement the Minor function for mat2 in matrices.cpp:
    mat2 Minor(const mat2& mat) {
        return mat2(
            mat._22, mat._21,
            mat._12, mat._11
        );
    }

How it works…

Using row and column elimination to find the minor of a matrix makes a lot more sense if we can visualize what is happening. Let's take a look at two examples, one using a 2 X 2 matrix and one using a 3 X 3 matrix.

Minor of a 2x2 matrix

Minor of a 2x2 matrix

Given the above matrix, we can find the minor for element 1, 1 by eliminating the first row and first column of the matrix. To demonstrate the elimination of a row and column, we write squares instead of numbers for the eliminated matrix components. The following matrix shows which components we eliminated to get a 1 X 1 matrix as a result:

Minor of a 2x2 matrix

We're left with the scalar D. If we think of D as a 1 X 1 matrix, its determinant is itself. We can now put the determinant D into element 1, 1 of the matrix of minors. If we find the determinant for every element we will have the matrix of minors:

Minor of a 2x2 matrix

Minor of a 3x3 matrix

Minor of a 3x3 matrix

Given the above matrix, let's find the minor for element 3,2. We begin by eliminating the third row and second column of the matrix:

Minor of a 3x3 matrix

The determinant of the resulting 2 X 2 matrix is the minor of element 3,2:

Minor of a 3x3 matrix

If we repeat this process for every element of the matrix, we will find the matrix of minors. For the preceding matrix M, the matrix of minors is as follows:

Minor of a 3x3 matrix
主站蜘蛛池模板: 永登县| 兴海县| 洪泽县| 金山区| 荥阳市| 区。| 苏尼特左旗| 沧州市| 信丰县| 夏津县| 象州县| 同心县| 宕昌县| 承德县| 哈巴河县| 河间市| 西乌| 河津市| 新蔡县| 新竹县| 汾阳市| 南涧| 长白| 黄平县| 三台县| 许昌市| 湛江市| 衢州市| 珲春市| 枣强县| 关岭| 晴隆县| 临澧县| 手游| 安新县| 罗城| 临沂市| 华阴市| 花垣县| 峨山| 舞阳县|