stochastic simulation markov chain program I assume for simp

stochastic simulation, markov chain program

I assume for simplicity that you are the only player of this board game. Start at square 1 and move at each step to one, two, or three squares ahead according to the outcome of spinning a roulette. If you land at the bottom of a ladder, immediate climb it. If you land on the head of the snake, slide 5 down to the tip of the snake\'s tail. The game ends at reaching square 12. The only way to reach 12 from squares 10 and 11 is by drawing 2 or 1, respectively; if the roulette gives a higher number than necessary, stay where you are. We wish to run a stochastic simulation of this game by using the Markov chain program. (a) What is the expected number of steps to go from 1 to 12? (b) On average, how many limes will a player climb a ladder? (c) On average, how many times will a player slide down a snake? Before writing your program, convince yourself that my transition probabilities diagram given below correctly interprets the rules of the game. The simulation consists of running the game till finish a large number of times and obtaining the three average values asked in the problem.

Solution

#include <stdio.h>

#include <math.h>

#include <stdlib.h>

#include <gsl/gsl_rng.h>

#include <gsl/gsl_randist.h>

void main()

{

int N=20000;

int thin=500;

int i,j;

gsl_rng *r = gsl_rng_alloc(gsl_rng_mt19937);

double x=0;

double y=0;

printf(\"Iter x y\ \");

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

    for (j=0;j<thin;j++) {

      x=gsl_ran_gamma(r,3.0,1.0/(y*y+4));

      y=1.0/(x+1)+gsl_ran_gaussian(r,1.0/sqrt(x+1));

    }

    printf(\"%d %f %f\ \",i,x,y);

}

}

stochastic simulation, markov chain program I assume for simplicity that you are the only player of this board game. Start at square 1 and move at each step to

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site