Ask Your Question
2

Substitute a function in a formal derivative

asked 2020-12-03 18:32:39 +0100

Cyrille gravatar image

updated 2020-12-03 18:49:06 +0100

This gives a nice result.

var('p w0 c g dc dg dp dw0')
EUa=function('EUa')(p,w0,c,g)
EUa_c=diff(EUa,c)
EUa_g=diff(EUa,g)
#
EUna=function('EUna')(p,w0,c,g)
EUna_g=diff(EUna,g)
EUna_c=diff(EUna,c)
##
dEUa=EUa_c*dc + EUa_g*dg 
dEUna=EUna_c*dc + EUna_g*dg
###
show(EUa)
show(EUna)
show(dEUa)
show(dEUna)
sol=solve(dEUa==dEUna, dg)
sol=(sol[0]/dc).full_simplify()
show(sol)

But now, I would like to substitute to EUa(p,w0,c,g) = p*U(w0)+(1-p)*U(0) and EUna(p,w0,c,g) = p*U(w0-c)+(1-p)*U(g*w0-c) then, later change the unknown function U(w) to say ln(w) or w^(1/2). I suppose I need to define first a function U=function('U')(w) after to define w as a variable. But all my tentatives fail.

edit retag flag offensive close merge delete

Comments

Hints :

  • use variable names in formal differentiations (e. g. diff(f(x,y).x) instead of diff(f, x)).

  • lookup substitute_function?

Emmanuel Charpentier gravatar imageEmmanuel Charpentier ( 2020-12-03 21:06:11 +0100 )edit

Hi @Emmanuel Charpentier

SageMath 9.2 notebook , W10

substitute_function?

Object substitute_function not found.

ortollj gravatar imageortollj ( 2020-12-04 09:13:06 +0100 )edit

Object substitute_function not found.

It's a method of symbolic expression objects. Dotting the "i"s and crossing the "t"s, try :

sage: x.substitute_function?                                                    
Docstring:     
   Return this symbolic expressions all occurrences of the function
   *original* replaced with the function *new*.

[ Snip...]

Emmanuel Charpentier gravatar imageEmmanuel Charpentier ( 2020-12-04 15:13:13 +0100 )edit

1 Answer

Sort by ยป oldest newest most voted
2

answered 2020-12-04 11:26:09 +0100

eric_g gravatar image

You should write

EUa = function('EUa')

instead of

EUa = function('EUa')(p,w0,c,g)

in order to distinguish the function EUa from its value at the point (p,w0,c,g). In this way, you will be able to use the method substitute_function to perform the substitution that you wish. If you want a shortcut for EUa(p,w0,c,g), then you should give it a name distinct from EUa. The next step to achieve what you want is to introduce a callable symbolic expression that contains the value that you want to substitute, e.g.

U = function('U')
EUa_U(p,w0,c,g) = p*U(w0) + (1-p)*U(0)
EUna_U(p,w0,c,g) = p*U(w0-c) + (1-p)*U(g*w0-c)

Then you can perform the substitution via

sol_U = sol.substitute_function(EUa, EUa_U).substitute_function(EUna, EUna_U)

Finally, the second operation that you mention is achieved by

U_1(w) = ln(w)
sol_U.substitute_function(U, U_1)

Here is the full example:

var('p w0 c g dc dg dp dw0')
EUa = function('EUa')
EUa_c = diff(EUa(p,w0,c,g), c)
EUa_g = diff(EUa(p,w0,c,g), g)
#
EUna = function('EUna')
EUna_g = diff(EUna(p,w0,c,g), g)
EUna_c = diff(EUna(p,w0,c,g), c)
#
dEUa = EUa_c*dc + EUa_g*dg 
dEUna = EUna_c*dc + EUna_g*dg
#
sol = solve(dEUa==dEUna, dg)
sol = (sol[0]/dc).full_simplify()
#
U = function('U')
EUa_U(p,w0,c,g) = p*U(w0) + (1-p)*U(0)
EUna_U(p,w0,c,g) = p*U(w0-c) + (1-p)*U(g*w0-c)
sol_U = sol.substitute_function(EUa, EUa_U).substitute_function(EUna, EUna_U)
#
U_1(w) = ln(w)
sol_U.substitute_function(U, U_1)

The outcome is

dg/dc == (g*w0 - c)*((p - 1)/(g*w0 - c) + p/(c - w0))/((p - 1)*w0)
edit flag offensive delete link more

Comments

Thanks a lot. I was just trying to do whazt you have perform nicely but without the distinction of the function and its value to the point.

Cyrille gravatar imageCyrille ( 2020-12-04 14:27:43 +0100 )edit

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: 2020-12-03 18:32:39 +0100

Seen: 462 times

Last updated: Dec 04 '20