首页 > 解决方案 > 谁能帮我解决这个 python 问题:狼和猎物动力学

问题描述

嘿伙计们,我今年夏天正在学习 python,我有一个问题要做,如果有人能提供帮助,对我来说一切都是新的:鉴于捕食者(狼)和猎物(鹿)的生态系统,我们将研究它们相互作用的动态. 我们将逐步研究它们数量的演变。在以下的每个时间增量dt=0.01适用:

编写函数

wolves_and_dear(deer_0, wolves_0, deer_growth, deer_predation, wolves_predation, wolves_decay, dt, n) 

这将模拟系统n次并找到系统中狼的最大值。 在此处输入图像描述

标签: python

解决方案


这是一个应该可以使用的基本模板,问题中似乎缺少公式,因此您必须自己添加它们。学习编写代码是一项非常有用的技能,所以不要复制粘贴这个答案,而是要从中学习。

def wolves_and_dear(deer_0, wolves_0, deer_growth, deer_predation, wolves_predation, wolves_decay, dt, n):
    best_wolves = 0
    for simulation in range(n):
        deer,wolves = deer_0,wolves_0
        t = 0
        while t < 1:
            deer += deer_growth
            deer -= deer_predation
            wolves -= wolves_predation
            wolves -= wolves_decay
            t += dt
        best_wolves = max(best_wolves,wolves)
    return best_wolves

如果您有任何问题,请发表评论,我会尽力提供帮助。


推荐阅读