# The Cake Eating Problem in Sage

Im interested in running a basic cake eating problem in sage. In its recursive formulation we have to solve the following bellman equations: $$v(k_t)=ln(k_t-k_{t+1})+\beta v(k_{t+1}), \ \ \ \beta\in(0,1)$$ The algorithm for solving this problem is as follows:

Step 1: Take an initial guess of $v(k_{t+1})=0$

Step 2: Solve for the maximum of $v(k_t)$ (in the first iteration this is $v(k_t)=ln(k_t-k_{t+1})$, the maximum here is simply where $k_{t+1}=0$ thus $v(k_t)=ln(k_{t})$ )

Step 3: Using our maximum for $v(k_t)$ iterate it forward and update our bellman (in this case we have $v(k_t)=ln(k_t-k_{t+1})+\beta [ln(k_{t+1}]$)

Step 4: Maximize this updated equation and repeat until convergence.

Any help is appreciated.

Hi there. Could you provide a little more detail of what you're after? I'm not famliar with the cake eating problem, so I had to do a bit of googling to get the background needed to understand the question. As far as I can tell, you're looking at something like the example here, with

Aandaboth set to 1 (so that the cake doesn't change size), andbset to your beta (discounted utility for eating the cake in the future):Using the worked example in that wikipedia page, I played around with the problem. I think I have a feel for the problem, but I'm not sure quite what you're asking.

Related question: Ask Sage question 52565: Recursive problems.

@jaydfox I have a video which goes through the pen and paper work on solving a planners problem here:https://www.youtube.com/watch?v=Bv_tP3GP5Qg&list=PLLAPgKPWbsiQ0Ejh-twYC3Fr8_WA9BKCc&index=4. Its pretty much the same problem for a cake eating problem except the production function changed.