SharedLab 10 / Lab 10.sagewsOpen in CoCalc
Lab 10
# Lab 10

# Name:Michele Shi
# 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 put each exercise in a new cell with an exercise number at the top.
# Label axes on all graphs.

#6 plotting function x^2+y^2 and the tangent plane that passes through (1,-1,2)
#z=k1x+k2y k1 and k2 are slopes. When x=0, the tangent line to x^2 is just f(x)=x and when y=0, tangent line to y^2 is just f(y)=y. so k1 and k2 are equal to 1  (derivative of x^2 is just x and at point (1,-1,2))
var("x,y")
plot3d(x^2+y^2,(x,-10,10),(y,-10,10),color="aqua",opacity=.4)+point3d((1,-1,2),color="purple",size=10)+plot3d(x+y,(x,-10,10),(y,-10,10),color="orange",opacity=.4)

(x, y)
3D rendering not yet implemented

#8 plot vector field for Holling tanner model
var("x","y")
r=0.2
Xprime=(r*x)*(1-(x/7))-(x/(1+x))*y
Yprime=(1/10)*y*(1-(y/x))
eqns=[Xprime,Yprime]
t=srange(0,100,.1)
sol=desolve_odeint(eqns,ics=[10,10],times=t,dvars=[x,y])
plot_vector_field([Xprime,Yprime],(x,-10,10),(y,-10,10))+point((.239,.24),size=10)+list_plot(sol,plotjoined=true)

(x, y)
#This equilibrium point is a stable spiral.

#9 computing the jacobian for the holling tanner model. assign the result to a variable J and "show"

J=jacobian([Xprime,Yprime],[x,y])
J

[-0.0571428571428571*x - y/(x + 1) + x*y/(x + 1)^2 + 0.200000000000000 -x/(x + 1)] [ 1/10*y^2/x^2 -1/5*y/x + 1/10]
#10 substitute equilibrium values of x and y into the jacobian. then compute eigen values and classify the equilibrium

J.subs({x:.239,y:.24})

[0.0300033894396598 -0.192897497982244] [ 0.100838570753313 -0.100836820083682]
random=matrix(RDF,[[0.0300033894396598,-0.192897497982244],[0.100838570753313, -0.100836820083682]])
random2=random.eigenvectors_right()
random2

[(-0.0354167153220111 + 0.12317352755925914*I, [(0.8103724317254524, 0.2748332660298634 - 0.5174584019829371*I)], 1), (-0.0354167153220111 - 0.12317352755925914*I, [(0.8103724317254524, 0.2748332660298634 + 0.5174584019829371*I)], 1)]
#since both eigenvalues are complex conjugates both with negative real parts, the equilibrium point is a stable spiral.

#11
var("x,y")
eqn1=0.0300033894396598*x -0.192897497982244*y
eqn2=0.100838570753313*x-0.100836820083682*y
plot_vector_field([eqn1,eqn2],(x,-10,10),(y,-10,10))

(x, y)
#Compared to the nonlinear system, this new vector field looks like all points will approach this. It is not as messy since the nonlinear system can have multiple equilibrium points but only approaching one. This system shown above has only one equilibrium point.