询问有关优化 while 循环的建议

问题描述

这是关于 RKF method

的算法的一部分
t = self.a
x = np.array(self.x0)
h = self.hmax

T = np.array( [t] )
X = np.array( [x] )
k= [0]*6
while t < self.b:

    if t + h > self.b:
        h = self.b - t
    
    k[0] = h * self.f(t,x)
    k[1] = h * self.f(t + a2 * h,x + b21 * k[0] )
    k[2] = h * self.f(t + a3 * h,x + b31 * k[0] + b32 * k[1])
    k[3] = h * self.f(t + a4 * h,x + b41 * k[0] + b42 * k[1] + b43 * k[2])
    k[4] = h * self.f(t + a5 * h,x + b51 * k[0] + b52 * k[1] + b53 * k[2] + b54 * k[3])
    k[5] = h * self.f(t + a6 * h,x + b61 * k[0] + b62 * k[1] + b63 * k[2] + b64 * k[3] + b65 * k[4])
    r = abs( r1 * k[0] + r3 * k[2] + r4 * k[3] + r5 * k[4] + r6 * k[5] ) / h
    r = r / (self.atol+self.rtol*(abs(x)+abs(k[0])))
    if len( np.shape( r ) ) > 0:
        r = max( r )
    if r <= 1:
        t = t + h
        x = x + c1 * k[0] + c3 * k[2] + c4 * k[3] + c5 * k[4]
        T = np.append( T,t )
        X = np.append( X,[x],0 )
    h = h * min( max( 0.94 * sqrt(sqrt( 1 / r )),0.1 ),4.0 )
    if h > self.hmax:
        h = self.hmax
    elif h < self.hmin or t==t-h:
        raise RuntimeError("Error: Could not converge to the required tolerance.")
        break

哪个工作得很好,但我想知道是否有可能使它更快更有效?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)