版本比较
浅谈线性代数合集
正文
增加 5 行删除 5 行
46 行未改动47484950515253545522 行未改动787980818283848586139 行未改动全部展开22622722822923023123223323474 行未改动30931031131231331431531631721 行未改动33934034134234334434534646 行未改动设矩阵 $A_{m \times p}$,$B_{p \times n}$,则乘积 $C = A \times B$ 满足 $C_{i, j} = \displaystyle \sum_{k = 1}^p A_{i, k} \cdot B_{k, j}$(其中矩阵 $C$ 大小为 $m \times n$)。例子:$\begin{pmatrix} 2 & 0 \\ 2 & 6 \end{pmatrix} \times \begin{pmatrix} 8 & 2 & 5 \\ 1 & 4 & 7 \end{pmatrix} = \begin{pmatrix} 16 & 4 & 10 \\ 22 & 28 & 52 \end{pmatrix}$。矩阵乘法满足结合律,即 $(A \times B) \timesC = A \times (B \times C)$;矩阵乘法不满足交换律,即一般情况下 $A \times B \neq B \times A$。证明很简单,直接暴力带入计算即可。::::success[Code]```cpp22 行未改动由于矩阵乘法满足结合律,我们便把快速幂的思想推广到矩阵当中。借助快速幂的思想,我们可以推出结论:对于方阵 $A$ 和整数 $k$,设 $k$ 的二进制位为 $1$ 的位置是 $p_1, p_2, \cdots, p_m$,则 $A^k = A^{2^{p_1}} \times A^{2^{p_2}} \times \cdots \times A^{2^{p_m}}$。于是,我们将初始矩阵设为单位矩阵 $I$(对应快速幂的初始值 $1$),然后将快速幂的整数乘法改为矩阵乘法即可。::::success[Code]139 行未改动全部展开cin >> n;f.mtx[1][1] = 1, f.mtx[1][2] = 1;f.mtx[2][1] = 1, f.mtx[2][2] = 0;cout << Qpow(f, n).mtx[2][1] << '\n';return 0;}```::::74 行未改动}}}return c;}} dis, ans;void Qpow() {ans = dis;21 行未改动dis.a[c[u]][c[v]] = dis.a[c[v]][c[u]] = w;}Qpow();cout << ans.a[c[s]][c[e]] << '\n';return 0;}```::::46 行未改动47484950515253545522 行未改动787980818283848586139 行未改动全部展开22622722822923023123223323474 行未改动30931031131231331431531631721 行未改动33934034134234334434534646 行未改动设矩阵 $A_{m \times p}$,$B_{p \times n}$,则乘积 $C = A \times B$ 满足 $C_{i, j} = \displaystyle \sum_{k = 1}^p A_{i, k} \cdot B_{k, j}$(其中矩阵 $C$ 大小为 $m \times n$)。例子:$\begin{pmatrix} 2 & 0 \\ 2 & 6 \end{pmatrix} \times \begin{pmatrix} 8 & 2 & 5 \\ 1 & 4 & 7 \end{pmatrix} = \begin{pmatrix} 16 & 4 & 10 \\ 22 & 28 & 52 \end{pmatrix}$。矩阵乘法满足结合律,即 $(A \times B) \timesC = A \times (B \times C)$;矩阵乘法不满足交换律,即一般情况下 $A \times B \neq B \times A$。证明很简单,直接暴力带入计算即可。::::success[Code]```cpp22 行未改动由于矩阵乘法满足结合律,我们便把快速幂的思想推广到矩阵当中。借助快速幂的思想,我们可以推出结论:对于方阵 $A$ 和整数 $k$,设 $k$ 的二进制位为 $1$ 的位置是 $p_1, p_2, \cdots, p_m$,则 $A^k = A^{2^{p_1}} \times A^{2^{p_2}} \times \cdots \times A^{2^{p_m}}$。于是,我们将初始矩阵设为单位矩阵 $I$(对应快速幂的初始值 $1$),然后将快速幂的整数乘法改为矩阵乘法即可。::::success[Code]139 行未改动全部展开cin >> n;f.mtx[1][1] = 1, f.mtx[1][2] = 1;f.mtx[2][1] = 1, f.mtx[2][2] = 0;cout << Qpow(f, n).mtx[2][1] << '\n';return 0;}```::::74 行未改动}}}return c;}} dis, ans;void Qpow() {ans = dis;21 行未改动dis.a[c[u]][c[v]] = dis.a[c[v]][c[u]] = w;}Qpow();cout << ans.a[c[s]][c[e]] << '\n';return 0;}```::::