CoCalc Shared Filesgraded-Lab 8 / Lab8-turnin.sagews
Views : 73
# Lab 1:

# Name:
# I worked on this code with:

# Please do all of your work for this week's lab in this worksheet. If
# you wish to create other worksheets for scratch work, you can, but
# this is the one that will be graded. You do not need to do anything
# to turn in your lab. It will be collected by your TA at the beginning
# of (or right before) next week’s lab.

# Be sure to clearly label which question you are answering as you go and to
# use enough comments that you and the grader can understand your code.1


# 1
#The equilibrium points are when R and J are both equal to zero
# R is equal to zero when it is equals to (bJ)/a
# J is equal to zero when it is equals to (-cR)/d

#2
var("a")
var("b")
var("c")
var("d")
var("R")
var("J")

a b c d R J
#3
ListRJ=[(1,1),(2,4),(-2,3),(-4,5),(-5,-6),(-2,-8),(4,-6),(3,-9)]

#4
a=4
d=4
b=.5
R_prime(R,V)=a*R
J_prime(R,V)=d*J
fig1= plot_vector_field((R_prime,J_prime),(R,-10,10),(J,-10,10),axes_labels=['R','J'])
show(fig1)
#this equilibrium is unstable

#5
a=-4
d=-4
b=.5
R_prime(R,J)=a*R
J_prime(R,J)=d*J
fig1= plot_vector_field((R_prime,J_prime),(R,-10,10),(J,-10,10),axes_labels=['R','J'])
show(fig1)
#this equilibrium is stable

#6
#The first one is when they both have feelings and the second one is when neither of tehm have feelings

#7
a=4
d=-4
b=.5
R_prime(R,V)=a*R
J_prime(R,V)=d*J
fig1= plot_vector_field((R_prime,J_prime),(R,-10,10),(J,-10,10),axes_labels=['R','J'])
show(fig1)
#this saddle point equilibrium is unstable

#8
a=4
d=4
b=.5
R_prime(R,V)=a*R
J_prime(R,V)=d*J
fig1= plot_vector_field((R_prime,J_prime),(R,-10,10),(J,-10,10),axes_labels=['R','J'])
point((0,0),color="red",size=1000)+fig1

#9
#This is a saddle point and therefore is unstable

#10
a=3
d=4
var("R", "J")
t1 = srange(0,10,0.1)
sol=desolve_odeint([a*R], ics=[100], dvars=[R], times=t)
t2 = srange(0,10,.1)
sol2=desolve_odeint([d*J],ics=[100], times=t, dvars=[J])
list_plot(zip(t,sol), axes_labels=["R","J "],color="red")+list_plot(zip(t2,sol2), axes_labels=["R","J"])

(R, J)
#11
b=4
c=4
R_prime(R,J)=b*J
J_prime(R,J)=c*R
fig1= plot_vector_field((R_prime,J_prime),(R,-10,10),(J,-10,10),axes_labels=['R','J'])
show(fig1)
#this shows an unstable saddle equilibrium point

#12
b=-4
c=-4
R_prime(R,J)=b*J
J_prime(R,J)=c*R
fig1= plot_vector_field((R_prime,J_prime),(R,-10,10),(J,-10,10),axes_labels=['R','J'])
show(fig1)

#The equilibrium is still an unstable saddle point just going in the opposite direction

#13
b=4
c=-4
R_prime(R,J)=b*J
J_prime(R,J)=c*R
fig1= plot_vector_field((R_prime,J_prime),(R,-10,10),(J,-10,10),axes_labels=['R','J'])
show(fig1)
#this equilibrium point shows a stable spiral

#14
b=4
c=-4
R_prime(R,J)=b*J
J_prime(R,J)=c*R
fig1= plot_vector_field((R_prime,J_prime),(R,-10,10),(J,-10,10),axes_labels=['R','J'])
point((0,0),color="red",size=1000)+fig1

#15
#the equilibrium is stable becuase the trajectory is spiraling around the equilibrium point, getting closer and closer to the point

#16
b=3
c=4
var("R", "J")
t1 = srange(0,10,0.1)
sol=desolve_odeint([b*J], ics=[100], dvars=[J], times=t)
t2 = srange(0,10,.1)
sol2=desolve_odeint([c*R],ics=[100], times=t, dvars=[R])
list_plot(zip(t,sol), axes_labels=["R","J "],color="red")+list_plot(zip(t2,sol2), axes_labels=["R","J"])

(R, J)
b=3
c=4
var("R", "J")
t1 = srange(0,10,0.1)
sol=desolve_odeint([b*J], ics=[10], dvars=[J], times=t)
t2 = srange(0,10,.1)
sol2=desolve_odeint([c*R],ics=[100], times=t, dvars=[R])
list_plot(zip(t,sol), axes_labels=["R","J "],color="red")+list_plot(zip(t2,sol2), axes_labels=["R","J"])

(R, J)
#10 part two
a=3
d=4
var("R", "J")
t1 = srange(0,10,0.1)
sol=desolve_odeint([a*R], ics=[5], dvars=[R], times=t)
t2 = srange(0,10,.1)
sol2=desolve_odeint([d*J],ics=[100], times=t, dvars=[J])
list_plot(zip(t,sol), axes_labels=["R","J "],color="red")+list_plot(zip(t2,sol2), axes_labels=["R","J"])

(R, J)
#17
b=4
c=-4
R_prime(R,J)=b*J
J_prime(R,J)=c*R
fig1= plot_vector_field((R_prime,J_prime),(R,-10,10),(J,-10,10),axes_labels=['R','J'])
t1 = srange(0,10,0.1)
sol=desolve_odeint([b*J], ics=[5], dvars=[R], times=t)
t2 = srange(0,10,.1)
sol2=desolve_odeint([c*R],ics=[100], times=t, dvars=[J])
list_plot(zip(t,sol), axes_labels=["R","J "],color="red")+list_plot(zip(t2,sol2), axes_labels=["R","J"])
show (fig1+list_plot)

#18
b=4
c=-4
R_prime(R,J)=J
J_prime(R,J)=-R+.05J
fig1= plot_vector_field((R_prime,J_prime),(R,-10,10),(J,-10,10),axes_labels=['R','J'])
t1 = srange(0,10,0.1)
sol=desolve_odeint([b*J], ics=[5], dvars=[R], times=t)
t2 = srange(0,10,.1)
sol2=desolve_odeint([c*R],ics=[100], times=t, dvars=[J])
list_plot(zip(t,sol), axes_labels=["R","J "],color="red")+list_plot(zip(t2,sol2), axes_labels=["R","J"])
list_plot+fig1

#in this tiem series plot as one individuals love begins to increase the others love will decrease.

#19 This term is appropriately because the values are getting closer and closer to the quilibrium point, as a resultt, it is a stable spiral.

#20
b=4
c=-4
R_prime(R,J)= J
J_prime(R,J)=-R+.05*J
fig1= plot_vector_field((R_prime,J_prime),(R,-10,10),(J,-10,10),axes_labels=['R','J'])
var("R", "J")
t1 = srange(0,10,0.1)
sol=desolve_odeint([b*J], ics=[10], dvars=[J], times=t)
t2 = srange(0,10,.1)
sol2=desolve_odeint([c*R],ics=[100], times=t, dvars=[R])
list_plot(zip(t,sol), axes_labels=["R","J "],color="red")+list_plot(zip(t2,sol2), axes_labels=["R","J"])
show(fig1)+show(list_plot)

(R, J)
<function list_plot at 0x7f56474212a8>
Error in lines 12-12 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> TypeError: unsupported operand type(s) for +: 'NoneType' and 'NoneType'
#21
b=4
c=-4
R_prime(R,J)=J
J_prime(R,J)=-R+.05*J
fig1= plot_vector_field((R_prime,J_prime),(R,-10,10),(J,-10,10),axes_labels=['R','J'])
t1 = srange(0,10,0.1)
sol=desolve_odeint([b*J], ics=[5], dvars=[R], times=t)
t2 = srange(0,10,.1)
sol2=desolve_odeint([c*R],ics=[100], times=t, dvars=[J])
list_plot(zip(t,sol), axes_labels=["R","J "],color="red")+list_plot(zip(t2,sol2), axes_labels=["R","J"])
list_plot+fig1
#in this tiem series plot as one individuals love begins to increase the others love will decrease.

#This is a semi stable equilibrium because the value first head towards the equilibrium point and then away from it

#4.2.1
var("H")
var("P")
var("G")
k1=.2
k2=.2
k3=.2
n=2
t=srange(0,100,.1)
Pprime=(H-(k2*P))
Gprime=(P-(k3*G))
Hprime=((1/(1+G^n)))-k1*H
sol=desolve_odeint([Hprime,Pprime,Gprime],ics=[1,1,1],dvars=[H,P,G],times=t)
list_plot(zip(t,sol[:,0]), plotjoined=True)+list_plot(zip(t,sol[:,1]), plotjoined=True,color="pink")+list_plot(zip(t,sol[:,2]),plotjoined=True,color="red")

H P G
var("H")
var("P")
var("G")
k1=.2
k2=.2
k3=.2
n=50
t=srange(0,100,.1)
Pprime=(H-(k2*P))
Gprime=(P-(k3*G))
Hprime=((1/(1+G^n)))-k1*H
sol=desolve_odeint([Hprime,Pprime,Gprime],ics=[1,1,1],dvars=[H,P,G],times=t)
list_plot(zip(t,sol[:,0]), plotjoined=True)+list_plot(zip(t,sol[:,1]), plotjoined=True,color="pink")+list_plot(zip(t,sol[:,2]),plotjoined=True,color="red")

H P G
#4.2.2
n=15
t=srange(0,100,.1)
Pprime=(H-(k2*P))
Gprime=(P-(k3*G))
Hprime=((1/(1+G^n)))-k1*H
sol=desolve_odeint([Hprime,Pprime,Gprime],ics=[1,5,7],dvars=[H,P,G],times=t)
sol=desolve_odeint([Hprime,Pprime,Gprime],ics=[1,1,1],dvars=[H,P,G],times=t)
list_plot(zip(t,sol[:,0]), plotjoined=True)+list_plot(zip(t,sol[:,1]), plotjoined=True,color="pink")+list_plot(zip(t,sol[:,2]),plotjoined=True,color="red")

Error in lines 3-3 Traceback (most recent call last): File "/cocalc/lib/python2.7/site-packages/smc_sagews/sage_server.py", line 1234, in execute flags=compile_flags), namespace, locals) File "", line 1, in <module> NameError: name 'H' is not defined
#4.2.3
var("H")
var("G")
k1=.2
k2=.2
k3=.2
n=5
t=srange(0,100,.1)
Gprime=P-(k3*G)
Hprime=((1/(1+(G^n)))-k1*H)
sol=desolve_odeint([Hprime,Gprime],ics=[1,1],dvars=[H,G],times=t)
list_plot(zip(t,sol[:,0]), plotjoined=True)+list_plot(zip(t,sol[:,1]), plotjoined=True,color="pink")

H G