|
|
发表于 2026-9-26 14:36:35
|
显示全部楼层
用 Python 的话说,可以交给 `sympy` 来解:
```python
from sympy import symbols, Eq, solve, expand, I, sqrt
x = symbols('x') # 默认复数符号
num = (x + 5) * (x + 6) * (x + 7) * (x + 8)
den = (x - 5) * (x - 6) * (x - 7) * (x - 8)
# 原方程:num / den = 1
# 等价于 num - den = 0,但要求 den != 0
expr = expand(num - den)
print(expr)
# 输出:52*x**3 + 2132*x
solutions = solve(Eq(expr, 0), x)
print(solutions)
# 输出:[0, -sqrt(41)*I, sqrt(41)*I]
# 原方程要求分母不为 0,即 x 不能是 5,6,7,8
valid_solutions = [s for s in solutions if s not in (5, 6, 7, 8)]
print(valid_solutions)
# 输出:[0, -sqrt(41)*I, sqrt(41)*I]
```
如果只要实数解,可以这样写:
```python
from sympy import symbols, Eq, solve
x = symbols('x', real=True)
solutions = solve(
Eq(
(x + 5) * (x + 6) * (x + 7) * (x + 8),
(x - 5) * (x - 6) * (x - 7) * (x - 8)
),
x
)
print(solutions)
# 输出:[0]
```
所以:
- 实数解:\(\boxed{x = 0}\)
- 复数解:\(\boxed{x = 0,\ x = \pm i\sqrt{41}}\)
用 Python 术语总结就是:
```python
x = 0 # 唯一实数解
``` |
|