缺少7个必需的位置参数

时间:2018-03-30 03:30:24

标签: python scipy

from scipy.optimize import fsolve
def f(theta1,theta2,theta3,theta4,beta1,beta2,beta3,beta4):
    func1 = -0.07*beta1*theta1**2/(-theta1**2 + 1) - 0.07*beta1*theta2**2/(-theta1*theta2 + 1) - 0.07*beta1*theta3**2/(-theta1*theta3 + 1) - 0.07*beta1*theta4**2/(-theta1*theta4 + 1) - 0.07*beta1/(-theta1**2 + 1) - 0.07*beta1/(-theta1 + 1) - 1.86*theta1/(-theta1**2 + 1) - 0.93*theta2/(-theta1*theta2 + 1) - 0.93*theta3/(-theta1*theta3 + 1) - 0.93*theta4/(-theta1*theta4 + 1) + 0.93*(-theta1 + 0.93)/(theta1**2 - 1) - 0.93/(-theta1 + 1)
    func2 = -0.07*beta2*theta1**2/(-theta1*theta2 + 1) - 0.07*beta2*theta2**2/(-theta2**2 + 1) - 0.07*beta2*theta3**2/(-theta2*theta3 + 1) - 0.07*beta2*theta4**2/(-theta2*theta4 + 1) - 0.07*beta2/(-theta2**2 + 1) - 0.07*beta2/(-theta2 + 1) - 0.06*theta1/(-theta1*theta2 + 1) - 0.12*theta2/(-theta2**2 + 1) - 0.06*theta3/(-theta2*theta3 + 1) - 0.06*theta4/(-theta2*theta4 + 1) + 0.06*(-theta1 + 0.93)/(theta1*theta2 - 1) - 0.06/(-theta2 + 1),
    func3 = -0.07*beta3*theta1**2/(-theta1*theta3 + 1) - 0.07*beta3*theta2**2/(-theta2*theta3 + 1) - 0.07*beta3*theta3**2/(-theta3**2 + 1) - 0.07*beta3*theta4**2/(-theta3*theta4 + 1) - 0.07*beta3/(-theta3**2 + 1) - 0.07*beta3/(-theta3 + 1) - 0.001*theta1/(-theta1*theta3 + 1) - 0.001*theta2/(-theta2*theta3 + 1) - 0.002*theta3/(-theta3**2 + 1) - 0.001*theta4/(-theta3*theta4 + 1) + 0.001*(-theta1 + 0.93)/(theta1*theta3 - 1) - 0.001/(-theta3 + 1),
    func4 = -0.07*beta4*theta1**2/(-theta1*theta4 + 1) - 0.07*beta4*theta2**2/(-theta2*theta4 + 1) - 0.07*beta4*theta3**2/(-theta3*theta4 + 1) - 0.07*beta4*theta4**2/(-theta4**2 + 1) - 0.07*beta4/(-theta4**2 + 1) - 0.07*beta4/(-theta4 + 1) - 0.003*theta1/(-theta1*theta4 + 1) - 0.003*theta2/(-theta2*theta4 + 1) - 0.003*theta3/(-theta3*theta4 + 1) - 0.006*theta4/(-theta4**2 + 1) + 0.003*(-theta1 + 0.93)/(theta1*theta4 - 1) - 0.003/(-theta4 + 1),
    func5 = -0.09*beta1*theta1**2/(-theta1**2 + 1) - 0.09*beta1*theta2**2/(-theta1*theta2 + 1) - 0.09*beta1*theta3**2/(-theta1*theta3 + 1) - 0.09*beta1*theta4**2/(-theta1*theta4 + 1) - 0.09*beta1/(-theta1**2 + 1) - 0.09*beta1/(-theta1 + 1) - 0.12*theta1/(-theta1**2 + 1) - 0.06*theta2/(-theta1*theta2 + 1) - 0.06*theta3/(-theta1*theta3 + 1) - 0.06*theta4/(-theta1*theta4 + 1) + 0.06*(-theta2 + 0.95)/(theta1*theta2 - 1) - 0.06/(-theta1 + 1),
    func6 = -0.09*beta2*theta1**2/(-theta1*theta2 + 1) - 0.09*beta2*theta2**2/(-theta2**2 + 1) - 0.09*beta2*theta3**2/(-theta2*theta3 + 1) - 0.09*beta2*theta4**2/(-theta2*theta4 + 1) - 0.09*beta2/(-theta2**2 + 1) - 0.09*beta2/(-theta2 + 1) - 0.95*theta1/(-theta1*theta2 + 1) - 1.9*theta2/(-theta2**2 + 1) - 0.95*theta3/(-theta2*theta3 + 1) - 0.95*theta4/(-theta2*theta4 + 1) + 0.95*(-theta2 + 0.95)/(theta2**2 - 1) - 0.95/(-theta2 + 1),
    func7 = -0.09*beta3*theta1**2/(-theta1*theta3 + 1) - 0.09*beta3*theta2**2/(-theta2*theta3 + 1) - 0.09*beta3*theta3**2/(-theta3**2 + 1) - 0.09*beta3*theta4**2/(-theta3*theta4 + 1) - 0.09*beta3/(-theta3**2 + 1) - 0.09*beta3/(-theta3 + 1) - 0.03*theta1/(-theta1*theta3 + 1) - 0.03*theta2/(-theta2*theta3 + 1) - 0.06*theta3/(-theta3**2 + 1) - 0.03*theta4/(-theta3*theta4 + 1) + 0.03*(-theta2 + 0.95)/(theta2*theta3 - 1) - 0.03/(-theta3 + 1),
    func8 = -0.09*beta4*theta1**2/(-theta1*theta4 + 1) - 0.09*beta4*theta2**2/(-theta2*theta4 + 1) - 0.09*beta4*theta3**2/(-theta3*theta4 + 1) - 0.09*beta4*theta4**2/(-theta4**2 + 1) - 0.09*beta4/(-theta4**2 + 1) - 0.09*beta4/(-theta4 + 1) - 0.23*theta1/(-theta1*theta4 + 1) - 0.23*theta2/(-theta2*theta4 + 1) - 0.23*theta3/(-theta3*theta4 + 1) - 0.46*theta4/(-theta4**2 + 1) + 0.23*(-theta2 + 0.95)/(theta2*theta4 - 1) - 0.23/(-theta4 + 1)
    return func1,func2,func3,func4,func5,func6,func7,func8

x0 = [0.8,0.8,0.8,0.8,0.8,0.6,0.5,0.7]
result = fsolve(f,x0)

我正在尝试解决上面的等式,但它显示:

  

TypeError:f()缺少7个必需的位置参数:'theta2','theta3','theta4','beta1','beta2','beta3'和'beta4'

。关于我做错了什么以及我应该怎样做才能解决问题的任何想法?

1 个答案:

答案 0 :(得分:1)

您需要进行两项更改才能使其正常工作。

  1. 将功能更改为:

    def f(x0):
        theta1, theta2, theta3, theta4, beta1, beta2, beta3, beta4 = x0
    
  2. funcX

  3. 中删除尾随逗号

    然后结果是:

    [-0.30288717 -0.42512799 -0.42004936 -0.41683512 -0.06015582  0.09188239
      0.00146244  0.00425686]