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

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
主站蜘蛛池模板: 漳浦县| 南宁市| 宣城市| 永安市| 柏乡县| 福清市| 吉林省| 佛冈县| 洛浦县| 织金县| 丰台区| 增城市| 濉溪县| 沙田区| 江安县| 石首市| 鄂尔多斯市| 延寿县| 丘北县| 洪洞县| 兴国县| 安顺市| 承德县| 仁怀市| 平乡县| 灌南县| 洪湖市| 中卫市| 依兰县| 肃北| 合阳县| 盈江县| 嘉鱼县| 鞍山市| 景泰县| 南乐县| 安徽省| 新巴尔虎右旗| 梓潼县| 庄河市| 临邑县|