import numpy as np
import matplotlib.pyplot as plt
L = np.array([
[0, 1, 1.8, 1.7, 0],
[0.61, 0, 0, 0, 0],
[0, 0.29, 0, 0, 0],
[0, 0, 0, 0.19, 0],
[0, 0, 0, 0.13, 0.08]
])
L = np.linalg.inv(L)
population_vector = np.array([289, 211, 120, 76, 51])
populations = [population_vector]
for _ in range(2):
population_vector = L @ population_vector
populations.append(population_vector)
years = range(0, -5, -2)
populations = np.array(populations).T
for age_group, pop in enumerate(populations):
plt.plot(years, pop, label=f'Age group {age_group}')
plt.legend()
plt.xlabel('Years')
plt.ylabel('Population')
plt.title('Backwards Cod Population Projections')
plt.show()
aW1wb3J0IG51bXB5IGFzIG5wCmltcG9ydCBtYXRwbG90bGliLnB5cGxvdCBhcyBwbHQKCkwgPSBucC5hcnJheShbCiAgICBbMCwgMSwgMS44LCAxLjcsIDBdLAogICAgWzAuNjEsIDAsIDAsIDAsIDBdLAogICAgWzAsIDAuMjksIDAsIDAsIDBdLAogICAgWzAsIDAsIDAsIDAuMTksIDBdLAogICAgWzAsIDAsIDAsIDAuMTMsIDAuMDhdCl0pCkwgPSBucC5saW5hbGcuaW52KEwpCnBvcHVsYXRpb25fdmVjdG9yID0gbnAuYXJyYXkoWzI4OSwgMjExLCAxMjAsIDc2LCA1MV0pCgpwb3B1bGF0aW9ucyA9IFtwb3B1bGF0aW9uX3ZlY3Rvcl0KZm9yIF8gaW4gcmFuZ2UoMik6CiAgICBwb3B1bGF0aW9uX3ZlY3RvciA9IEwgQCBwb3B1bGF0aW9uX3ZlY3RvcgogICAgcG9wdWxhdGlvbnMuYXBwZW5kKHBvcHVsYXRpb25fdmVjdG9yKQoKeWVhcnMgPSByYW5nZSgwLCAtNSwgLTIpCnBvcHVsYXRpb25zID0gbnAuYXJyYXkocG9wdWxhdGlvbnMpLlQKZm9yIGFnZV9ncm91cCwgcG9wIGluIGVudW1lcmF0ZShwb3B1bGF0aW9ucyk6CiAgICBwbHQucGxvdCh5ZWFycywgcG9wLCBsYWJlbD1mJ0FnZSBncm91cCB7YWdlX2dyb3VwfScpCnBsdC5sZWdlbmQoKQpwbHQueGxhYmVsKCdZZWFycycpCnBsdC55bGFiZWwoJ1BvcHVsYXRpb24nKQpwbHQudGl0bGUoJ0JhY2t3YXJkcyBDb2QgUG9wdWxhdGlvbiBQcm9qZWN0aW9ucycpCnBsdC5zaG93KCk=