0

我的任务是创建一个使用公式模拟人口增长的程序x_new = r * x_previous * (1-x_previous),其中r是繁殖力参数,x是人口。我有一个工作程序和方法。但是,我的数学没有检查出来。我应该能够测试 的初始种群.01、繁殖力参数1.11000时间步长并得到答案.09)。

这是我的程序:

import java.util.Scanner;

public class Lab6Question3 {

public static void main(String[] args) {
    Scanner input = new Scanner(System.in);

    System.out.println("The population, p: ");
    double p = input.nextDouble();
    System.out.println("The fecundity rate, r: ");
    double r = input.nextDouble();
    System.out.println("Number of Time Steps, n: ");
    int n = input.nextInt();

    int i; //iterations

    System.out.println("-------------------------------------");
    System.out.println("Simulation with starting population " + p); 
    System.out.println("Running " + n + " steps");
    System.out.println("Varying fecundicity 1, 1.1, ..., 4.9, 5");

    for (i = 0; i < n; i++) { 

    System.out.println("r = " + r + " final population = " + p);

    r = r + 0.1;

    p = populationGrowth(p, r);

    }

}

public static double populationGrowth(double population, double fecundicity) 
{
    double p;

    return (fecundicity * population * (1 - population));

}
}

而且我的输出使用迭代正确格式化,但填充结果是错误的:

Simulation with starting population 0.01
Running 10000 steps
Varying fecundicity 1, 1.1, ..., 4.9, 5
r = 1.0 final population = 0.01
r = 1.1 final population = 0.01089
r = 1.2000000000000002 final population = 0.012925689480000004
r = 1.3000000000000003 final population = 0.01658620084090661

.
.
.

有什么想法可能是造成疼痛的原因吗?提前致谢!

4

1 回答 1

0

r达到5.2迭代时43,您的增长函数变为负数,因为x_previous is > 1...所以1-x_previous < 0,您确定模型是正确的...这似乎是一个概念问题。尝试在excel中对其进行建模。

另一件事,你r在计算下一个p值之前增加你。你确定这是对的吗?

于 2018-03-04T02:29:51.573 回答