var('x,y,t')
xp = x*(1-x-y)
yp = y*(3/4-y-x/2)
a = -1.5
b = 2
c = -1.5
d = 1.5
G = plot_vector_field([xp,yp],(x,a,b),(y,c,d))
# plot x-nullclines
G += parametric_plot((0,t),(t,c,d),color='red',thickness=5)
G += plot(1-x,(x,a,b),color='red',thickness=5,ymin=c,ymax=d)
# plot y=nullclines
G += parametric_plot((t,0),(t,a,b),color='purple',thickness=5)
G += plot(3/4-x/2,(x,a,b),color='purple',thickness=5,ymin=c,ymax=d)
# find equlibria (where red and purple cross)
equs = solve([xp,yp],(x,y),soln_dict=true)
show("Equilibria locate at the following:")
for equ in equs:
show(equ[0], ", ", equ[1])
X = function('X')(t)
Y = function('Y')(t)
de1 = diff(X,t) - xp(x=X,y=Y) == 0
de2 = diff(Y,t) - yp(x=X,y=Y) == 0
npts = 50
@interact
def _(x0 = slider(a,b,0.1,1),y0 = slider(c,d,0.1,1)):
soln = desolve_system_rk4([xp,yp], [x,y], ics=[0,x0,y0],
ivar=t, end_points=npts)
H = Graphics()
for k in range(npts):
H += points((soln[k][1],soln[k][2]))
(G+H).show(figsize=(10,10))
|
Click to the left again to hide and once more to show the dynamic interactive window
|