尝试在scipy中使用对分优化器时出现浮点错误

2024-09-29 21:27:36 发布

您现在位置:Python中文网/ 问答频道 /正文

我在使用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

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


Tags: 代码inpyimportaslinezerosscipy

热门问题