### Assignment 1: Simulating Ecological Homeostasis

作业math | Python代做 – 这是利用math进行训练的代写, 对math的流程进行训练解析, 是比较典型的math/Python等代写方向

#### Installation

```
If the math equations are not rendering nicely below, you may need to install nbconvert.
```

```
On some systems this can be done by executing pip3 --user --upgrade nbconvert
```

#### Background: The Gaia Hypothesis & Daisy World

```
In the 1970s, James Lovelock and Lynn Margulis developed the Gaia Hypothesis. This is a highly controversial theory which proposes that the global
biosphere is self-regulating that ecosystems work to maintain the conditions necessary life to persist on Earth. As a case in point to support his theory,
Lovelock observed that the amount of heat arriving from our Sun has increased significantly since the origin of life, but that the tempera- ture of the planet has
remained within the limits of hability throughout. How does this homeostasis (loosely translatable as keeping things the same) occur?
```

```
Lovelock argues that the homeostasis is a natural biproduct of complex ecosystems, but this is a very controversial claim, because it seems to contradict
classic ideas of evolution being driven by selfish competition and survival of the fittest. Lovelocks theory suggests that instead of competing and being
selfish, diverse species come to some sort of agreement, whereby theyll cooperate to make conditions beneficial for all life (and not just themselves). If you
are interested to know more, the wikipedia page on the Gaia Hypothesis provides some more information including links to further reading.
```

```
Debate concerning the Gaia Hypothesis continues today. A computational model known as Daisy World has been developed to show how regulation of
environmental conditions (such as the temperature of the planet) can happen. The model considers a planet populated by two different types of daisies, black
ones and white ones. The black daisies increase the temperature (by a small amount) by absorbing sunlight, and the white ones reflect light back into space,
decreasing the local temperature. In this assignment, we will develop a simplified version of Daisy World that only includes the white daisies.
```

```
As is common in developing computational models, we will make many simplifying assumptions. We will assume:
```

- the daisies grow better at certain temperatures than others;
- the temperature of the planet is the same everywhere;
- daisies are the only relevant species that lives on the planet;
- the carrying capacity (i. e. the number of daisies that are alive at equilibrium) is well approximated as a function of temperature;
- when there are no daisies around, it is still possible for a population to grow (we can imagine there are always seeds in the ground).

#### Model

```
Our model will be a continuous-time dynamical system that is described by three differ- ential equations. Each equation describes the dynamics of one of the
following variables.
```

```
-- the normalized population density of daises. 1 means the planet is covered in the maximum possible density of daises and 0 means there are no
daisies at all, etc.
```

- the temperature of the planet (this corresponds in our simplified model to the temperature everywhere)
- an external perturbing force to the temperature. This can be conceived of as an increase in the radiation from the star that the planet is orbiting, or any other (combination) of factors that are modifying the planets temperature other than the presence of the daisies.

```
In this assignment, as you follow the instructions, you will build a computational model of this system. By the end of it hopefully you will have gained some
insight into one way that biological-feedback can (at least in theory) stabilise environments as claimed by Lovelock and Margulis.
```

#### n

#### y

#### p

#### Step 1: Write a function that maps the temperature to the carrying capacity of the daisies.

```
In our equations, the carrying capacity is written. It describes the equilibrium population density, i. e. what the population density (n) would move toward if
everything else were held constant. Assumption 4 tells us that we can is well approximated as some function of temperature ( ):
```

```
A typical response of a carrying capacity to an environmental feature such as temperature is a Gaussian function:
```

```
In this equation, there are three parameters ( , and ). specifies the height of the curves peak; specifies the position of the maximum; and specifies the
standard deviation, i. e. the width of the curve.
```

```
What values for these parameters should we use? is normalized, so the peak of the curve should be 1. Let us assume that the daisies grow best at a
temperature of C. and that the standard deviation is 3.
```

#### k

#### k y

#### k = f ( y )

#### k = f ( y )= a exp( )

#### ( y b )^2

#### 2 c^2

#### a b c a b c

#### k

#### 25 o

```
Q1a. (0.5 marks) Write a Python function that takes y as an argument and returns k.
```

In [1]: *## Q1a answer goes here…define the following function*

```
def carrying_capacity(...) :
...
```

```
Q1b. (0.5 marks) To confirm that your function is correct, plot it for suitable values of y. The numpy function numpy.arange may be useful for generating an
array of y-values. (Or you can use a Python list comprehension).
```

```
FOR ALL PLOTS LABEL AXES AND PROVIDE TITLES OR POINTS WILL BE LOST!
```

In [3]: *## Q1b answer goes here…*

#### Step 2: Describing how daisy density changes over time.

```
In our model, the population density ( ) changes as a function of the current population density ( ) and the current carrying capacity ( ):
```

```
We shall model as always approaching the carrying capacity, with a rate of this approach that is linearly proportional to the difference between the current
population density and the carrying capacity. The scale of the response (i. e., the slope of the line),.
```

#### n n k

#### = g ( n , k )

#### dn

#### dt

#### n

#### s =0.

```
Q2a. (0.5 marks) Write down (in math notation, not code) the differential equation that captures what has just been described above. If it is not clear to you
how to do this, think about what a graph of this function should look like. Use pencil and paper to think this through.
```

```
Double click on the word ANSWER below, to edit the markdown. Your answer here should sit between the two sets of dollar-signs to be displayed as latex
math. When you've written an equation, to see it rendered as math, run the cell (I hit control-enter to do so).
```

```
The basics of latex math in markdown can be found here: https://www.latex-tutorial.com/tutorials/amsmath/
```

#### = g ( n , k )= ANSWER

#### dn

#### dt

```
Q2b. (0.25 marks) Translate the above mathematical equation into a Python function that takes two arguments (n and k) and returns the rate at which n
changes. In other words, fill in the following blank.
```

In [2]: *## Q2b answer goes here…* **def** dndt(n,k): **return** …

#### Q2c. (0.25 marks) To confirm that your function is working how it should be, plot g ( n , k ) for an appropriate range of values of n, with k = 0.5.

In [1]: *## Q2c answer goes here…*

```
Q2d. (0.5 marks) Super-impose on the same plot g ( n, k ) when k is fixed to one or two other values (you pick the values).
```

In [ ]: *## Q2d answer goes here…*

```
Q2e. (0.5 marks) In a sentence or two, describe why the above plots confirm that this function is working correctly. DONT FORGET TO LABEL YOUR PLOTS.
```

#### Step 3: Describing how temperature changes over time.

```
The temperature changes at a rate proportional to the sum of (1) the influence of every-thing other than the daisies, which is captured by the variable , and (2)
the influence of the daisies. The influence of the daisies will be linearly proportional to their density, giving us the following differential equation,
```

```
where is a constant that describes the amount of influence that the daisies have. Well assign this parameter a value of , which can be interpreted as
saying that when the daisies are at their maximum possible density, they bring the global temperature down by 10 degrees.
```

#### p

#### = p + rn

#### dy

#### dt

#### r r = 10

#### Q3. (0.25 marks) Translate the above Equation into a Python function as you did with the differential equation for n.

In [7]: *## Q3 answer goes here…*

#### Step 4: Non-daisy influence

```
Let us imagine that the radiation of the sun is increasing at an increasing rate. This can be described using the following differential equation, where
is a constant representing the rate of that increase and represents the amount of time that has passed since the start of the simulation.
```

#### q =0.

#### t

#### = h ( t )= qt

#### dp

#### dt

#### Q4. (0.25 marks) Translate this differential Equation into a Python function as you have done with the differential equations for n and y.

In [9]: *## Q4 answer goes here…*

```
At this point you should have four Python functions:
```

```
def carrying_capacity(...):
"""returns carrying capacity"""
...
```

```
def dndt(...):
"""returns rate of change of population density """
...
```

```
def dydt(...):
"""returns rate of temperature change"""
...
```

```
def dpdt(...):
"""returns rate of change of non-daisy infl. upon temperature"""
....
```

```
Q5. (2 marks) Write a trajectory function that uses these functions to simulate a trajectory from the initial condition that is passed in as an argument.
```

```
Your function should use the Euler integration we have learned about in class, and must NOT use an existing library (e.g. scipy) to solve the integration. The
functions signature should look like this, where the final argument (dur) indicates the duration of the trajectory to simulate.
```

```
def trajectory(init_n, init_y, init_p, dur) :
...
return ns, ys, ps, times
```

```
Tips:
```

```
Experiment to pick an appropriate time step value.
Be careful to pass time (and not the time step or the iteration count) to dpdt().
Make your code as clear and understandable as you can to improve chances of getting partial credit.
```

In [1]: *## Complete this to answer Q* DT = … **def** trajectory(init_n, init_y, init_p, dur) : … **return** ns, ys, ps, times

#### Step 6: Plotting results and interpretation

```
Simulate a trajectory that starts with and that runs for 45 time units.
```

```
Q6a. (0.25 marks) On a labelled figure, plot a time-series that shows how the population density changes over the course of the simulation.
```

#### n 0 = y 0 = p 0 = 0

In [ ]:

```
Q6b. (0.25 marks) On a separate labelled figure, plot a time-series that shows how the temperature changes over the course of the simulation.
```

In [ ]:

```
Q6c. (0.5 marks) Create a new figure that replots what you plotted in Q6b, but also superimposes on top of that same plot a time-series that shows how the
temperature would have changed if the daisies had no influence upon temperature. Label which line is which using a legend.
```

In [ ]:

```
Q7. (1 mark) Interpret the results. What has happened? What are the striking features about the trajectories? What affects them? What conclusion(s) can we
draw from the simulation? Write a short paragraph summarizing your interpretation.
```

In [ ]:

### Additional plots

```
If you have additional plots you'd like to refer to in your answer above, please include them below here and label them so that it is easy to see in your answer(s)
above which figure(s) you are referring to.
```

In [2]: *## code for generating additional plots goes here…*