Ask Your Question
0

Define a function with different cases

asked 2016-04-13 00:20:01 +0100

Massimo2013 gravatar image

I'm working with a function whose functional form is different at a specific value of the parameter (a=1):

 if a==1:
            U(x,L)=log(x)+log(1-L)
 else:
            U(x,L)=(x^(1-a)/(1-a)+(1-L)^(1-a)/(1-a))

Is it possible to define once and for all a function U(x,L,a) which includes the parameter as a variable so that I don't need to redefine it when a = 1?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2016-04-13 16:23:08 +0100

calc314 gravatar image

You can create a Python function which does this as follows:

def U(x,L,a):
    if a==1:
            return(log(x)+log(1-L))
    else:
            return(x^(1-a)/(1-a)+(1-L)^(1-a)/(1-a))
edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2016-04-13 00:20:01 +0100

Seen: 714 times

Last updated: Apr 13 '16