MathGroup Archive 2010

[Date Index] [Thread Index] [Author Index]

Search the Archive

Dynamic programming and Manipulate

  • To: mathgroup at smc.vnet.net
  • Subject: [mg111361] Dynamic programming and Manipulate
  • From: Alice Lesser <alice.lesser at bwin.org>
  • Date: Thu, 29 Jul 2010 06:41:53 -0400 (EDT)

Hi group,

I'm attempting to model a 3-dimensional recurrence relation with two variable parameters a and b as follows:

discretemodel[a0_, b0_] := Module[{a = a0, b = b0},
  prob[1, 1, 1] = 1.0;
  prob[1, x_, y_] = 0;
  prob[t_, 0, y_] = 0;
  prob[t_, x_, 0] = 0;
  prob[t_, x_, y_] := prob[t - 1, x - 1, y]*a + prob[t - 1, x, y - 1]*b +=
 prob[t - 1, x, y]*(1 - a - b);
  probabilities = Table[prob[t, x, y], {t, 1, 5}, {x, 1, 5}, {y, 1, 5}];
(* some further manipulations of these t matrices of probabilities to be inserted here later *)
  Grid[probabilities[[5]]]
  ]
Manipulate[discretemodel[avalue, bvalue],
 {{avalue, 0.2}, 0, 1, 0.1},
 {{bvalue, 0.1}, 0, 1, 0.1}]

This works fine for these small values of t,x and y, but aborts for larger values such as {t,1,20}. Surely a 20 x 5 x 5 matrix is not too large for Mathematica to handle?

If I instead use the standard dynamic programming approach, so that line 6 above becomes
  prob[t_, x_, y_] := prob[t,x,y] = prob[t - 1, x - 1, y]*a + prob[t - 1, x, y - 1]*b + prob[t - 1, x, y]*(1 - a - b);

then the calculation works fine for large values of t, but I lose the Manipulate functionality (logically enough I suppose, since values of prob become fixed).
Is there a way to get around this problem?

I'm new to Mathematica after many years with another system, and it may
very well be the case that I'm not setting this model up right to begin with, any comm ents on possible better ways to do this would be much appreciated!

 Many thanks!
Alice


  • Prev by Date: Re: Problems compiling addrow with gcc-mingw (windows).
  • Next by Date: AxesLabel parallel to 3D axes?
  • Previous by thread: Re: Substiuting variables within an integral
  • Next by thread: AxesLabel parallel to 3D axes?