我尝试求解非线性方程式时出错

时间:2019-05-21 04:54:05

标签: python numpy scipy

我正在尝试求解以下方程式:

enter image description here

我将上面的等式转换为如下所示的python代码:

from scipy.optimize import fsolve
import numpy as np

u = lambda b : ((1 - b)(7.864 - 5.336*b + 25.864*np.power(b,2) - 11.935*np.power(b,3) - 0.336*np.power(b,4))) - 6.164

fsolve(u,np.linspace(0,1,10))

但是我收到一条错误消息:

enter image description here

这可能是什么原因?我在做什么错?

1 个答案:

答案 0 :(得分:2)

在(1-b)和(7.864 ...:

之间缺少一个*
In [11]: from scipy.optimize import fsolve
    ...: import numpy as np
    ...:
    ...: u = lambda b : ((1 - b) * (7.864 - 5.336*b + 25.864*np.power(b,2) - 11.935*np.power(b,3) - 0.336*np.power(b,4))) - 6.164
    ...:                       # ^ MISSING HERE
    ...: fsolve(u,np.linspace(0,1,10))
    ...:
Out[11]:
array([0.20503009, 0.20503009, 0.20503009, 0.20503009, 0.20503009,
       0.20503009, 0.20503009, 0.20503009, 0.20503009, 0.20503009])

出现错误TypeError: 'numpy.ndarray' object is not callable,这与尝试执行的操作相同:

In [12]: a
Out[12]: array(42)

In [13]: a()
TypeError: 'numpy.ndarray' object is not callable

In [14]: a(1)
TypeError: 'numpy.ndarray' object is not callable