1170:Lab3
Goals For This Week
This week we’ll look at iterative maps.
•
Figure out iterative maps based on Data
•
Predict the future of a population and interpret the results.
The table below shows the size of an experimental population of fruit flies every week over an 11 week period.
Week Population
5
6
3
4
0
1
2
76
64
81
54
3
10
32
7
8
9
10
87
39
84
48
11 87
First let’s plot these data as a function of time.
> population<-c(3,10,32,76,64,81,54,87,39,84,48,87)
> weeks<-seq(0,11)
> plot(weeks,population,xlab=’Time(Weeks)’,ylab=’ FLIES ’,main=’ FLIES size vs Time’)
Save this Plot.
It’s difficult to see what, if any, pattern the population follows. We hypothesize that the population is described by an iterative map.
p ( t ) = f ( p ( t
− is by plotting the population vs the population the week prior.
1)). We can try to see what the function f
1
Population Population one week later
54
87
39
84
48
3
10
32
76
64
81
10
32
76
64
81
54
87
39
84
48
87
We plot this data with the code below. population[1:11] refers to the first population sizes and population[2:12] starts with the second week, offsetting everything by one.
> plot(population[1:11],population[2:12],xlab=’ FLIES Before’,ylab=’ FLIES After’,main=’ FLIES size vs Earlier
Save this Plot.
The data points all seem to lie on an upside down parabola.
In fact, I generated these data using a logistic map. This means that p ( t ) = f ( r, p ( t
−
1)) = rp (1
− p/ 100).
You have to try to figure out what the value r is. We can use the same approach that you used in lab2.
First define the function.
> f<-function(r,p)r*p*(1-p/100)
Then plot it over the top of the data. Remember we’ll have to define some extra values for the horizontal axis to get smooth curve. In this case this also has units population. Then we’ll have to guess an r . In the example below, I’ve set r = 1.
> population_values_horz<-seq(0,100,.1)
> lines(population_values_horz,f(1,population_values_horz))
Adjust r until the curve matches up well with the data, then Save this Plot.
In the rest of the code for this lab, I’m going to use r = 1 even though this is not the correct value.
Now we want to use the function f to predict what will happen to the population in the future. We’ll create a new vector called pop g uess . We’ll set the first value in the vector to 3. Note that technically this corresponds to time= 0, but we can’t assign a zeroth position in a vector in R.
> pop_guess<-seq(1,100)
> pop_guess[1]<-3
Now that the list is initialized we can calculate all the remaining values.
> pop_guess[2]<-f(1,pop_guess[1])
> pop_guess[3]<-f(1,pop_guess[2])
> pop_guess[4]<-f(1,pop_guess[3])
> pop_guess[5]<-f(1,pop_guess[4])
2
If we wanted to repeat this for 100 weeks then this would get repetitive. We can automate this process with a for loop.
> for(i in seq(2,100))pop_guess[i]<-f(1,pop_guess[i-1])
The above line means ”for each i from 2 to 200 let pop guess[i] be f(1,pop guess[i-1])”. This is exactly what we want.
Finally, let’s plot the all of the predicted data.
> plot(seq(1,100),pop_guess, xlab ="Time(Weeks)", ylab ="Population", main ="Predicted ⁀ redFLIES Population")
Save this Plot.
1. Plot the original population data versus weeks (should already be done)
2. Plot the population versus the value the week before (should already be done)
3. Find the best value for r and then plot this function on top of the previous plot (should already be done)
4. Plot the future values of the population up to 100 weeks, starting with 3 FLIES (should already be done)
5.
Describe what is happening to the population in the previous problem.
6. Plot the future values of the population up to 500 weeks, starting with 3 FLIES
7. Plot 100 weeks assuming you start with 30 FLIES . Comment on the difference between this and 3
FLIES .
8. Plot 500 weeks assumging you start with 3 FLIES , but try letting r = 3. Describe what you see.
9. Plot 500 weeks assumging you start with 3 FLIES , but try letting r = 3 .
8. Describe what you see.
3