/* Numerical solution to simple Baseball Markov chain model */ /* Written by Carey Williamson, January 2019 */ #include #include /* Transition rates for Markov chain model */ #define LAMBDA1 0.20 /* transition rate to get first out */ #define LAMBDA2 0.25 /* transition rate to get second out */ #define LAMBDA3 0.25 /* transition rate to get third out */ #define LAMBDA4 0.50 /* transition rate for TV commercial */ #define DEBUG 1 /* verbose debugging */ int main () { float p0, p1, p2, p3; float denom, ratio; denom = 1.0 / LAMBDA1; denom += 1.0 / LAMBDA2; denom += 1.0 / LAMBDA3; denom += 1.0 / LAMBDA4; #ifdef DEBUG printf("denom value is %f\n", denom); #endif p0 = 1.0 / (LAMBDA1 * denom); #ifdef DEBUG printf("p0 is %f\n", p0); #endif ratio = LAMBDA1 / LAMBDA2; p1 = ratio * p0; #ifdef DEBUG printf("p1 is %f times p0, so p1 = %f\n", ratio, p1); #endif ratio = LAMBDA1 / LAMBDA3; p2 = ratio * p0; #ifdef DEBUG printf("p2 is %f times p0, so p2 = %f\n", ratio, p2); #endif ratio = LAMBDA1 / LAMBDA4; p3 = ratio * p0; #ifdef DEBUG printf("p3 is %f times p0, so p3 = %f\n", ratio, p3); #endif printf("\n"); printf("Analytical Markov Chain Model of Baseball\n"); printf("\n"); printf(" Prob(nobody out): p0 = %f\n", p0); printf(" Prob(one out): p1 = %f\n", p1); printf(" Prob(two out): p2 = %f\n", p2); printf(" Prob(three out): p3 = %f\n", p3); printf("\n"); printf("Sanity check: p0 + p1 + p2 + p3 = %f\n", p0 + p1 + p2 + p3); printf("\n"); }