Я работаю в Python, чтобы ответить на этот вопрос о том, должна ли группа пришельцев приносить население в 5 миллионов человек, а ресурсная нагрузка - 1 миллион против населения в 1 миллион человек и нагрузки в 5 миллионов человек ... Я пытаюсь найтикакой из 2 вариантов максимизирует население на новой планете через 200 лет.Вот мой код:
Вот моя производная функция
def derivs3(y1, t):
c = P0 + R0
r = a / c
q = (a + b) / c
Pi = y1[0]
Ri = y1[1]
Wi = y1[2]
# the model equations
dPdt = q * Pi*Ri/(1+Wi)
dRdt = - q * Pi*Ri/(1+Wi) + (a / q) * Wi / (t + .0001)
dWdt = b
return [dPdt, dRdt, dWdt]
Здесь я определяю свои параметры:
# model parameters
a = 0.02 # related to conversion of unallocated resources into population
b = 0.0001 # related to growth of knowledge
W0 = 0.0 # initial amount of knowledge
# time period
Tmax = 600 # years
Здесь я запускаю odeint и строю графикрезультаты:
# Put your code here
t = np.arange(0, Tmax, 0.1)
P0 = 5
R0 = 1
y0 = [P0,R0,W0]
soln = odeint(derivs3, y0, t)
PSol = soln[:, 0]
RSol = soln[:, 1]
WSol = soln[:, 2]
P0 = 1
R0 = 5
y0 = [P0,R0,W0]
soln = odeint(derivs3, y0, t)
PSol2 = soln[:, 0]
RSol2 = soln[:, 1]
WSol2 = soln[:, 2]
plt.plot(t,PSol)
plt.plot(t,PSol2)
plt.legend(("5Bil Aliens, 1Bil Resources","1Bil Aliens, 5Bil Resources"), loc='upper left', prop={'size':15}, bbox_to_anchor=(1,1))
plt.grid()
plt.xlabel("time (years)")
plt.ylabel("Population (billions)")
plt.title("Populations vs. Time")
И вот здесь возникает проблема:
if PSol[200] > PSol2[200]:
print("To maximize population after 200 years (for a total of", round(PSol[200],2),"billion aliens), the aliens should take a population of 5 Billion Aliens, and a load of 1 Billion Resources.")
elif PSol[200] < PSol2[200]:
print("To maximize population after 200 years (for a total of", round(PSol2[200],2),"billion aliens), the aliens should take a population of 1 Billion Aliens, and a load of 5 Billion Resources.")
else:
print("The population after 200 years will be the same (for a total of", round(PSol2[200],2),"billion aliens), whether the aliens take a population of 5 Billion Aliens and a load of 1 Billion Resources, or a population of 1 Billion Aliens and a load of 5 Billion Resources")
Итак, он возвращает следующие операторы печати, которые не совпадают с графиком, который я получаю,Вероятно, это проблема с индексированием, , но я использую PSol [200] и PSol2 [200], потому что я хочу знать, сколько инопланетян и ресурсов они должны принести, если они хотят увеличить население через 200 лет. Смотрите ниже (игнорируйте линию около 600 лет, потому что я не корректировал их, зная, что они будут возвращать те же проблемы):
Вот график.Я знаю, что это правильно (попросил справочную), так что это должны быть отключены индексированные значения.
![Here is the graph](https://i.stack.imgur.com/aMg8i.png)