Project 2 for MA132
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

31 lines
586 B

#include <stdlib.h>
#include <stdio.h>
#include <math.h>
const double R = 2.0;
const double step_size = 0.5; // years
const double t_stop = 10.0;
const double max_sustainable_pop = 4460000*5;
const double initial_p = 0.001;
int main()
{
double p = initial_p;
int ii;
FILE *f = fopen("data/data.txt", "w");
if (!f)
{
fprintf(stderr, "bad file\n");
return 1;
}
for (int ii = 0; ii < t_stop / step_size; ii++)
{
double p_new = R * p * (1 - p);
fprintf(f, "%lf %lf %lf\n", ii * step_size, p, p * max_sustainable_pop);
p = p_new;
}
fclose(f);
}