I was assigned a program for inputting data and outputting a table in which the Verhulsts formula was calculated for k number of years. I used this equation:
http://www.resnet.wm.edu/~jxshix/math410/Verhulst.html
The equation below:
p (n + 1) = (1 + gh) p (n) - gp (n) ^ 2 / M.
Here is the program I made. I deleted the part of my code that asks for input, as I feel you will be bored if you miss:
>
I was instructed to check my code using the examples from the link above, which sets g (growth rate) to 125, 250, and 300, respectively. I feel that my program is pretty accurate for the first two numbers (they exactly correspond to the graph), but when I connect 300, I get very different values ββfrom the graph presented. I'm not sure if Ive made any mistake in expressing the above in my code, or if the graph is especially horrible. Ive kept everything else constant using the parameters mentioned on the above site.
Here is the result I get: g = 300. The first column is the year, the second is the population:
1 35 2 96 3 88 4 102 5 75 6 116 7 37 8 100 9 80 10 112
Compared to the output that I looked from the third chart in the link above. Again, these are guesses, so I cannot vouch for their accuracy:
1 25 2 70 3 120 4 33 5 94 6 90 7 98 8 86 9 92 10 70
The fact that I can get outputs that correspond to the first and second graphs, but not the third, is bewildering. Is my implementation in C ++ equations sound ?:
int i; int pop; for (i = 1; i <= k ; i++) { pop = (((1 + (g - h)) * pn) - g*(pn*pn)/M) + .5; // the equation pn = pop; // this takes the new value of pop and inserts it as pn, to be looped until i <= k cout << i << " " << pop << endl; }