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

  • Game Physics Cookbook
  • Gabor Szauer
  • 680字
  • 2021-04-02 20:27:28

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
主站蜘蛛池模板: 白水县| 景洪市| 邹城市| 左云县| 岑溪市| 崇礼县| 宁强县| 乐都县| 合作市| 建德市| 康保县| 博兴县| 平度市| 达拉特旗| 霞浦县| 博野县| 南部县| 铜山县| 屏边| 泌阳县| 社会| 循化| 西城区| 望城县| 武胜县| 金阳县| 广元市| 玉环县| 盖州市| 饶河县| 松滋市| 阿拉善盟| 科技| 商河县| 临武县| 雅江县| 涿鹿县| 闵行区| 黔江区| 长丰县| 察隅县|