我一直在尝试使用scipy在python中解决R1的以下等式,但我得到了错误:
result = root_scalar(equation, bracket=[0, 8])
Traceback (most recent call last):
Cell In[1638], line 1
result = root_scalar(equation, bracket=[0, 8])
File ~\anaconda3\lib\site-packages\scipy\optimize\_root_scalar.py:275 in root_scalar
r, sol = methodc(f, a, b, args=args, **kwargs)
File ~\anaconda3\lib\site-packages\scipy\optimize\_zeros_py.py:784 in brentq
r = _zeros._brentq(f, a, b, xtol, rtol, maxiter, args, full_output, disp)
ValueError: f(a) and f(b) must have different signs
方程为:
K= 10**(a0 + (a1 * np.log10(R1/R2)) + (a2 * (np.log10(R1/R2))**2) + (a3 * (np.log10(R1/R2))**3) + (a4 * (np.log10(R1/R2))**4)) + 0.0166
我使用的代码如下:
R2 = 0.002294000005349517
K = 0.09539999812841415
a0 = -1.1358
a1 = -2.1146
a2 = 1.6474
a3 = -1.1428
a4 = -0.6190
def equation(log_R1_R2):
x = log_R1_R2
return 10**(a0 + a1*x + a2*x**2 + a3*x**3 + a4*x**4) - (K - 0.0166)
result = root_scalar(equation, bracket=[0, 8])
log_R1_R2 = result.root
R1 = R2 * 10**log_R1_R2
1条答案
按热度按时间eqoofvh91#
这个问题似乎更适合多项式根求解器。使用
numpy.polynomial.Polynomial
类,我们可以创建所讨论的多项式,获得根,并使用这些根找到R1
。至于你想用哪个根,那是你自己决定的,因为我不知道它的应用。输出(即根):