Ask Your Question
0

Substitution in implicit function

asked 2020-05-12 18:09:05 +0200

Cyrille gravatar image

This is the code to the implicit differentiaion of a function from the theoretical point of view

    var("w1, w2, a, p")
    EU(w1, w2, a, p)= p*w1^a+ (1-p)*w2^a
    var("dw1, dw2")
    V_w1 = diff(V, w1)
    V_w2 = diff(V, w2)
    # Differential
    dV = V_w1 * dw1 + V_w2 * dw2 
    show("dV ="+latex(dV))
    # Dérivée du premier ordre
    sol=solve(dV==0, dw2)
    show(sol[0]/dw1)

Now without to be obliged to rewrite all the commands, I would like to apply this procedure to the EU function or any other function. I have tried to use dV.substitute_function(V, EU) and (sol[0]/dw1).right_hand_side() but without success. I have an amplified problem for the second order derivative since I am nosure of my formulation due to the fact that one must substitute the first order derivative inside derivation.

edit retag flag offensive close merge delete

Comments

What is V ?

tmonteil gravatar imagetmonteil ( 2020-05-12 18:18:08 +0200 )edit

V=function('V')(w1, w2). The solution you propose works nicely but not for the theoretical presentation since my_procedure(V)return an error. I would like both but at last this is nice. Then I realize it suffice ta add return to your code to obtain what I was searching. Thanks

Cyrille gravatar imageCyrille ( 2020-05-12 19:04:24 +0200 )edit
2

I am not sure what is wrong in my answer which merits a downvote, I do not get an error for the abstract V, see my update.

tmonteil gravatar imagetmonteil ( 2020-05-12 21:08:44 +0200 )edit

1 Answer

Sort by » oldest newest most voted
1

answered 2020-05-12 18:22:07 +0200

tmonteil gravatar image

updated 2020-05-12 21:09:22 +0200

I am not completely sure about your question, but i guess that what you call "procedure" is actually a Python function, which you can define using the def statement (check for Python introductions, there are very good tutorials online):

var("w1, w2, a, p")
EU(w1, w2, a, p)= p*w1^a+ (1-p)*w2^a

def my_procedure(V): 
    var("dw1, dw2")
    V_w1 = diff(V, w1)
    V_w2 = diff(V, w2)
    # Differential
    dV = V_w1 * dw1 + V_w2 * dw2 
    show("dV ="+latex(dV))
    # Dérivée du premier ordre
    sol = solve(dV == 0, dw2)
    show(sol[0]/dw1)

Then, calling:

my_procedure(EU)

leads to

$dV = \left( w_{1}, w_{2}, a, p \right) \ {\mapsto} \ a \mathit{dw}_{1} p w_{1}^{a - 1} - a \mathit{dw}_{2} {\left(p - 1\right)} w_{2}^{a - 1}$

$\frac{\mathit{dw}_{2}}{\mathit{dw}_{1}} = \frac{p w_{1}^{a - 1} w_{2}^{-a + 1}}{p - 1}$

and

V=function('V')(w1, w2)
my_procedure(V)

leads to

$dV = \mathit{dw}_{1} \frac{\partial}{\partial w_{1}}V\left(w_{1}, w_{2}\right) + \mathit{dw}_{2} \frac{\partial}{\partial w_{2}}V\left(w_{1}, w_{2}\right)$

$\frac{\mathit{dw}_{2}}{\mathit{dw}_{1}} = -\frac{\frac{\partial}{\partial w_{1}}V\left(w_{1}, w_{2}\right)}{\frac{\partial}{\partial w_{2}}V\left(w_{1}, w_{2}\right)}$

edit flag offensive delete link more

Comments

I have a little complementary question : this procedure is define for $w_1$, $w_2$ and then for $dw_1$ and $d_w2$. Ok but if my variables are say $x$ and $y$ I would like to work with $dx$ and $dy$. How to do in such a way to have an universal procedure ?

Cyrille gravatar imageCyrille ( 2020-05-13 15:58:59 +0200 )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-05-12 18:09:05 +0200

Seen: 419 times

Last updated: May 12 '20