Python 尝试在scipy中使用对分优化器时发生浮点错误

Python 尝试在scipy中使用对分优化器时发生浮点错误,python,optimization,scipy,Python,Optimization,Scipy,我在scipy中使用对分优化器时遇到问题。以下是我的代码的相关部分: 我是怎么进口东西的 import numpy as np import scipy.optimize as sp import matplotlib.pyplot as plt 插入代码,导致以下错误的部分 #All variables are previously defined except for h def BeamHeight(h): x = 1000e3*M[i]*h/(fw*h^3-(fw-wt)(h-

我在scipy中使用对分优化器时遇到问题。以下是我的代码的相关部分:

我是怎么进口东西的

import numpy as np
import scipy.optimize as sp
import matplotlib.pyplot as plt
插入代码,导致以下错误的部分

#All variables are previously defined except for h
def BeamHeight(h):
    x = 1000e3*M[i]*h/(fw*h^3-(fw-wt)(h-2*ft)^3) - Max_stress_steel
    return x
for i in range(0,50):
    h = np.zeros((50))  
    h[i] = sp.bisect(BeamHeight, hb, 5,xtol = 0.001)
导致此错误的原因:

Traceback (most recent call last):
  File "ShearMoment.py", line 63, in <module>
    h[i] = sp.bisect(BeamHeight, hb, 5,xtol = 0.001)
  File "/usr/lib/python2.7/dist-packages/scipy/optimize/zeros.py", line 248, in bisect
    r = _zeros._bisect(f,a,b,xtol,rtol,maxiter,args,full_output,disp)
  File "ShearMoment.py", line 58, in BeamHeight
    x = 1000e3*M[i]*h/(fw*h^3-(fw-wt)(h-2*ft)^3) - Max_stress_steel
TypeError: 'float' object is not callable
回溯(最近一次呼叫最后一次):
文件“ShearMoment.py”,第63行,中
h[i]=sp.bisect(束高,hb,5,xtol=0.001)
文件“/usr/lib/python2.7/dist packages/scipy/optimize/zeros.py”,第248行,对分
r=_零。_对分(f、a、b、xtol、rtol、maxiter、args、全输出、disp)
文件“剪切力矩.py”,第58行,梁高
x=1000e3*M[i]*h/(fw*h^3-(fw wt)(h-2*ft)^3)-最大应力钢
TypeError:“float”对象不可调用

我知道scipy.optimize需要一个函数作为其参数之一。我做得不对吗?

在Python中,串联不是隐式乘法,
^
不是指数运算。乘法必须用
*
明确表示,幂运算必须写成
**
波束高度的这一部分

fw*h^3-(fw-wt)(h-2*ft)^3
必须写为

fw*h**3-(fw-wt)*(h-2*ft)**3

在Python中,串联不是隐式乘法,
^
不是指数运算。乘法必须用
*
明确表示,幂运算必须写成
**
波束高度的这一部分

fw*h^3-(fw-wt)(h-2*ft)^3
必须写为

fw*h**3-(fw-wt)*(h-2*ft)**3