求解如下方程

from scipy.optimize import fsolve, root
import numpy as np
# 定义方程内容
def f(x, *arg):
return arg[0] * 2 ** (1 - x) / (1 - x) + (1 - arg[0]) * 1.6 ** (1 - x) / (1 - x) - arg[0] * 3.85 ** (1 - x) / (
1 - x) - (1 - arg[0]) * 0.1 ** (1 - x) / (1 - x)
# 参数p为一个超参数
results = [[p * 0.1, fsolve(f, x0=0, args=(p * 0.1))[0]] for p in range(2, 10)]
print(np.array(results), '\n')
results = [[p * 0.1, root(f, x0=0, args=(p * 0.1))['x'][0]] for p in range(2, 10)]
print(np.array(results))
# output results
[[ 0.2 -0.94683705]
[ 0.3 -0.48657472]
[ 0.4 -0.14263228]
[ 0.5 0.14636333]
[ 0.6 0.4114561 ]
[ 0.7 0.67618002]
[ 0.8 0.9705809 ]
[ 0.9 1.3683912 ]]
[[ 0.2 -0.94683705]
[ 0.3 -0.48657472]
[ 0.4 -0.14263228]
[ 0.5 0.14636333]
[ 0.6 0.4114561 ]
[ 0.7 0.67618002]
[ 0.8 0.9705809 ]
[ 0.9 1.3683912 ]]

本文介绍了一种利用Python的Scipy库求解特定形式的非线性方程的方法。通过定义方程和使用fsolve及root函数,文章展示了如何根据不同参数找到方程的根,提供了一个具体的示例及其输出结果。
7667





