CoCalc Public Fileslab5AnnaSteinnecker.sagewsOpen with one click!
Authors: Ashwin Joseph, Anna Steinnecker
Views : 82
s=var('R,J') t=srange(0,20,0.05) ic1=[.5,.6] ic2=[.5,-.2] ic3=[-.9,.6] ic4=[-.5,-.7] @interact def Romeo_Juliet(a=slider(-2,2,0.5,default=-1), b=slider(-2,2,0.5,default=0), c=slider(-2,2,0.5,default=0), d=slider(-2,2,0.5,default=-1)): titleeq= ("$R'= "+'%2.1f'%(a)+" R "+"%+2.1f"%(b)+" J$\n" +"$J' = "+'%2.1f'%(c)+" R "+"%+2.1f"%(d)+" J$") vector_field=[a*R+b*J,c*R+d*J] pv=plot_vector_field(vector_field,(R,-1,1),(J,-1,1),plot_points=11,axes_labels=["R","J"]) sol1=desolve_odeint(vector_field,times=t,ics=ic1,dvars=[R,J]) ps1=list_plot(sol1,plotjoined=True,color='blue')+disk(ic1,.03,(0,2*pi),color='blue') sol2=desolve_odeint(vector_field,times=t,ics=ic2,dvars=[R,J]) ps2=list_plot(sol2,plotjoined=True,color='red')+disk(ic2,.03,(0,2*pi),color='red') sol3=desolve_odeint(vector_field,times=t,ics=ic3,dvars=[R,J]) ps3=list_plot(sol3,plotjoined=True,color='green')+disk(ic3,.03,(0,2*pi),color='green') sol4=desolve_odeint(vector_field,times=t,ics=ic4,dvars=[R,J]) ps4=list_plot(sol4,plotjoined=True,color='purple')+disk(ic4,.03,(0,2*pi),color='purple') show(pv+ps1+ps2+ps3+ps4,xmin=-1,xmax=1,ymin=-1,ymax=1,aspect_ratio=1, title=titleeq,figsize=8,fontsize=20)
Interact: please open in CoCalc
vs=var("D,M") t=srange(0,50,0.05) Dmax=3.1 Mmax=2.5 @interact def Deer_Moose(r_D=slider(0,5,0.5,default=3,label="$r_D$"), r_M=slider(0,5,0.5,default=2,label="$r_M$"), alpha=slider(0,2,0.5,default=0.5,label="$\\alpha$"), D0=slider(0,Dmax,0.1,default=1,label="$D_0$"), M0=slider(0,Mmax,0.1,default=1,label="$M_0$")): titleeq=("$D'= " + '%2.1f'%(r_D) + " D - M D - D^2$\n " + "$M’= " + '%2.1f'%(r_M) + " M - " + '%2.1f'%(alpha) + " M D - M^2$") vector_field=[r_D*D-M*D-D^2,r_M*M-alpha*M*D-M^2] initial_value=[D0,M0] pv=plot_vector_field(vector_field,(D,0,Dmax),(M,0,Mmax), plot_points=11,axes_labels=["D","M"]) sol1=desolve_odeint(vector_field,times=t,ics=initial_value,dvars=[D,M]) ps1=list_plot(sol1,plotjoined=True,color='green',thickness=2) d1=disk(initial_value,.035,(0,2*pi),color='green') nullclines=( plot(r_D-D,(D,0,r_D),color="red",thickness=3)+plot(r_M-alpha*D,(D,0,r_M/alpha),color="blue",thickness=3))
Interact: please open in CoCalc
show(pv+ps1+d1+nullclines,xmin=0,xmax=Dmax,ymin=0,ymax=Mmax,aspect_ratio=1,title=titleeq,figsize=8,fontsize=20,svg=False) def Scale_vf(xy): scale=sqrt(5+xy[0]^2+xy[1]^2) return [xy[0]/scale,xy[1]/scale] vs=var("D,M") t=srange(0,50,0.05) Dmax=4.0 Mmax=3.5 @interact def Deer_Moose_norm(r_D=slider(0,5,0.5,default=3,label="$r_D$") r_M=slider(0,5,0.5,default=2,label="$r_M$"), alpha=slider(0,2,0.5,default=0.5,label="$\\alpha$"), D0=slider(0,Dmax,0.1,default=1,label="$D_0$"), M0=slider(0,Mmax,0.1,default=1,label="$M_0$")): titleeq=("$D'= " + ''%2.1f'%(r_D) + " D - M D - D^2$\n " +"$M'= " + ''%2.1f'%(r_M) + " M - " + ''%2.1f’%(alpha) + " M D - M^2$") vector_field=[r_D*D-M*D-D^2,r_M*M-alpha*M*D-M^2] initial_value=[D0,M0] pv=plot_vector_field(Scale_vf(vector_field),(D,0,Dmax),(M,0,Mmax),plot_points=11,axes_labels=["D","M"]) sol1=desolve_odeint(vector_field,times=t,ics=initial_value,dvars=[D,M]) ps1=list_plot(sol1,plotjoined=True,color='green',thickness=2) d1=disk(initial_value,.035,(0,2*pi),color='green') nullclines=(plot(r_D-D,(D,0,r_D),color="red",thickness=3) +plot(r_M-alpha*D,(D,0,r_M/alpha),color="blue",thickness=3)) show(pv+ps1+d1+nullclines,xmin=0,xmax=Dmax,ymin=0,ymax=Mmax,
*** WARNING: Code contains non-ascii characters *** Error in lines 0-1 Traceback (most recent call last): File "/cocalc/lib/python2.7/site-packages/smc_sagews/sage_server.py", line 1191, in execute flags=compile_flags), namespace, locals) File "", line 1, in <module> NameError: name 'pv' is not defined
aspect_ratio=1,title=titleeq,figsize=8,fontsize=20,svg=False)
Error in lines 0-1 Traceback (most recent call last): File "/cocalc/lib/python2.7/site-packages/smc_sagews/sage_server.py", line 1191, in execute flags=compile_flags), namespace, locals) File "<string>", line 1 aspect_ratio=Integer(1),title=titleeq,figsize=Integer(8),fontsize=Integer(20),svg=False) ^ SyntaxError: invalid syntax