python:brentq优化

2024-05-18 23:43:34 发布

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

我的代码有一些非常恼人的问题。 我认为我的问题是,在最小壁厚部分(wtMIN)下,我在一个最优值内计算一个最优值。答案会收敛到某个值,但在这个转换过程中,brentq函数所需的零会移开计算边界。你知道吗

 def wtMIN(self,diameter):
    '''
    #here the minimum required wallthickness is calculated for a given diameter
    #Firstly the minimum diameter required to overcome stresses is calculated
    #Since inertia increases to the power of 4 this optimisation always leads to 
    #very large diameter and very small wall thickness, this causes the structure
    #to buckle.
    #Therefore a bucking check is done to see if the structure would buckle
    #Under de BuckOk check. If the structure would buckle a smaller diameter is
    #used and the buckling calculation is made again up untill a diameter and wall
    #thickness if found were no buckling occurs.
    #This buckling optimization cant be done with an optimizer since the
    #function is not contintous.
    '''
    try:
        diameter=diameter[0]
    except TypeError:
        diameter=diameter
    D=diameter
    wt=brentq(self.stressRATIO,D/10000,D/3,args=(D),xtol=0.001)
    buckOK = 'False'
    while buckOK == 'False':
        buckOK=self.buckcheck(D,wt)
        if buckOK == 'False':
            D=D-0.01
            wt=brentq(self.stressRATIO,D/10000,D/3,args=(D),xtol=0.001)
    return wt

再次,我认为这里的问题是,D=D-01回路想要找到最小屈曲直径,导致最佳值在brentq范围之外移动(我得到一个值误差,f(a)和f(b)需要有不同的符号。你知道吗

有人知道怎么解决这个问题吗?这已经折磨了我四个多星期了

桑克斯


Tags: andthetoselffalseifisstructure

热门问题