. Advertisement .
..3..
. Advertisement .
..4..
This is the program I run:
from pylab import*
from math import*
m=0.1
Lo=1
tt=30
k=200
t=20
g=9.81
dt=0.01
n=int((ceil(t/dt)))
km=k/m
r0=[-5,5*sqrt(3)]
v0=[-5,5*sqrt(3)]
a=zeros((n,2))
r=zeros((n,2))
v=zeros((n,2))
t=zeros((n,2))
r[1,:]=r0
v[1,:]=v0
for i in range(n-1):
rr=dot(r[i,:],r[i,:])**0.5
a=-g+km*cos(tt)*(rr-L0)*r[i,:]/rr
v[i+1,:]=v[i,:]+a*dt
r[i+1,:]=r[i,:]+v[i+1,:]*dt
t[i+1]=t[i]+dt
#print norm(r[i,:])
plot(r[:,0],r[:,1])
xlim(-100,100)
ylim(-100,100)
xlabel('x [m]')
ylabel('y [m]')
show()
After I run, it returns an error
a=-g+km*cos(tt)*(rr-L0)*r[i,:]/rr
RuntimeWarning: invalid value encountered in divide
Does anyone have any suggestions for my problem: runtimewarning: invalid value encountered in true_divide in the programs. How to correct it?
I have some recommendation for your problem
The output is:
Divide
rr
, which could be 0.0. You can checkrr
to see if it is zero.Your code may be trying to “divide zero” or “divide NaN”. You can do this if you’re aware of it and don’t mind it.