(*by Nasser M. Abbasi, solves the inventory problem for Math 504*) Manipulate[ k = 0; A = makeA[s, maxNumberOfItems]; initialState[[maxNumberOfItems + 1]] = 1; currentState = initialState; m = MatrixPower[A, n]; currentState = initialState . m; GraphicsGrid[ { {Text[Style[MatrixForm[{currentState}]]]}, {Graphics[Text[Style[MatrixForm[MatrixPower[A, n]], 10]], ImageSize -> {500, 200}]} }, Frame -> All, Spacings -> 0 ] , {{n, 1, "Power of Matrix="}, 1, 50, 1, AppearanceElements -> All, ContinuousAction -> False}, {{s, 5, "s level="}, 1, maxNumberOfItems - 1, 1, AppearanceElements -> All, ContinuousAction -> False}, {m, None}, {g, None}, {A, None}, {k, None}, {i, None}, {j, None}, {initialState, None}, {currentState, None}, Initialization :> { maxNumberOfItems = 7; max = 8; initialState = Table[0, {i, maxNumberOfItems + 1}]; demand[j_] := Module[{}, Which[j == 0, .1, j == 1, .6, j == 2, .1, j == 3, 0, j == 4, .05, j == 5, .05, j == 6, .1, j == 7, 0, True, 0 ] ]; p[i_, j_, s_, S_] := Total[Table[demand[v], {v, S, max}]] /; (j == 0 && i < s); p[i_, j_, s_, S_] := Total[Table[demand[v], {v, i, max}]] /; (j == 0 && i >= s); p[i_, j_, s_, S_] := demand[S - j] /; (i < s && (0 < j <= S)); p[i_, j_, s_, S_] := demand[i - j] /; (i >= s && (0 < j <= i)); p[i_, j_, s_, S_] := 0; makeA[s_, S_] := Module[{}, Table[p[i, j, s, S], {i, 0, maxNumberOfItems}, {j, 0, maxNumberOfItems}] ] } ]