Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
coding a function
#4
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 total utility depending on consumption single utilities u_1, u_2 and u_3.
U(sol,parameters) = u_1 + beta * u_2 + beta**2 * u_3. 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(as are y and beta later on) but q isnt.

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?

I have to create a function where I can plug in q and the parameters and get the total Utility U
The first part is the description of the function that my teacher has given me.
 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 
Reply


Messages In This Thread
coding a function - by helpless_coder - Apr-29-2020, 03:08 PM
RE: coding a function - by pyzyx3qwerty - Apr-29-2020, 03:19 PM
RE: coding a function - by jefsummers - Apr-29-2020, 04:26 PM
RE: coding a function - by jefsummers - Apr-29-2020, 10:01 PM
RE: coding a function - by helpless_coder - Apr-29-2020, 10:42 PM
RE: coding a function - by jefsummers - Apr-30-2020, 02:10 AM
RE: coding a function - by deanhystad - Apr-30-2020, 03:31 AM
help with coding a function - by helpless_coder - Apr-29-2020, 04:41 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
Question Need help with NumPy Histogram function coding Triikey 1 972 May-15-2023, 01:45 PM
Last Post: deanhystad
  New to Python - tiny coding assistance on user input function and assign to variable Mountain_Duck 1 2,538 Mar-23-2019, 06:54 PM
Last Post: Yoriz

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020