# Revision history [back]

### Issues with Cake Eating Problem

A while back I asked about simulating the cake eating problem in sage and the algorithm seems like an excellent way to work with things. So far the code looks as follows for obtaining a soloution to the cake eating problem:

#Step1: Name variables
k,k1,v0,beta,vk,vk1=var('k,k1,v0,beta,vk,vk1')

beta=0.6
v0=log(k)

#Step 3: the Loop
for n in range(5):
vk = log(k-k1) + beta*v0(k=k1)
FOC = vk.diff(k1)
k1star = solve(FOC==0, k1)
print(n, k1star)
v0 = (vk).subs(k1=k1star[0].rhs())


The results I get are as follows:

0 [k1 == 3/8*k]
1 [k1 == 24/49*k]
2 [k1 == 147/272*k]
3 [k1 == 816/1441*k]
4 [k1 == 4323/7448*k]


Initially I thought that it would be a matter of just setting k to some value however this breaks the loop.

If I wanted to obtain values for k1 (and then plot them) how would I go about doing this?

### Issues with Cake Eating Problem

A while back I asked about simulating the cake eating problem in sage and the algorithm seems like an excellent way to work with things. So far the code looks as follows for obtaining a soloution to the cake eating problem:

#Step1: Name variables
k,k1,v0,beta,vk,vk1=var('k,k1,v0,beta,vk,vk1')

beta=0.6
v0=log(k)

#Step 3: the Loop
for n in range(5):
vk = log(k-k1) + beta*v0(k=k1)
FOC = vk.diff(k1)
k1star = solve(FOC==0, k1)
print(n, k1star)
v0 = (vk).subs(k1=k1star[0].rhs())


The results I get are as follows:

0 [k1 == 3/8*k]
1 [k1 == 24/49*k]
2 [k1 == 147/272*k]
3 [k1 == 816/1441*k]
4 [k1 == 4323/7448*k]


Initially I thought that it would be a matter of just setting k to some value however this breaks the loop.

If I wanted to obtain values for k1 (and then plot them) how would I go about doing this?

### Issues with Cake Eating Problem

A while back I asked about simulating the cake eating problem in sage and the algorithm seems like an excellent way to work with things. So far the code looks as follows for obtaining a soloution to the cake eating problem:

#Step1: Name variables
k,k1,v0,beta,vk,vk1=var('k,k1,v0,beta,vk,vk1')

beta=0.6
v0=log(k)

#Step 3: the Loop
for n in range(5):
vk = log(k-k1) + beta*v0(k=k1)
FOC = vk.diff(k1)
k1star = solve(FOC==0, k1)
print(n, k1star)
v0 = (vk).subs(k1=k1star[0].rhs())


The results I get are as follows:

0 [k1 == 3/8*k]
1 [k1 == 24/49*k]
2 [k1 == 147/272*k]
3 [k1 == 816/1441*k]
4 [k1 == 4323/7448*k]


Initially I thought that it would be a matter of just setting k to some value however this breaks the loop.

If I wanted to obtain values for k1 (and then plot them) how would I go about doing this?

### Issues with Cake Eating Problem

A while back I asked about simulating the cake eating problem in sage and the algorithm seems like an excellent way to work with things. So far the code looks as follows for obtaining a soloution to the cake eating problem:

#Step1: Name variables
k,k1,v0,beta,vk,vk1=var('k,k1,v0,beta,vk,vk1')

beta=0.6
v0=log(k)

#Step 3: the Loop
The Loop to Obtain Policy function
for n in range(5):
vk = log(k-k1) + beta*v0(k=k1)
FOC = vk.diff(k1)
k1star = solve(FOC==0, k1)
print(n, k1star)
v0 = (vk).subs(k1=k1star[0].rhs())


The results I get are as follows:

0 [k1 == 3/8*k]
1 [k1 == 24/49*k]
2 [k1 == 147/272*k]
3 [k1 == 816/1441*k]
4 [k1 == 4323/7448*k]


Initially I thought that it would be a matter of just setting k to some value however this breaks the loop.

If I wanted to obtain values for k1 (and then plot them) how would I go about doing this?