CoCalc SharedHomework 2- Maya Schuster.sagewsOpen in CoCalc
Description: Homework 2- Maya Schuster
Author: Maya Schuster
#Further Exercises 4.3.6
#a
var("S,P")
t=srange(0,100,0.1)
sol=desolve_odeint([0.5-(0.23*S*(P)^2), (0.23*S*(P)^2)-(0.4*P)], ics=[1,5], dvars=[S,P], times=t) #First set of initial conditions
list_plot(zip(t, sol[:,0]), plotjoined=True) + list_plot(zip(t,sol[:,1]), color="red", axes_labels=["Time","S/P"], plotjoined=True)

(S, P) var("S,P")
t=srange(0,100,0.1)
sol=desolve_odeint([0.5-(0.23*S*(P)^2), (0.23*S*(P)^2)-(0.4*P)], ics=[10,25], dvars=[S,P], times=t) #Second set of initial conditions
list_plot(zip(t, sol[:,0]), plotjoined=True) + list_plot(zip(t,sol[:,1]), color="red", axes_labels=["Time","S/P"], plotjoined=True)

(S, P) var("S,P")
t=srange(0,100,0.1)
sol=desolve_odeint([0.5-(0.23*S*(P)^2), (0.23*S*(P)^2)-(0.4*P)], ics=[9,3], dvars=[S,P], times=t) #Third set of initial conditions
list_plot(zip(t, sol[:,0]), plotjoined=True) + list_plot(zip(t,sol[:,1]), color="red", axes_labels=["Time","S/P"], plotjoined=True)

(S, P) #This system has oscillatory behavior, and as the initial values of S and P increases, the height/steepness of the oscillations decrease.

#b
var("S","P")
@interact
def interactive(V=(0.48,0.6)):
t=srange(0,200,0.1)
sol=desolve_odeint([V-(0.23*S*(P^2)), (0.23*S*(P)^2)-(0.4*P)], ics=[1,5], dvars=[S,P], times=t)
p=list_plot(zip(t,sol[:,0]), axes_labels=["time","S/P"], plotjoined=True, legend_label=["S"])+list_plot(zip(t,sol[:,1]), color="green", legend_label=["P"],plotjoined=True)
show (p)

(S, P)
#There starts to be persistent oscillations around V0=0.5