I created a formula where
t = time
x,y is rugby union score
p3h, p5g etc are probabilities of scores (penalty-drop goal =3p, try -no conversion =5 p, try+conv =7 p) etc
g[t_, x_, y_] := g[t, x, y] = Which[
x < 0 || y < 0, 0,
x == 0 && y == 0 && t == 0, 1,
(x != 0 || y != 0) && t == 0, 0,
x == 1 || x == 2 || x == 4 || y == 1 || y == 2 || y == 4, 0,
t > 0,
p3h*g[t - 1, x - 3, y] + p3a*g[t - 1, x, y - 3] +
p5h*g[t - 1, x - 5, y] + p5a*g[t - 1, x, y - 5] +
p7h*g[t - 1, x - 7, y] + p7a*g[t - 1, x, y - 7] +
pns*g[t - 1, x, y]
]
things are fast if I calculate a possible score in an early state of the game (t=1-80)
but when I want to compute something later on, it gets really slow (g[45, 15,7] for instance).
Furthermore if I want to sum all possible scores where home wins
Sum[g[79,i,j],{i,1,500},{j,0,i-1}]
then it takes ages.
Does anyone have any idea how to improve speed?
Should I create something similar in excel (lets sat a tennis markov chain with less states as rugby) it makes all calculations instanetly. Apparently because every state is calclated once.
Any idea? My knowledge in mathematica coding is really poor.
Thanks in advance.
