FaradayZhangChina 2015-06-02 08:50 采纳率: 0%
浏览 1575
已采纳

请大家帮忙看看这段代码如何写才好?

如果题目的意思是:
方法头必须是double[] preyPredLV(double[] preyPred, double[] a, double[] b, int n};
然后,题目的要求如下,谁能给出一段代码,符合题目的要求?
The dynamics between predators and preys in a given ecosystem attracts a lot of attention from researchers. Different scientists have developed Predator-Prey models to try to understand the interactions and foresee the evolution of the populations.
在给定的生态系统里,食肉动物和猎物之间的动态吸引了许多来自调研人员的注意力。不同的科学家开发了食肉动物-猎物模型,试图理解和预测人口进化的交互。

One of the first analyzed Predator-Prey ecosystems was the “Lynx-Snowshoe hare” and one of the first Predator-Prey models defined was the one developed by Lotka and Volterra.
其中,第一个分析食肉动物-猎物生态系统的是”Lynx-Snow雪地靴野兔”,以及第一个定义的食肉动物-猎物模型是由Lotka和Volterrra开发的。

This Predator-Prey model defines:
这个食肉动物-猎物模型定义了:

 H[n] as the snowshoe hare population (being n a specific moment of time)
是雪地靴野兔的人口(n是一个特定时刻 )
 L[n] as the lynx population
是猞猁的人口
 It assumes that the primary growth of the hare population in the absence of lynx is a1*H[n] and that the lynx population in the absence of hares declines –b1*L[n]
假设,当猞猁缺乏的时候,野兔人口的主要增长是a1*H[n],并且,野兔缺乏的时候,猞猁的人口下降是-b1*L[n].
 It also assumes that the primary loss of snowshoe hares is due to predating a2*H[n]*L[n] and the growth of the lynx population is from the energy derived from eating snowshoe hares b2*H[n]*L[n]
它还假设雪地靴野兔的主要减少是因为捕食a2*H[n]*L[n],且猞猁的人口增长是因为来源于吃雪地靴野兔得到的能量b2*H[n]*L[n]

The Lotka-Volterra model is defined by the following formula:

H[n+1] = H[n] + a1 * H[n] - a2*H[n]*L[n] = H[n] * (1 + a1 - a2*L[n])
L[n+1] = L[n] - b1 * L[n] + b2*H[n]*L[n] = L[n] * (1 - b1 +b2*H[n])

For instance, let’s assume that the initial population of snowshoe hares is 300 and the initial population of lynxes is 20, and the values of the constants that regulate the model are a1=0.1, a2=0.01, b1=0.01 and b2=0.00002. The previous formula can be used to calculate the population of both lynxes and snowshoe hares after 2 periods:
举个例子,让我们假设,雪地靴野兔的初始人口是300个,猞猁的初始人口是20个,约束这个模型的常量的值是a1=0.1, a2=0.01, b1=0.01 and b2=0.00002。前一个公式能被用来计算猞猁和雪地靴野兔的人口,在期间2以后。

After 1 period the population of snowshoe hares will be:
在期间1以后,雪地靴野兔的人口将会是:
H[1] = H[0] + a1 * H[0] - a2*H[0]*L[0] = H[0] * (1 + a1 - a2*L[0]) = 300 *(1 + 0.1 - 0.01*20) = 270
In turn, the population of lynxes will be:
相应地,猞猁的人口将会是:
L[1] = L[0] - b1 * L[0] + b2*H[0]*L[0] = L[0] * (1 - b1 +b2*H[0]) = 20 * (1 - 0.01 + 0.00002*300) = 19.92

Notice that we keep the decimals for the following loop in the formula.
注意,我们保持小数点给公式里的下面的循环

After 2 periods, the population of snowshoe hares will be:
H[2] = H[1] * (1 + a1 - a2*L[1]) = 270 * (1 + 0.1 - 0.01*19.92) = 243.216
经过2个期间,雪地靴野兔的人口将会是如上面的公式

And the population of lynxes will be:
L[2] = L[1] * (1 - b1 +b2*H[1]) = 19.92 * (1 - 0.01 + 0.00002*270) = 19.828368
且猞猁的人口将会是以上的只数

If we continue, we can guess the population after 20 periods:
H[20]=47.15 snowshoe hares
L[20]=17.28 lynxes
如果我们继续,我们能够猜测20个期间以后的人口数:

Or after 100 periods:
H[100]=8.44 snowshoe hares
L[100]=7.89 lynxes
经过100期间:

Or even after 200 periods:
H[200]=903.17 snowshoe hares
L[200]=3.91 lynxes
或者甚至经过200个期间以后:


  • 写回答

3条回答 默认 最新

  • JonsonJiao 2015-06-02 09:44
    关注

    开始的时候我认为这个就是一个递归调用的过程,也写好了代码,计算1、2、20都没有问题,等到100的时候就受不了,计算时间太长了,后来我改成了这个样子,Java代码如下:

      private static final int POP_H0 = 300;
        private static final int POP_L0 = 20;
    
        private float[] popH;
        private float[] popL;
    
        public static void main(String[] args) {
    
            EveryThingTest ett = new EveryThingTest();
            int period = 200;
    
            ett.printPop(period);
    
        }
    
        /**
         * 输出period时的两种动物数量
         * 
         * @param period
         */
        private void printPop(int period) {
            // TODO Auto-generated method stub
            popH = new float[period + 1];
            popL = new float[period + 1];
            popH[0] = POP_H0;
            popL[0] = POP_L0;
            for (int i = 1; i < period + 1; i++) {
                popH[i] = getPopH(popH[i - 1], popL[i - 1]);    //非递归调用
                popL[i] = getPopL(popH[i - 1], popL[i - 1]);    //非递归调用
            }
            // float popH = getPopH(period);    //递归调用
            // float popL = getPopL(period);    //递归调用
            System.out.println("经过" + period + "期间之后:");
            System.out.println("-->野兔数据量为" + popH[period]);
            System.out.println("-->猞猁数据量为" + popL[period]);
        }
    
        /**
         * 非递归方式,根据传入的前一个时间的野兔和猞猁值计算野兔数量
         * @param preH
         * @param preL
         * @return
         */
        private float getPopH(float preH, float preL) {
            // TODO Auto-generated method stub
            return preH * (1 + 0.1f - 0.01f * preL);
        }
    
        /**
         * 非递归方式,根据传入的前一个时间的野兔和猞猁值计算猞猁数量
         * @param preH
         * @param preL
         * @return
         */
        private float getPopL(float preH, float preL) {
            // TODO Auto-generated method stub
            return preL * (1 - 0.01f + 0.00002f * preH);
        }
    
        /**
         * 递归计算野兔的数量,period为0时返回300
         * 
         * @param period
         * @return
         */
        private float getPopH(int period) {
            // TODO Auto-generated method stub
            System.out.println("计算" + period);
            if (period == 0) {
                return POP_H0;
            } else {
                return getPopH(period - 1)
                        * (1 + 0.1f - 0.01f * getPopL(period - 1));
            }
        }
    
        /**
         * 递归计算period时的猞猁数量,period为0时返回20
         * 
         * @param period
         * @return
         */
        private float getPopL(int period) {
            // TODO Auto-generated method stub
            if (period == 0) {
                return POP_L0;
            } else {
                return getPopL(period - 1)
                        * (1 - 0.01f + 0.00002f * getPopH(period - 1));
            }
        }
    

    非递归调用,计算时间秒级啊。

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示
  • ¥15 求三国群英传pl国战时间的修改方法
  • ¥15 matlab代码代写,需写出详细代码,代价私
  • ¥15 ROS系统搭建请教(跨境电商用途)
  • ¥15 AIC3204的示例代码有吗,想用AIC3204测量血氧,找不到相关的代码。