Reference no: EM132394127
Assignment
1 Question
The H ´enon map is a pair of equations given by
xn+1 = 1 - ax2n + yn (1)
yn+1 = bxn (2)
These equations can display some interesting behavior when its results are looked at. First, create a function called Henon, which will take 5 input parameters: the initial x and y, the parameters a and b, and the number of iterations n. Inside this function you will iterate the equations the given number of times, and store the results in separate lists. (One for the x values, and one for the y values. Remember to update your values as you go!) It will return both of these lists after its done. Show this code, and show the output lists for x = 1.0, y = 0.25, a = b = 0.25 after 5 iterations.
(Hint: you should get the same values for x and y the whole time.)
2 Question
Use your Henon function to calculate the outputs for x and y after 25 iterations for the values a = b = 0.5, and initial x = 0, y = 1. Use matplotlib to create 2 subplots, with 2 rows and 1 column. The top plot should be a blue line for your x values, and the bottom should be a red line for your y values. Show the code to run the Henon function and create this plot, and the plot itself.
3 Question
Now we can see what happens when we start bouncing between several different values. Use your Henon function again to calculate the outputs for x and y after 100 iterations for the values a = 1.4 and b = 0.3. Your initial conditions should be x = 0.7, and y = 0. Use matplotlib to create 2 subplots, with 2 rows and 1 column same as before. Again, the top plot should be a blue line for your x values, and the bottom should be a red line for your y values. Show the code to run the Henon function and create this plot, and the plot itself.
4 Question
While the previous plots are interesting in that you can see similar bouncing for x and y, but things get really interesting when you plot both of them together. Calculate x and y using the same initial conditions and parameters you did for the previous question, but this time run it for 500 iterations. To plot the data, use a scatter plot. You should also label the x and y axis as ‘x' and ‘y', and title the plot as ‘Henon Data'. Show the code for this plot and the plot itself.
5 Question
The Lotka-Volterra equations, also known as the predator-prey equations, are a pair of equations that describe how a population of predators and a population of prey interact. They can be written as
x(t + 1) = x(t) + [a x(t) - b x(t)y(t)]Δt (3)
y(t + 1) = y(t) - [c y(t) - d x(t)y(t)]Δt (4)
where x is the prey, and y is the predator. Create and show your code for a Populations function. This function will take 7 parameters as input: x, y, the parameters a, b, c, d, and the number of iterations n.
You'll set δt inside the function as 0.2. Similar to our previous function, it will calculate the two above equations and return both the x and y results as a list from the calculation. Show this code.
6 Question
After creating your function, you should test it to see that it works. To do so, run the function with the following parameters: a = c = 0.1, b = d = 0. Start with 50 predators and 50 prey, and show the where the populations end up after 100 iterations. (Only show the last elements of the lists, not the lists themselves!)
Check that you get 362.23 for the population of the prey, and 6.63 for the population of the predator. If you don't, go back and look at your function again.
7 Question
Now we can see what happens when the two populations interact. Run your function again, this time with the parameters a = 0.02, b = 0.0005, c = 0.05, and d = 0.0005. Start with 50 prey and 25 predators, and run your simulation for 4000 iterations. Show a plot of the two populations individually with both of them on the same plot. Label the x axis as ‘Iterations' and the y axis as ‘Population Size'. Title it as ‘Predator-Prey Model'. Show the code to generate this plot, and the resulting plot.
8 Question
We can make a population go extinct if we have the correct parameters. Run your function for a third time, this time with the parameters a = 0.01, b = 0.01, c = 0.2, and d = 0.02. Start with 50 prey and 25 predators again, and run your simulation for 200 iterations. Same as before, show a plot of the two populations with both of them on the same plot. Label the x axis as ‘Iterations' and the y axis as ‘Population Size'. Title it as ‘Population Extinction'. Show the code to generate this plot, and the resulting plot.