# Demo 3:矩阵秩 > 第 11 章 查询复杂度 · [本章演示](index.md) · [代码演示总索引](../index.md) **可视化**:3 子图 —— 4×4 高斯消元 + 量子查询复杂度 **对应教程**:[第 11 章 查询复杂度 中相关小节](https://tutorial.chenzhaoyun.com/quantum-tutorial/ch11-query-complexity/) · 依赖安装:`pip install "unified-quantum[visualization,simulation]"` ## 实现要点 核心:构造 4x4 二值矩阵 A (rank=3), 演示 (左上) 矩阵 A 热图 + rank + 奇异值 (右上) 高斯消元 4 步 row-echelon 形式 (经典 nm = 16 次 oracle 查询基线) (左下) 经典 O(nm) vs 量子 O(sqrt(r(n-r+1)) L T) 查询数对比 (右下) uniqc 验证 16 个 entry oracle: A[i,j]=0 -> P(0)~1; A[i,j]=1 -> P(0)~0 ## 完整源码 ```{literalinclude} 03_matrix_rank.py :language: python :linenos: :caption: demos/ch11-query-complexity/03_matrix_rank.py ``` ## 运行结果 ![Demo 3:矩阵秩](03_matrix_rank.png) ## 运行方式 ```bash # 仓库根目录执行;输出 PNG 到 demos/ch11-query-complexity/03_matrix_rank.png,关键统计到 stdout .venv/bin/python3 demos/ch11-query-complexity/03_matrix_rank.py ``` --- [← 本章演示](index.md) · [↑ 代码演示总索引](../index.md) · [⌂ 教程门户](https://tutorial.chenzhaoyun.com/)