# 求解递推关系（Solve recurrence relations，solve_recurrence）

求解数列的递推关系。

## 怎么写

### solve_recurrence(equations, unknown, variable)

求出用下标表示的数列。含 t(n/b) 时，n 是 b 的幂，答案中会注明。

**equations**

递推式，或包含初始值（如 a(0) = 1）的列表。接受一个方程或放在方括号中的方程列表。

**unknown**

要求解的未知数，例如 y。接受一个变量或变量列表。

**variable**

要处理的变量，是一个名称，例如 x。接受一个变量或变量列表。

## 示例

- $\displaystyle \begin{cases} a(n+1) = 2 a(n) \\ a(0) = 1 \end{cases} \Rightarrow a(n) = 2^{n}$

  `solve_recurrence([a(n+1) = 2 a(n), a(0) = 1], a, n)`

  在求解器中，`solve_recurrence([a(n+1) = 2 a(n), a(0) = 1], a, n)` 的结果是 `[[a(n) -> 2^n]]`。

  [在求解器中打开](https://zh.hilberon.com/?q=solve_recurrence%28%5Ba%28n%2B1%29%20%3D%202%20a%28n%29%2C%20a%280%29%20%3D%201%5D%2C%20a%2C%20n%29)
- $\displaystyle \begin{cases} t(n) = 2 t\left(\frac{n}{2}\right)+n \\ t(1) = 1 \end{cases} \Rightarrow t(n) = n+\frac{n \ln(n)}{\ln(2)},\ n \ge 1,\ \frac{\ln(n)}{\ln(2)} \in \mathbb{Z}$

  `solve_recurrence([t(n) = 2 t(n/2) + n, t(1) = 1], t, n)`

  在求解器中，`solve_recurrence([t(n) = 2 t(n/2) + n, t(1) = 1], t, n)` 的结果是 `[[t(n) -> n + n*ln(n)/ln(2) if n >= 1 and ln(n)/ln(2) : integer]]`。

  [在求解器中打开](https://zh.hilberon.com/?q=solve_recurrence%28%5Bt%28n%29%20%3D%202%20t%28n%2F2%29%20%2B%20n%2C%20t%281%29%20%3D%201%5D%2C%20t%2C%20n%29)

## 相关函数

- [recurrence_growth](https://zh.hilberon.com/library/recurrence_growth)

  分治递推式的增长阶，以简单函数的 big_theta 表示。
- [solve_ode](https://zh.hilberon.com/library/solve_ode)

  求解微分方程或方程组，可附带初始条件。

---
Source: https://zh.hilberon.com/library/solve_recurrence
