/*
Replicator Equation by Runge-Kutta method

dx/dt = x(1-x)((A+B)x-B)
*/

#include 
#include 

#define h 0.1 

#define A -0.75 /* A > 0, B < 0 : Non Dilemma, A < 0, B > 0 : Prisoner's Dilemma*/
#define B -0.25 /* A > 0, B > 0 : Coordination, A < 0, B < 0 : Hawk-Dove */

double FUNC();

main()
{
  int j; /*j; step number*/
  double nx=0,x=0.6;
  double nt=0,t=1.0;
  double k1=0.0,k2=0.0,k3=0.0,k4=0.0;
  
  for(j=0; j<=300;j++)
    {
      k1=h*FUNC(t,x);
      k2=h*FUNC(t+0.5*h,x+0.5*k1);
      k3=h*FUNC(t+0.5*h,x+0.5*k2);
      k4=h*FUNC(t+h,x+k3);
      
      nx=x+0.166666667*(k1+2.0*k2+2.0*k3+k4);
      nt=t+h;
      
      printf("%d %f \n",j,x);
      x=nx;
      t=nt;
    }
  return 0;
}

double FUNC(double t, double x)
{
  return (x*(1.0-x)*((A+B)*x-B) );
}



出力結果

RED=Non Dilemma , YELLOW=Prisoner's Dilemma, GREEN=Coordination, BLUE=Hawk-Dove



/*
対称2人ゲームにおけるPotential
Potentialの形状から安定性が分かる。
*/

#include 
#include 

#define a -2.0
#define b -1.0

main()
{
  double x=0.0;

  for(x=0.0;x<=1.0;x+=0.01)
    {
    printf("%f %f\n", x,0.25*(a+b)*x*x*x*x-(a+2.0*b)*x*x*x/3.0+0.5*b*x*x+0.25);
    }
   return 0;
}



出力結果

RED=Non Dilemma , GREEN=Prisoner's Dilemma, BLUE=Coordination, YELLOW=Hawk-Dove


Back to C Language

Google




BLOG
PICASAWEB
Panoramio