python - Euler function not giving results -
we have programmed euler function study population changes.
he used while
loop keep our values in biological range (no births, etc.). when run script, plot axis range -0.6 +0.6 , no graph drawn.
does know wrong code?
t=np.zeros((n+1)) in range (n): t[i+1]=t[i]+dt s = np.zeros((n+1)) z = np.zeros((n+1)) r = np.zeros((n+1)) s[0] = n-1 z[0] =1 i=0 while s[i]>0 , s[i] <n , z[i] < n , z[i] > 0 , r[i] >0 , r[i] <n , i<n: s[i+1] = s[i]+dt*(-b*s[i]*z[i]) z[i+1] = z[i]+dt*(b*s[i]*z[i]-a*z[i]) r[i+1] = r[i]+dt*(a*z[i]) i=i+1 self.trace(t,s,r,z,i) def trace(self,t, s, r, z, i): plt.plot(t[:i],s[:i],'b') plt.plot(t[:i],z[:i],'r') plt.plot(t[:i],r[:i],'y') plt.show()
i see r
initialized as:
r = np.zeros((n+1))
then in while loop conditions require r[i] >0
.
since i=0
, r[i]=0
, condition false loop not execute.
perhaps missing initialization of r[0] = ...
Comments
Post a Comment