RuntimeWarning: invalid value encountered in divide

前端 未结 4 1757
野的像风
野的像风 2021-01-30 06:00

I have to make a program using Euler\'s method for the \"ball in a spring\" model

from pylab import*
from math import*
m=0.1
Lo=1
tt=30
k=200
t=20
g=9.81
dt=0.01         


        
4条回答
  •  遇见更好的自我
    2021-01-30 06:42

    Python indexing starts at 0 (rather than 1), so your assignment "r[1,:] = r0" defines the second (i.e. index 1) element of r and leaves the first (index 0) element as a pair of zeros. The first value of i in your for loop is 0, so rr gets the square root of the dot product of the first entry in r with itself (which is 0), and the division by rr in the subsequent line throws the error.

提交回复
热议问题