Cake Eating in Finite and Infinite Time
The following was implemented in Maple by Marcus Davidsson (2008) davidsson_marcus@hotmail.com
and is based upon the work by Adamek (2006) The CakeEating Problem
1) Cake Eating in Finite Time
Introduction
We assume that we have a cake that in the first period has a size of CS(1)

(1) 
We now assume that we have five time periods. We assume that we consume a fraction of the cake in each time period denoted by C(1), C(2), C(3), C(4).
Note that we assume that the cake is completly gone in the fifth time period which means that our consumption in period five is zero
The equation of motion for the cake size in each periods are given by
We will now derive the expressions for consumption in the four periods
Period1
The cake size in the last period is given by

(2) 
where C(1), C(2), C(3) and C(4) are the amount of consumtion in each period
We again assume that all cake is gone in the last period which means that CS(5)=0.
If we plug this into the previous equation then we get the expression for the terminal condition in period one

(3) 
We can now express this equation in C(1) terms only.
Note that we discount consumption over time where B^t is a discount factor. Note that B=1/(1+r) where r is the interest rate.
Note that since B^t < 1 it means that consumption will be decreasing over time
If we plug the all the rewritten expressions into the previous equation we get

(4) 
We now solve for CS(1)

(5) 
We now note that
We know that

(6) 
We now multiply both sides by B so we get

(7) 
Which can be written as

(8) 
Now we know that X and Y are given by

(9) 

(10) 
We now subtract BCS(initial) from both sides of CS(initial) so we get

(11) 
Which can be written as

(12) 
We now divide both sides by (1B) so we get

(13) 
We can now solve for C(1)

(14) 
Which is the expression for the optimal consumtion in period one
Period2
Our terminal condition for period two is given by

(15) 
We can now express this equation in C(2) terms only.
If we plug that into the previous equation we get

(16) 
We now solve for CS(2)

(17) 
We now note that
We know that

(18) 
We now multiply both sides by B so we get

(19) 
Which can be written as

(20) 
Now we know that X and Y are given by

(21) 

(22) 
We now subtract BCS(2) from both sides of CS(2) so we get

(23) 
Which can be written as

(24) 
We now divide both sides by (1B) so we get

(25) 
We can now solve for C(2)

(26) 
Which is the expression for the optimal consumtion in period two
Period3
Our terminal condition for period three is given by

(27) 
We can now express this equation in C(3) terms only.
If we plug that into the previous equation we get

(28) 
We now solve for CS(3)

(29) 
We now note that
We know that

(30) 
We now multiply both sides by B so we get

(31) 
Which can be written as

(32) 
Now we know that X and Y are given by

(33) 

(34) 
We now subtract BCS(3) from both sides of CS(3) so we get

(35) 
Which can be written as

(36) 
We now divide both sides by (1B) so we get

(37) 
We can now solve for C(3)

(38) 
Which is the expression for the optimal consumtion in period three
Period4
Our terminal condition for period three is given by

(39) 
The above equation is already express in only C(4) terms which means that we can solve for consumption directly

(40) 
Which is the expression for the optimal consumtion in period four
Consumtion Dynamics Over Time
We can now visualize the dynamics of consumtion over time
We first note that the equations of motion for the cake size in period two and three are given by

(41) 

(42) 

(43) 
This means that the equation of motions can be written as

(44) 

(45) 

(46) 

(47) 
We now assume that
Which means that the amount of consupmtion in each period are given by

(48) 

(49) 

(50) 

(51) 
We first make sure that all cake is consumed

(52) 
We can now plot the consumption over time
We can now plot the cake size over time
Alternative Formulation
Note that we could have solved the above problem in a much more straight forward way
We assume that our utility from cake consumption at time t is given by

(53) 
We now note that we discount utility from cake consumption over time.
The discounting is done through a discount factor B^t where B=1/(1+r) and r is the interest rate. Note that since B^t < 1 it means that will be decreasing over time.

(54) 
We now note that our objective is to maximize the sum of the discounted utility form consumption over time as seen below

(55) 
If we plug in the previous expression in this equation we get

(56) 
In our case our objective function Ob is therefor given by

(57) 

(58) 
We again assume that
This gives us

(59) 
Which is the same values of , , and we had before
2) Cake Eating in infinite Time
The cake size in the end for a n period example is given by

(60) 
We again assume that all cake is gone in the last period which means that CS(n+1)=0.
If we plug this into the previous equation then we get the expression for the terminal condition in period one

(61) 
We can now express this equation in C(1) terms only.
If we plug the all the rewritten expressions into the previous equation we get

(62) 
which can be written as

(63) 

(64) 
We now note that
##########################################
if we assume that
then the sum

(65) 
can be approximated by

(66) 
##########################################
The sum of can therefor be approximated by the expression

(67) 
which means that we can write the above expression as

(68) 
which gives us

(69) 
which means that that consumption is given by

(70) 
We now note that
##########################################
when then
We can show this by noting that
##########################################
This means that our previous equation is reduced to

(72) 
We can now visualize the consumtion and cake size over time
Consumption vector
Cake size vector
Legal Notice: The copyright for this application is owned by the authors. Neither Maplesoft nor the authors are responsible for any errors contained within and are not liable for any damages resulting from the use of this material.. This application is intended for noncommercial, nonprofit use only. Contact the authors for permission if you wish to use this application in forprofit activities.