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

  1. #include <stdlib.h>
  2. #include <stdio.h>
  3. #include <math.h>
  4. const double R = 2.0;
  5. const double step_size = 0.5; // years
  6. const double t_stop = 10.0;
  7. const double max_sustainable_pop = 4460000*5;
  8. const double initial_p = 0.001;
  9. int main()
  10. {
  11. double p = initial_p;
  12. int ii;
  13. FILE *f = fopen("data/data.txt", "w");
  14. if (!f)
  15. {
  16. fprintf(stderr, "bad file\n");
  17. return 1;
  18. }
  19. for (int ii = 0; ii < t_stop / step_size; ii++)
  20. {
  21. double p_new = R * p * (1 - p);
  22. fprintf(f, "%lf %lf %lf\n", ii * step_size, p, p * max_sustainable_pop);
  23. p = p_new;
  24. }
  25. fclose(f);
  26. }