# Demo 1:Trotter Ising 链 > 第 5 章 哈密顿量模拟与 QSP · [本章演示](index.md) · [代码演示总索引](../index.md) **可视化**:3 子图(H+误差+末态分布) —— 一阶/二阶 Trotter 误差对数曲线 **对应教程**:[第 5 章 哈密顿量模拟与 QSP 中相关小节](https://tutorial.chenzhaoyun.com/quantum-tutorial/ch05-hamiltonian-qsp/) · 依赖安装:`pip install "unified-quantum[visualization,simulation]"` ## 实现要点 模型: H = -J Σ_{i=1}^{n-1} Z_i Z_{i+1} - h Σ_{i=1}^{n} X_i, n=4, J=1, h=0.5, t=1. 对 r ∈ {1, 2, 4, 8, 16, 32} 步数分别构造 - 一阶 Trotter: (Π_k e^{-iα_k H_k t/r})^r - 二阶 Strang: 半步正序 + 半步反序 通过 c.get_matrix() 与精确 exp(-iHt) 比较 Frobenius 范数误差. ZZ 项 e^{iJδ Z_i Z_{i+1}} 由 CNOT(i,j) · R_z(j, -2Jδ) · CNOT(i,j) 实现. X 项 e^{ihδ X_j} = R_x(j, -2hδ). ## 完整源码 ```{literalinclude} 01_trotter_ising.py :language: python :linenos: :caption: demos/ch05-hamiltonian-qsp/01_trotter_ising.py ``` ## 运行结果 ![Demo 1:Trotter Ising 链](01_trotter_ising.png) ## 运行方式 ```bash # 仓库根目录执行;输出 PNG 到 demos/ch05-hamiltonian-qsp/01_trotter_ising.png,关键统计到 stdout .venv/bin/python3 demos/ch05-hamiltonian-qsp/01_trotter_ising.py ``` --- [← 本章演示](index.md) · [↑ 代码演示总索引](../index.md) · [⌂ 教程门户](https://tutorial.chenzhaoyun.com/)