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.
 
 
 

37 lines
814 B

#include <stdlib.h>
#include <stdio.h>
#include <math.h>
const double Rmate = 5.1;
const double Rdeath = 0.05;
const double R = Rmate - Rdeath;
const double step_size = 0.01;
const double time_for_total_death = 0.1; // years
const double t_stop = 100.0;
const double lambda = step_size / time_for_total_death;
const double max_sustainable_pop = 1000000;
const double initial_p = 0.01;
int main()
{
double p = initial_p;
int ii;
const double r_to_lambda = pow(R, lambda);
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_to_lambda * p * pow(1 - p, lambda);
fprintf(f, "%lf %lf %lf\n", ii * step_size, p, p * max_sustainable_pop);
p = p_new;
}
fclose(f);
}