# Lab 8 # Name: Esha Harwalkar # 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 r = 0.2 K = 100 A = 8 f(N)= 0.2*N *(1-(N/100))*((N/8)-1) #define the mathematical function f(0) f(A) f(K)
0
0
0
#2: possibleEqlist = [0, 3,5,8, 25, 50, 100] #create a list of possible equilibrium values Eqlist = [] #create an empty list for the actual equilibrium values for i in possibleEqlist: #for each value in the possible Eq list if f(i) == 0: #if f(i) equals 0 (f(N) function from #1) Eqlist.append(i) #add that i value to the actual equilibrium values list b = Eqlist #assign a variable to the list of actual equilibrium values b #call the function
[0, 8, 100]
#3 t = srange(0,200) #define what the times list is sol = desolve_odeint(f(N),times = t, ics = [5], dvars=N) #simulate a differential equation (f(N)) with initial condition of 5. list_plot(sol, plotjoined = True) #plot the simulation
in this graph we see that when N = 5, the system wants to return to 0, which shows that 0 is a stable point. It is going AWAY from the next equilibrium value of 8 and TOWARDS 0.
sol = desolve_odeint(f(N),times = t, ics = [50], dvars=N) #simulate a differential equation (f(N)) with initial condition of 50. list_plot(sol, plotjoined = True) #plot the simulation
in this graph we see that when N = 50, the system wants to go towards 100. Since the arrows to the left AND right of the equilibrium at N=8 are pointing away from the Eq. point, we can confirm that the Eq. point at N = 8 is UNSTABLE.
sol = desolve_odeint(f(N),times = t, ics = [110], dvars=N) #simulate a differential equation (f(N)) with initial condition of 110. list_plot(sol, plotjoined = True) #plot the simulation
in this graph, we see that when N = 110 ("to the right of N = 100"), the system wants to return to 100. This means that the arrows to the left and right of the Eq. point at N = 100 are pointing TOWARDS the Eq. point, so this Eq, point at N = 100 is STABLE.
#4 if (f(N) < 0 and N < b) and (f(N) > 0 and N > b): #if the change vectors point to the left of the Eq point (when N is less than the Eq point) and the change vectors point to the right of the Eq point (when N is greater than the Eq point) print "This is an unstable point" elif (f(N) > 0 and N <b) and (f(N) < 0 and N > b) : #if the change vectors point to the right of the Eq point (when N is less than the Eq point) and the change vectors point to the left of the Eq point (when N is greater than the Eq point) print "This a stable point" else: print "This is a semi-stable point"
#5 def myfunction(f, before_b, after_b): #the before and after b is the same thing as I wrote about with "N<b" or "N > b" if f(before_b) < 0 and f (after_e) > 0: #the same as I did in #4 for the rest of the body of this code print "this is an unstable equilibrium point" elif f(before_b) > 0 and f(after_b) < 0: print "this is a stable equilibrium point" else: print "this is a semi-stable point" f(N)= 0.2*N *(1-(N/100))*((N/8)-1) #define the mathematical function myfunction(f, 50, 110) #picked two values for N that are to the left and right of an EQ point of 100
this is a stable equilibrium point
#6 derivative(N) = diff(f, N) #takes derivative of f(N) . This is really just taking the derivative of the original differenial equation derivative
N |--> -0.000250000000000000*(N - 8)*(N - 100) - 0.000250000000000000*(N - 8)*N - 0.000250000000000000*(N - 100)*N
#7 if derivative(b[0]) == 0: #plug in the first value of the equilibrium point list b print "Test failed"
the test didn't fail because the second derivative of the Eq point I inserted, was not equal to 0
derivative(b[1]) #the value outputted will give us the result of plugging in the second value in the b list (which is 8) into the second derivative equation
0.184000000000000
derivative(b[2])#the value outputted will give us the result of plugging in the third value in the b list (which is 100) into the second derivative equation
-2.30000000000000
derivative(b[0])#the value outputted will give us the result of plugging in the first value in the b list (which is 0) into the second derivative equation
-0.200000000000000
b
[0, 8, 100]
#8 list = [0,8,100] for i in list: if derivative(i) < 0: #plug in the first value of the equilibrium point list b print "stable" else derivative(i)> 0: print "unstable"
#9 new_list = [0,8,100] def newfunction (Nprime, new_list): for i in list: if derivative(i) < 0: #plug in the first value of the equilibrium point list b print "stable" if derivative(i) > 0: print "unstable" newfunction (Nprime(N),new_list)
Error in lines 8-8
Traceback (most recent call last):
File "/cocalc/lib/python2.7/site-packages/smc_sagews/sage_server.py", line 1188, in execute
flags=compile_flags) in namespace, locals
File "", line 1, in <module>
NameError: name 'Nprime' is not defined