# 按幂合并同类项（Collect terms by powers of a variable，collect）

按某个变量的幂次合并表达式中的项。

## 怎么写

### collect(expr, x)

**expr**

任意表达式：一个数、一个公式、一个列表或一个矩阵。接受一个表达式。

**x**

用于合并的变量。接受一个变量。

## 示例

- $\displaystyle x^{2} y+x^{2} z+x = x^{2} (y+z)+x$

  `collect(x^2 y + x^2 z + x, x)`

  在求解器中，`collect(x^2 y + x^2 z + x, x)` 的结果是 `x^2*(y + z) + x`。

  [在求解器中打开](https://zh.hilberon.com/?q=collect%28x%5E2%20y%20%2B%20x%5E2%20z%20%2B%20x%2C%20x%29)

## 相关函数

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

  在假定变量为实数的前提下展开表达式。
- [coefficients](https://zh.hilberon.com/library/coefficients)

  列出多项式的系数，常数项在前。
- [cyclotomic](https://zh.hilberon.com/library/cyclotomic)

  给定阶数的分圆多项式。
- [cancel](https://zh.hilberon.com/library/cancel)

  约去分数的公因式。
- [degree](https://zh.hilberon.com/library/degree)

  多项式关于某个变量的次数。
- [apart](https://zh.hilberon.com/library/apart)

  将有理式拆分成部分分式。

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