跳到正文

个人记录

矩阵快速幂与矩阵设计入门

ZMQ_Ink65536约 4 分钟
原文
文章信息与版本

文章信息

发布
2026年10月28日
收录
2026年10月28日
更新
2026年11月15日
篇幅
约 4 分钟

版本

  1. v1当前

矩阵快速幂与矩阵设计入门

矩阵快速幂

I have 矩阵!

I have 快速幂!

I have 矩阵快速幂!

O(n3log⁡k)\mathcal O(n^3 \log k)

矩阵设计

  1. 确定状态向量
  2. 写出一阶线性更新方程组
  3. 提取系数填入矩阵

典例 11:f(x)=f(x−1)+f(x−2)f(x) = f(x - 1) + f(x - 2)

状态 vt=[ftft−1]v_t = \begin{bmatrix}f_t \\ f_{t - 1}\end{bmatrix},目标 vt+1=[ft+1ft]v_{t + 1} = \begin{bmatrix} f_{t + 1} \\ f_t \end{bmatrix}。

方程组:

{ft+1=1×ft+1×ft−1ft=1×ft+0×ft−1\begin{cases} f_{t + 1} = {\color{Red} 1} \times f_t + {\color{Red} 1} \times f_{t - 1} \\ f_{t} = {\color{Red} 1} \times f_{t} + {\color{Red} 0} \times{f_{t - 1}} \end{cases}

填入矩阵:

[ft+1ft]=[1 11 0][ftft−1]\begin{bmatrix} f_{t + 1} \\ f_t \end{bmatrix} = \begin{bmatrix} 1 \ 1 \\ 1 \ 0 \end{bmatrix} \begin{bmatrix} f_t \\ f_{t - 1} \end{bmatrix}

进阶 f(x)=f(x−1)+f(x−2)+3f(x) = f(x - 1) + f(x - 2) + 3,求 ∑f(x)\sum f(x)

加入 sts_t 表示前缀和,1t1_t 表示常数。

状态向量 vt=[stftft−11]v_t = \begin{bmatrix} s_t \\ f_t \\ f_{t - 1} \\ 1\end{bmatrix},目标向量 vt+1=[st+1ft+1ft1]v_{t + 1} = \begin{bmatrix} s_{t + 1} \\ f_{t + 1} \\ f_t \\ 1 \end{bmatrix}。

方程组:

{st+1=1×st+1×ft+1×ft−1+3×1ft+1=0×st+1×ft+1×ft−1+3×1ft=0×st+1×ft+0×ft−1+0×11=0×st+0×ft+0×ft−1+1×1\begin{cases} s_{t + 1} = {\color{Red} 1} \times s_t + {\color{Red} 1} \times f_t + {\color{Red} 1} \times f_{t - 1} + {\color{Red} 3} \times 1 \\ f_{t + 1} = {\color{Red} 0} \times s_t + {\color{Red} 1} \times f_t + {\color{Red} 1} \times f_{t - 1} + {\color{Red} 3} \times 1 \\ f_t = {\color{Red} 0} \times s_t + {\color{Red} 1} \times f_t + {\color{Red} 0} \times f_{t - 1} + {\color{Red} 0} \times 1 \\ 1 = {\color{Red} 0} \times s_t + {\color{Red} 0} \times f_t + {\color{Red} 0} \times f_{t - 1} + {\color{Red} 1} \times 1 \\ \end{cases}

填入矩阵:

M=[1 1 1 30 1 1 30 1 0 00 0 0 1]M = \begin{bmatrix}1 \ 1 \ 1 \ 3 \\ 0 \ 1 \ 1 \ 3 \\ 0 \ 1 \ 0 \ 0 \\ 0 \ 0 \ 0 \ 1 \end{bmatrix}

进阶 带时间 tt:f(x)=2f(x−1)+x2+x+1f(x) = 2f(x - 1) + x^2 + x + 1

状态向量 vt=[ftt2t1]v_t = \begin{bmatrix} f_t \\ t^2 \\ t \\ 1 \end{bmatrix},目标向量 vt+1=[ft+1(t+1)2(t+1)1]v_{t + 1} = \begin{bmatrix} f_{t + 1} \\ (t + 1)^2 \\ (t + 1) \\ 1 \end{bmatrix}。

填入矩阵:

M=[2 1 3 30 1 2 10 0 1 10 0 0 1]M = \begin{bmatrix} 2 \ 1 \ 3 \ 3 \\ 0 \ 1 \ 2 \ 1 \\ 0 \ 0 \ 1 \ 1 \\ 0 \ 0 \ 0 \ 1\end{bmatrix}
原文