math-矩阵的加法、乘法、转置、求逆、行列式

  • 矩阵运算 及 md表示 记录
  • python需要用到的库 numpy
    • import numpy as np

矩阵加法

  • 两个 相同维数 矩阵的加法可以通过对应元素的相加得到, $a_{ij} + b_{ij}$

$$
\begin{Bmatrix}
1 & 2 & 3 \
4 & 5 & 6
\end{Bmatrix}
+
\begin{Bmatrix}
4 & 5 & 6 \
7 & 8 & 9
\end{Bmatrix}
=
\begin{Bmatrix}
5 & 7 & 9 \
11 & 13 & 15
\end{Bmatrix}
$$


矩阵乘法

  • 定义 设矩阵 $A=(a_{ij}){m \times n}$, $B=(b{ij}){s \times n}$ ,那么 矩阵A 与 矩阵B 的乘积是一个 $m \times n$ 矩阵$C=(c{ij}){m \times n}$ ,其中 $c{ij}=a_{i1}b_{1j}+a_{i2}b_{2j}+…+a_{is}b_{sj}=\sum_{k=1}^s{a_{ik}b_{kj}}$

  • 只有当 矩阵A 的 列数 等于 矩阵B 的 行数 时,两个矩阵才能相乘

  • 例如
    $$
    C=A \times B =
    \begin{Bmatrix}
    1 & 2 & 3\
    4 & 5 & 6
    \end{Bmatrix}
    \times
    \begin{Bmatrix}
    1 & 4\
    2 & 5\
    3 & 6

    \end{Bmatrix}

    \begin{Bmatrix}
    1x1+2x2+3x3 & 1x4+2x5+3x6\
    4x1+5x2+6x3 & 4x4+5x5+6x6

    \end{Bmatrix}

    \begin{Bmatrix}
    14 & 32\
    32 & 77
    \end{Bmatrix}
    $$

  • python代码测试

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    def matTest2():
    ma = [[1, 2, 3],
    [4, 5, 6]]
    ma = np.mat(ma) # 转为ndarray对象,矩阵化
    mb = [[1, 4],
    [2, 5],
    [3, 6]]
    mb = np.mat(mb)
    mc = ma.dot(mb) # 矩阵乘法
    print(mc)
    pass

    结果
    [[14 32]
    [32 77]]

转置矩阵

  • 定义:把矩阵 A 的 行列互换 所得到的矩阵称为 原矩阵 的 转置矩阵,以 $A^T$ 表示。

  • 即 $A=(a_{ij}){m \times n}$ , $A^T = (a{ji})_{n \times m}$


    $$
    A =
    \begin{Bmatrix}
    a_{11} & a_{12} & \cdots & a_{1n} \
    a_{21} & a_{22} & \cdots & a_{21} \
    \vdots & \vdots & \ddots & \vdots \
    a_{m1} & a_{m1} & \cdots & a_{mn} \
    \end{Bmatrix}
    ,A^T =
    \begin{Bmatrix}
    a_{11} & a_{21} & \cdots & a_{m1} \
    a_{12} & a_{22} & \cdots & a_{m2} \
    \vdots & \vdots & \ddots & \vdots \
    a_{1n} & a_{2n} & \cdots & a_{nm} \
    \end{Bmatrix}
    $$

  • 例如:
    $$
    A=
    \begin{Bmatrix}
    1 & 2 & 3 \
    4 & 5 & 6
    \end{Bmatrix}
    , A^T=
    \begin{Bmatrix}
    1 & 4\
    2 & 5\
    3 & 6
    \end{Bmatrix}
    $$

  • python代码测试

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    def matTest3():
    ma = [[1, 2, 3],
    [4, 5, 6]]
    ma = np.mat(ma)
    mb = ma.T #矩阵转置
    print(mb)
    pass

    结果
    [[1 4]
    [2 5]
    [3 6]]

矩阵求逆

  • 定义:一个n阶 方阵A 称为可逆的,或非奇异的,如果存在一个n阶 方阵B,使得 $A \times B = B \times A = E$ 并称B是A的一个 逆矩阵。不可逆的矩阵称为 奇异矩阵。A 的逆矩阵记作 $A^{-1}$。且 $A \times A^{-1}$ 得到的矩阵为 对角线元素全为1其他元素全为0

  • 例如:
    $$
    A=
    \begin{Bmatrix}
    -2 & 1\
    4 & -3
    \end{Bmatrix}
    ,B=
    \begin{Bmatrix}
    -\frac{3}{2} & -\frac{1}{2}\
    -2 & -1
    \end{Bmatrix}
    $$

    $$
    A \times B =
    \begin{Bmatrix}
    -2 & 1\
    4 & -3
    \end{Bmatrix}
    \times
    \begin{Bmatrix}
    -\frac{3}{2} & -\frac{1}{2}\
    -2 & -1

    \end{Bmatrix}

    \begin{Bmatrix}
    1 & 0\
    0 & 1
    \end{Bmatrix}
    $$

  • 所以判断两个矩阵是否为互逆矩阵,直接相乘即可判断

  • 性质:

    1. 可逆矩阵一定是方阵。
    2. (唯一性)如果矩阵A是可逆的,其逆矩阵是唯一的。
    3. A的逆矩阵的逆矩阵还是A。记作 $(A^{-1})^{-1} = A$
    4. 可逆矩阵A的转置矩阵AT也可逆,并且 $(A^T)^{-1} = (A^{-1})^T$ (转置的逆等于逆的转置)
    5. 若矩阵A可逆,则矩阵A满足消去律。即AB=O(或BA=O),则B=O,AB=AC(或BA=CA),则B=C。
    6. 两个可逆矩阵的乘积依然可逆。
    7. 矩阵可逆当且仅当它是满秩矩阵。
  • python代码测试

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    def matTest4():
    ma = [[-2, 1],
    [4, -3]]
    ma = np.mat(ma)
    mb = np.linalg.inv(ma) # 矩阵求逆
    print(mb)
    mc = ma.dot(mb)
    print(mc)
    pass

    结果
    [[-1.5 -0.5]
    [-2. -1. ]]
    [[ 1. 0.]
    [ 0. 1.]]

矩阵行列式

  1. 对角线展开
    $$
    二阶:
    \begin{Bmatrix}
    a_1 & b_1\
    a_2 & b_2
    \end{Bmatrix}
    = a_1b_2-a_2b_1
    $$

    $$
    三阶:
    \begin{Bmatrix}
    a_1 & b_1 & c_1\
    a_2 & b_2 & c_2\
    a_3 & b_3 & c_3
    \end{Bmatrix}
    =a_1b_2c_3+b_1c_2a_3+c_1a_2b_3-a_3b_2c_1-b_3c_2a_1-c_3a_2b_1
    $$

  2. 降阶展开(适合高阶行列式)
    $$
    按第一阶展开:
    \begin{Bmatrix}
    a_1 & b_1 & c_1\
    a_2 & b_2 & c_2\
    a_3 & b_3 & c_3

    \end{Bmatrix}

    a_1 \times
    \begin{Bmatrix}
    b_2 & c_2\
    b_3 & c_3
    \end{Bmatrix}

  • b_1 \times
    \begin{Bmatrix}
    a_2 & c_2\
    a_3 & c_3
    \end{Bmatrix}
  • c_1 \times
    \begin{Bmatrix}
    a_2 & b_2\
    a_3 & b_3
    \end{Bmatrix}
    $$

$$
按中阶展开:
\begin{Bmatrix}
a_1 & b_1 & c_1\
a_2 & b_2 & c_2\
a_3 & b_3 & c_3
\end{Bmatrix}
=
b_2 \times
\begin{Bmatrix}
a_1 & c_1\
a_3 & c_3
\end{Bmatrix}

  • a_2 \times
    \begin{Bmatrix}
    b_1 & c_1\
    b_3 & c_3
    \end{Bmatrix}
  • c_2 \times
    \begin{Bmatrix}
    a_1 & b_1\
    a_3 & b_3
    \end{Bmatrix}
    $$
  1. python代码测试

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    def matTest5():
    ma = [[1, 2],
    [1, 3]]
    ma = np.mat(ma)
    mb = np.linalg.det(ma)
    print(mb)

    mf = [[1, 2, 3],
    [4, 5, 6],
    [7, 8, 9]]
    mf = np.mat(mf)
    me = np.linalg.det(mf)
    print(me)

    结果
    1.0
    6.66133814775e-16

附_矩阵的markdown表示

1
2
3
4
5
6
7
8
9
$$
\left\{
\begin{matrix}
1 & 2 & 3 \\
4 & 5 & 6 \\
7 & 8 & 9
\end{matrix}
\right\} \tag{2}
$$

$$
\left{
\begin{matrix}
1 & 2 & 3 \
4 & 5 & 6 \
7 & 8 & 9
\end{matrix}
\right} \tag{2}
$$


1
2
3
4
5
6
7
$$
\begin{Bmatrix}
1 & 2 & 3 \\
4 & 5 & 6 \\
7 & 8 & 9
\end{Bmatrix} \tag{5}
$$

$$
\begin{Bmatrix}
1 & 2 & 3 \
4 & 5 & 6 \
7 & 8 & 9
\end{Bmatrix} \tag{5}
$$


1
2
3
4
5
6
7
8
9
$$
\left[
\begin{matrix}
1 & 2 & 3 \\
4 & 5 & 6 \\
7 & 8 & 9
\end{matrix}
\right] \tag{3}
$$

$$
\left[
\begin{matrix}
1 & 2 & 3 \
4 & 5 & 6 \
7 & 8 & 9
\end{matrix}
\right] \tag{3}
$$


1
2
3
4
5
6
7
$$
\begin{bmatrix}
1 & 2 & 3 \\
4 & 5 & 6 \\
7 & 8 & 9
\end{bmatrix} \tag{4}
$$

$$
\begin{bmatrix}
1 & 2 & 3 \
4 & 5 & 6 \
7 & 8 & 9
\end{bmatrix} \tag{4}
$$


1
2
3
4
5
6
7
8
9
10
$$
\left[
\begin{matrix}
1 & 2 & \cdots & 4 \\
7 & 6 & \cdots & 5 \\
\vdots & \vdots & \ddots & \vdots \\
8 & 9 & \cdots & 0 \\
\end{matrix}
\right] \tag {6}
$$

$$
\left[
\begin{matrix}
1 & 2 & \cdots & 4 \
7 & 6 & \cdots & 5 \
\vdots & \vdots & \ddots & \vdots \
8 & 9 & \cdots & 0 \
\end{matrix}
\right] \tag {6}
$$


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
$$
\left[
\begin{array}{cc|c}
1 & 2 & 3 \\
4 & 5 & 6
\end{array}
\right]
=>
\left[
\begin{array}{cc|c}
1 & 2 & 3 \\
4 & 5 & 6
\end{array}
\right] \tag{7}
$$

$$
\left[
\begin{array}{cc|c}
1 & 2 & 3 \
4 & 5 & 6
\end{array}
\right]
=>
\left[
\begin{array}{cc|c}
1 & 2 & 3 \
4 & 5 & 6
\end{array}
\right] \tag{7}
$$


1
我们使用矩阵 $\bigl( \begin{smallmatrix} a & b \\ c & d \end{smallmatrix} \bigr)$ 作为因子矩阵,将其...

我们使用矩阵 $\bigl( \begin{smallmatrix} a & b \ c & d \end{smallmatrix} \bigr)$ 作为因子矩阵,将其…