Apr-29-2020, 03:08 PM
Hello everyone
I have an assignment for university which I am having some problems with. We have to define a function which will return the utility depending on consumption u_1, u_2 and u_3 and parameters which are already given. U(sol,parameters) = c1**0.5 + c2**0.5 + c3**0.5. The problem comes in when we have a look how u_2 is defined: u_2 <= q * n / z. In this case n and z are known but q and u_2 arent.
This is the code I used to define the function but obviously u_3 will be 0. how can I code this an other way?
def U(sol,params):
"""
Returns the lifetime utility of a young person as a function of his consumption and money holdings (sol)
as well as the parameters of the model (params)
"""
y, z, n, beta = params
q = sol
u_1 = (y - q) ** (1/2)
u_2 = ((n / z) * q) ** (1/2)
u_3 = ((n/z)**2 * q - (n/z)**2 * q)** (1/2)
return u_1 + beta * u_2 + beta**2 * u_3
I have an assignment for university which I am having some problems with. We have to define a function which will return the utility depending on consumption u_1, u_2 and u_3 and parameters which are already given. U(sol,parameters) = c1**0.5 + c2**0.5 + c3**0.5. The problem comes in when we have a look how u_2 is defined: u_2 <= q * n / z. In this case n and z are known but q and u_2 arent.
This is the code I used to define the function but obviously u_3 will be 0. how can I code this an other way?
def U(sol,params):
"""
Returns the lifetime utility of a young person as a function of his consumption and money holdings (sol)
as well as the parameters of the model (params)
"""
y, z, n, beta = params
q = sol
u_1 = (y - q) ** (1/2)
u_2 = ((n / z) * q) ** (1/2)
u_3 = ((n/z)**2 * q - (n/z)**2 * q)** (1/2)
return u_1 + beta * u_2 + beta**2 * u_3