fork download
  1. import numpy as np
  2. import matplotlib.pyplot as plt
  3.  
  4. L = np.array([
  5. [0, 1, 1.8, 1.7, 0],
  6. [0.61, 0, 0, 0, 0],
  7. [0, 0.29, 0, 0, 0],
  8. [0, 0, 0, 0.19, 0],
  9. [0, 0, 0, 0.13, 0.08]
  10. ])
  11. L = np.linalg.inv(L)
  12. population_vector = np.array([289, 211, 120, 76, 51])
  13.  
  14. populations = [population_vector]
  15. for _ in range(2):
  16. population_vector = L @ population_vector
  17. populations.append(population_vector)
  18.  
  19. years = range(0, -5, -2)
  20. populations = np.array(populations).T
  21. for age_group, pop in enumerate(populations):
  22. plt.plot(years, pop, label=f'Age group {age_group}')
  23. plt.legend()
  24. plt.xlabel('Years')
  25. plt.ylabel('Population')
  26. plt.title('Backwards Cod Population Projections')
  27. plt.show()
Success #stdin #stdout 1.72s 56780KB
stdin
Standard input is empty
stdout
Standard output is empty