weixin_45231150
Dr.yyl
采纳率0%
2021-02-27 22:41

Python做计算中出现的奇怪报错

模拟晶体的螺旋生长中,用ndarray数组迭代,在计算到几百步后,开始报错:

D:/PycharmProjects/yyl1.py:91: RuntimeWarning: overflow encountered in double_scalars
  +dt*(math.sin(pi*(phi[i,j]-phi_s(midx-i*h,midy-j*h)))+l*U[i,j]*(1+math.cos(pi*(phi[i,j]-phi_s(midx-i*h,midy-j*h)))))
D:/PycharmProjects/yyl1.py:92: RuntimeWarning: overflow encountered in double_scalars
  sum_U[i,j]=10*(dt/(h**2))*(U[i+1,j]-2*U[i,j]+U[i-1,j]+U[i-1,j+1]-2*U[i,j]+U[i+1,j-1]+U[i+1,j+1]-2*U[i,j]+U[i-1,j-1]+U[i-1,j+1]-2*U[i,j]+U[i+1,j-1])+F*dt
Traceback (most recent call last):
  File "D:/PycharmProjects/yyl1.py", line 91, in <module>
    +dt*(math.sin(pi*(phi[i,j]-phi_s(midx-i*h,midy-j*h)))+l*U[i,j]*(1+math.cos(pi*(phi[i,j]-phi_s(midx-i*h,midy-j*h)))))
ValueError: math domain error

Process finished with exit code 1


 

求大神解决

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

1条回答

  • Brentbin Brentbin 21天前

    估计是哪里出异常值了

    个人感觉可能是在h**2这里

    因为这句:

    overflow encountered in double_scalars

    而这个报错会产生inf

    由inf可以导致math domain error

    点赞 评论 复制链接分享