I'm trying to use recursion to solve a joint inventory/ dynamic pricing problem as in monahan, petruzzi and zhao 2004.
I tried to solve for y[t]
and k[t]
via recursion with the following code:
m = 0.5;
λ = 0.1;
k[0] = 0;
y[0] = 0;
Clear[y];
Clear[k];
r[t_Integer, z_] :=
1/z^m (-(1/λ)*E^(-λ*z) + 1/λ + k[t - 1]*λ*Integrate[(z - w)^m*E^(-λ*w), {w, 0, z}]) // N;
y[t_Integer] := y[t] = ArgMax[{r[t, j], j > y[t - 1]}, j] // N;
k[t_Integer] := k[t] = r[t, y[t]];
y[1]
I get the following message:
$RecursionLimit::reclim: Recursion depth of 1024 exceeded. >>
When I solve the problem manually, it works fine:
b = 2;
m = 1 - 1/b;
λ = 1/187;
r1[z_] := 1/z^m (-(1/λ)*E^(-λ*z) + 1/λ ) // N;
y1 = ArgMax[{r1[g], g >= 0}, g];
y1
r1[y1]
234.953 8.72688
r2[z_] :=
N[(1/z^m)*(-(1/λ)/E^(λ*z) + 1/λ + r1[y1]*λ*Integrate[(z - w)^m/E^(λ*w), {w, 0, z}])];
y2 = ArgMax[{r2[h], h >= y1}, h];
y2
r2[y2]
486.281 14.432
r3[z_] :=
N[(1/z^m)*(-(1/λ)/E^(λ*z) + 1/λ + r2[y2]*λ*Integrate[(z - w)^m/E^(λ*w), {w, 0, z}])];
y3 = ArgMax[{r3[i], i >= y2}, i];
y3
r3[y3]
687.782 18.982
...
Could anybody tell me where's my mistake?
This is the updated code, after editing the suggestions:
m = 0.5;
\[Lambda] = 1/187;
r[0, z_] := 0;
Clear[k, y];
k[0] = 0;
y[0] = 0;
r[t_Integer, z_] :=
1/z^m (-(1/\[Lambda]) Exp[-\[Lambda] z] + 1/\[Lambda] +
k[t - 1] \[Lambda] Integrate[(z - w)^m Exp[-\[Lambda] z], {w, 0,
z}]) // N;
y[t_Integer] := y[t] = ArgMax[{r[t, j], j > y[t - 1]}, j] // N;
k[t_Integer] := k[t] = r[t, y[t]];
y[1]
k[1]
y[3]
k[3]
234.953
8.72688
234.953
11.3039
k[0],y[0]
after youClear[k,y]
.. $\endgroup$