You are on page 1of 12

S Venugopal LS 30B Lecture 3 & 4 (Winter 2021)

Final Exam
Useful Tips
• Meet and discuss how to approach the problems with your study group
members BEFORE you begin answering.
• Meet and discuss your answers AFTER you complete the exam.
• Make sure to upload your exams in a timely manner as instructed
below. The 48-hour exam is only to provide ample time to complete it,
keeping in mind that these are difficult times for students in more than
one way. Please do not procrastinate the exam or its upload until the
last minute.

Exam Instructions
• This is a take-home exam which needs to be completed in a 48-hour
period. You may use the course resources on CCLE site and your labs
on CoCalc as needed (but not elsewhere on the internet).

• You can type your answers. You can also digitally write on tablets etc.

• You are expected to collaborate with your study group. However, as


always, each student must show their work to receive full credit for each
problem. Collaboration outside the study group is regarding as
cheating. Also submitting the exact same document or answer by each
student of a study group will be considered cheating. To be safe, please
write/type your own answers and show simulated graphs as instructed
in the questions.

• If you have a question about the exam at any point during the exam
period, post a question publicly on Campuswire. If it is a private matter,
email Dr. V directly. Questions about content or your own progress, will
not be answered. Also, please do not post any screenshots of your
answers on CampusWire.

• Your answers must be uploaded as a single PDF on GradeScope by the


deadline posted. Late submissions will not be accepted unless
accompanied by a valid excuse.

• Please make sure to select the pages for the corresponding questions
during submission on Gradescope without fail. Thank you!
Statement of Academic Integrity
“As a student and member of the University community, you
are here to get an education and are, therefore, expected to
demonstrate integrity in your academic endeavors. All
students must uphold University of California Standards of
Student Conduct as administered by the Office of the Dean of
Students. Students are subject to disciplinary action for
several types of misconduct, including but not limited to:
cheating, multiple submissions, plagiarism, prohibited
collaboration, facilitating academic dishonesty, or knowingly
furnishing false information. In this exam, you are allowed to
use the class resources posted on CCLE and collaborate with
only your pre-assigned study group members. Violations of
the Student Conduct Code may result in serious
consequences such as suspension or dismissal. For more
information about academic integrity, please visit
www.deanofstudents.ucla.edu."

ENTER YOUR FULL NAME TO ACKNOWLEDGE THAT YOU HAVE READ THE ABOVE
STATEMENT AND WERE NEITHER GIVEN NOR PROVIDED UNAUTHORIZED HELP ON
THIS EXAM.

Student’s Full Name: ______________________________________________________


Appreciating Study Group Peers (Extra Credit)
Mention the full names of the study group members who you
collaborated with on this exam. Those students will receive
two points in extra credit for this exam.
1. [25 points] Stable Oscillations and Chaos.

1.1. Some species of insects have populations that follow a delayed version of logistic growth
differential equation like the one given below:

𝑁(𝑡 − 𝜏) 𝑁(𝑡)𝑛
𝑁 ′ (𝑡) = 𝑟𝑁(𝑡 − 𝜏) (1 − )−𝛽( )
𝑘 1 + 𝑁(𝑡)𝑛

For 𝑡 ≤ 0, 𝑁(𝑡) = 10. Given 𝑟 = 0.2 , 𝑘 = 1000, 𝛽 = 0.1, 𝑛 = 10.

a) (10 points) With 𝜏 = 1.5, what happens to the insect population at 𝑡 = 200 time units. Simulate
the model in CoCalc using the code given below. Show your simulated time series graph in your
answer. No need to provide your code in this answer! Hint: For importing graphs from CoCalc, see
APPENDIX I.

-------------------------------------- Code for dde_solve() ---------------------------------------------------

%auto
def dde_solve(dde, statevar, delayedvars, history, tmax,
timestep):
# Check validity of delays.
if min(delayedvars.values()) < 0:
raise ValueError("This function will not work with
negative delays. "
"Consider consulting a fortune teller instead.")
if any(val<timestep for val in delayedvars.values()):
raise ValueError("Time step should not be larger than
delay.")

# Set up variables and delays.

delayedvars = delayedvars.items()
dde = dde.subs({v: statevar for v, delay in delayedvars
if delay == 0})
delayedvars = [(v, delay) for v, delay in delayedvars if
delay != 0]
allvars = [str(statevar)] + [str(v) for v, delay in
delayedvars]
delays = [delay for v, delay in delayedvars]

# Set up fast functions.


dde_func = fast_float(dde, *allvars)
history_func = fast_float(history, "t")

# Adjust the timestep if necessary


mindelay = min(delays) if delays else timestep
timestepcorrectionfactor = ceil(timestep / mindelay)
timestep /= timestepcorrectionfactor

# A function to perform history lookups.


def lookup(t):
"""Does a history lookup at each delay from t, stores
result in allvars[1:]"""
for i, delay in enumerate(delays):
if t - delay <= 0:
allvars[i+1] = history_func(t - delay)
else:
r = (t - delay) / timestep
n = floor(r)
r -= n
allvars[i+1] = result[n]*(1 - r) + result[n
+ 1]*r

# Set up for the first iteration.


result = [history_func(0)]
lookup(0)
for t in sxrange(0, tmax - timestep, timestep):
# Compute k1. Note history lookup has already been
done.
allvars[0] = result[-1]
k1 = dde_func(*allvars)
# Compute k2.
lookup(t + timestep/2)
allvars[0] += timestep/2 * k1
k2 = dde_func(*allvars)
# Compute k3. Note history lookup has already been
done.
allvars[0] = result[-1] + timestep/2 * k2
k3 = dde_func(*allvars)
# Compute k4.
lookup(t + timestep)
allvars[0] = result[-1] + timestep * k3
k4 = dde_func(*allvars)
# Finally, compute the RK4 weighted average.
result.append(result[-1] + (k1 + 2*k2 + 2*k3 + k4)/6
* timestep)
return result[::timestepcorrectionfactor]
-------------------------------------------------------------------------------------------------------------------

-------------------------- Code for the model ----------------------------------------------------------------

#Create the variables and their values


var("N", "N_tau")
r = 0.2
k = 1000
beta = 0.1

n=10

tau = 1.5
max_time = 200
tstep = 0.1
t = srange(0,max_time,tstep)

Nprime = r*N_tau*(1-(N_tau/k))-beta*(N^n/(1+N^n)) #Create


dde
delay = {N_tau: tau} #Tell the computer what variable is tau
#Simulate and plot
sol = dde_solve(Nprime,N,delay, history = 10, tmax =
max_time, timestep = tstep)
list_plot(list(zip(t, sol)), plotjoined = true, axes_labels
= ["Time","Insect Population"])
---------------------------------------------------------------------------------------------------------------

b) (3 points) As you must know, a delay differential equation can produce stable oscillations when
the delay, 𝜏, of the negative feedback, and the steepness of this feedback are high enough. Now,
reason which model parameter would you modify to increase the steepness of the negative feedback
in this model. Hint: You may use the code above which you used to simulate the model in CoCalc
and tweak the different model parameter values to see if they cause oscillations.

c) (3 points) Suppose you figured out the steepness parameter in (b), show a simulated time series
graph of oscillations in your answer and indicate what value was used for the steepness parameter.
Hint: For importing graphs from CoCalc, see APPENDIX I.
1.2. (9 points) Romeo and Juliet’s love are always distorted by external factors. This time, Romeo’s
attraction goes awry when Juliet’s nurse gets involved. Since the nurse is involved, it makes sense
to model the characters’ happiness rather than their attraction to each other. With that, we have the
following assumptions.

– Juliet loves her nurse and wants to be exactly as happy as the nurse herself is. So 𝐽′ = 𝑠(𝑁 − 𝐽).
– The nurse is similarly attached to Juliet and her happiness grows in proportion to Juliet’s.
However, she is a bit of a worrywart, and her happiness causes itself to decline. She is also worried
about Juliet’s developing relationship with Romeo, so whenever their emotions are in sync, her
happiness drops precipitously. Thus, 𝑁 ′ = 𝑟𝐽 − 𝑁 − 𝑅𝐽.
– Finally, Romeo just wants his life to be simple. When Juliet and the nurse have different emotions,
he finds it hard to deal with them, but he does not actually care whether they are happy or not. Also,
his happiness causes itself to decline, just as in the case of the nurse. So 𝑅 ′ = 𝐽𝑁 − 𝑏𝑅.

a) (6 points) Simulate this model using the parameter values s = 10, b = 8/3, and r = 28, with the
initial conditions J(0) = 0.1, N(0) = −6, and R(0) = 0.01. Using a step size of 0.01, plot a time series
and 3D trajectory. Show the plots in your answer sheet. Hint: Refer to your Lab 3. No need to
provide your code. See APPENDIX I for copying graphs from CoCalc into your answer sheets.

b) (3 points) Pick an initial point close to the original one and plot a trajectory and time series as
in the previous part. Overlay the plots for the two initial conditions. What do you observe?
2. [35 points] Discrete-Time Linear Systems
2.1. In a pond ecosystem, green algae produce energy from sunlight via photosynthesis, fish eat the
algae and consume some of that energy, and bacteria decompose the dead algae and fish to
obtain more of that energy. A discrete-time model can be set up to track the energy through such
an ecosystem as given below, where 𝐴 is the amount of energy in the algae, 𝐹 is the amount of
energy in the fish, and 𝐵 is the amount of energy in the bacteria.

𝐴𝑁+1 1.01 0 0 𝐴𝑁
( 𝐹𝑁+1 ) = [0.09 0.57 0 ] ( 𝐹𝑁 )
𝐵𝑁+1 0.03 0.07 0.36 𝐵𝑁

a) The above model was based on the following assumptions. Starting with these assumptions,
make a flow diagram (5 points) and arrive at the system of equations which result in the above
matrix model (5 points).

• For each joule of energy in the algae, the algae will produce an additional 0.25 joules each
day. (In short, ignoring other factors, the amount of energy in algae will increase by 25% per
day.)

• Each day, 12% of the energy in the algae is used up by the algae and leaves the ecosystem, an
additional 9% of it ends up in the fish who eat the algae, and an additional 3% of it ends up in
the bacteria who eat the dead algae.

• Each day, 36% of the energy in the fish is used up and leaves the ecosystem, and another 7%
of it goes to the bacteria.

• Each day, 64% of the energy in the bacteria is used up and leaves the ecosystem.

𝐴0 1 𝐴30
b) (12 points) Using an initial condition, ( 𝐹0 ) = (5), simulate the model to find ( 𝐹30 ).
𝐵0 8 𝐵30
Provide the time series graph in your answer and briefly explain in your own words, what is
happening to the energy flow in this food chain.

Hint: You may use the code below to simulate the model in CoCalc. (No need to re-insert this
code in your answer sheet). See APPENDIX I to get the graphs into your answer sheet.
-------------------------- Code for the model ----------------------------------------------------------------

M=zero_matrix(RDF,3,3) # Make zero matrix


M[0,0]=1.01
M[1,0]=0.09
M[1,1]=.57
M[2,0]=.03
M[2,1]=.07
M[2,2]=.36
show(M)

v0 = vector([1,5,8]) #Make initial population vector


A = [v0[0]] # for making time series
F = [v0[1]] # for making time series
B = [v0[2]] # for making time series
for i in srange (0,30):
v0 = M*v0 #Multiply current
population vector by M
A.append(v0[0])
F.append(v0[1])
B.append(v0[2])
list_plot (A, axes_labels = ["Time (Years)","Algae
Energy"], size = 50) #Use list_plot
list_plot (F, axes_labels = ["Time (Years)","Fish
Energy"], size = 50) #Use list_plot
list_plot (B, axes_labels = ["Time (Years)","Bacteria
Energy"], size = 50) #Use list_plot
--------------------------------------------------------------------------------------

c) (3 points) Find and list the eigenvalues for this model. Hint: You may use the code below in
CoCalc.

show("Eigenvalues:")
show(M.eigenvalues())

d) (2 points) What is the principal eigenvector corresponding to the dominant eigenvalue? Hint:
You may use the code below in CoCalc.

max(M.eigenvectors_right())

e) (4 points) Suppose the amount of energy in the algae is 10 joules, how much energy will be in
the fish and bacteria? Hint: You may refer to your lab 8 on Mangrove model for the approach to
be used.

f) (4 points) If you were to use diagonalization to obtain the same solution as the simulations
𝐴30
above for ( 𝐹30 ), provide the corresponding mathematical expression and briefly describe what
𝐵30
each term in that notation refers to. Indicate the size of each matrix.
3. Analysis of Multivariable Nonlinear System Dynamics
3.1. [60 points] The following is a model of the nonlinear interactions between wolves (𝑊)
and their prey, the elk (𝐸) in Yellowstone National Park.

𝑾′ = 𝟐𝑬𝑾 − 𝟒𝑾 − 𝑾𝟐
𝑬′ = 𝟏𝟒𝑬 − 𝑬𝟐 − 𝑬𝑾

a) Find and classify all the equilibria of this model. If an equilibrium does not make
practical sense, discard from stability analysis.

Note: The clarity of the question precludes further student inquiries such “should I use
eigenvalues, or should I use linear approximation or should I find the Jacobian matrix or
should I find the stability of ALL the equilibrium points or why is there more than one
equilibrium or can we get negative values as equilibrium”. If you have any other question,
please ask on CampusWire.

b) Using simulations of 4 different trajectories beginning at well-thought initial


conditions, demonstrate that your theoretical analysis in (a) matches simulated results.
Also comment on what will happen to these populations in the long run. At the end of this
answer, copy and paste the code you used in your answer sheet. Please keep it short and
legible.

Note: The clarity of the question precludes further student inquiries such as “should I draw
time series graphs, or how many trajectories should I draw or should I show all the
variables or should I draw all the trajectories on the same graph”. If you have any other
question, please ask on CampusWire.

Rubric:

• Finding the equilibria: 8 points


• Performing linear stability analysis on each equilibrium point: total 30 points
• Code for the simulations: 5 points
• Simulating the trajectories: 2.5 points per trajectory, 5 points for the clarity of the graph
including appropriate axes labels and scaling.
• Conclusions of your analysis of model behavior: 2 points
3.2. [30 points] Finally to neurons, Dr. V’s favorite! Neurons are brain cells essential for our
nervous system function. The following differential equations represent a well-known
model for a hypothetical neuron. Neuroscientists use experimental inputs to switch a
neuron’s state from resting (stable equilibrium) to an oscillatory state or spiking state.
Such an input is modeled here as the parameter, 𝜇.

1
𝑉′ = (−𝑊 + 𝑉(1 − 𝑉)(𝑉 − 0.1) + 𝜇)
0.008
𝑊 ′ = 𝑉 − 0.5𝑊

Where 𝑉 and 𝑊 describe some biological variable of neurons. Note that when 𝜇 = 0 (no
experimental input), the equilibrium is at (𝑉 ∗ , 𝑊 ∗ ) = (0,0), which represents a stable
resting state. When 𝜇 = 0.3 (with experimental input), the equilibrium is at (𝑉 ∗ , 𝑊 ∗ ) =
(0.1, 0.2).

Use your knowledge of eigenvalues of the linear approximation at the two equilibria given
for this nonlinear model and show that a change in 𝜇 as above can produce the qualitative
switch from the stable equilibrium to oscillatory behavior in the model neuron. Briefly
explain what type of bifurcation this could be.

Note: The rubric below should give you sufficient hint for the expected steps in your
answer. No need for any simulations.

Rubric:

• Finding the Jacobian Matrix at the equilibria: 6+6 points


• Finding the eigenvalues of the Jacobian matrix for the parameter values provided: 6+6
points
• Explanation clarifying what leads to the switch in behavior based on your analysis: 6 points
APPENDIX

I. Getting your simulated graphs from CoCalc into your answer sheet
To get the graph into your answer document, you can:

• Right click on the graph in CoCalc and select “copy image”


• Then paste it in your answer word document using “Paste Special”. Be sure to select the image
option for pasting.
• If you are using something other than Microsoft Word to type your answers, the above approach
should work there too.

II. Some Useful Formulas

You might also like