ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Wed, 13 May 2020 15:58:59 +0200Substitution in implicit functionhttps://ask.sagemath.org/question/51390/substitution-in-implicit-function/ 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.
Tue, 12 May 2020 18:09:05 +0200https://ask.sagemath.org/question/51390/substitution-in-implicit-function/Comment by Cyrille for <p>This is the code to the implicit differentiaion of a function from the theoretical point of view</p>
<pre><code> 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)
</code></pre>
<p>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 <code>dV.substitute_function(V, EU)</code> and <code>(sol[0]/dw1).right_hand_side()</code> 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.</p>
https://ask.sagemath.org/question/51390/substitution-in-implicit-function/?comment=51395#post-id-51395V=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. ThanksTue, 12 May 2020 19:04:24 +0200https://ask.sagemath.org/question/51390/substitution-in-implicit-function/?comment=51395#post-id-51395Comment by tmonteil for <p>This is the code to the implicit differentiaion of a function from the theoretical point of view</p>
<pre><code> 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)
</code></pre>
<p>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 <code>dV.substitute_function(V, EU)</code> and <code>(sol[0]/dw1).right_hand_side()</code> 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.</p>
https://ask.sagemath.org/question/51390/substitution-in-implicit-function/?comment=51398#post-id-51398I 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.Tue, 12 May 2020 21:08:44 +0200https://ask.sagemath.org/question/51390/substitution-in-implicit-function/?comment=51398#post-id-51398Comment by tmonteil for <p>This is the code to the implicit differentiaion of a function from the theoretical point of view</p>
<pre><code> 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)
</code></pre>
<p>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 <code>dV.substitute_function(V, EU)</code> and <code>(sol[0]/dw1).right_hand_side()</code> 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.</p>
https://ask.sagemath.org/question/51390/substitution-in-implicit-function/?comment=51392#post-id-51392What is `V` ?Tue, 12 May 2020 18:18:08 +0200https://ask.sagemath.org/question/51390/substitution-in-implicit-function/?comment=51392#post-id-51392Answer by tmonteil for <p>This is the code to the implicit differentiaion of a function from the theoretical point of view</p>
<pre><code> 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)
</code></pre>
<p>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 <code>dV.substitute_function(V, EU)</code> and <code>(sol[0]/dw1).right_hand_side()</code> 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.</p>
https://ask.sagemath.org/question/51390/substitution-in-implicit-function/?answer=51393#post-id-51393I 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)}$Tue, 12 May 2020 18:22:07 +0200https://ask.sagemath.org/question/51390/substitution-in-implicit-function/?answer=51393#post-id-51393Comment by Cyrille for <p>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 <code>def</code> statement (check for Python introductions, there are very good tutorials online):</p>
<pre><code>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)
</code></pre>
<p>Then, calling:</p>
<pre><code>my_procedure(EU)
</code></pre>
<p>leads to</p>
<p>$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}$</p>
<p>$\frac{\mathit{dw}_{2}}{\mathit{dw}_{1}} = \frac{p w_{1}^{a - 1} w_{2}^{-a + 1}}{p - 1}$</p>
<p>and </p>
<pre><code>V=function('V')(w1, w2)
my_procedure(V)
</code></pre>
<p>leads to</p>
<p>$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)$</p>
<p>$\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)}$</p>
https://ask.sagemath.org/question/51390/substitution-in-implicit-function/?comment=51402#post-id-51402I 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 ?Wed, 13 May 2020 15:58:59 +0200https://ask.sagemath.org/question/51390/substitution-in-implicit-function/?comment=51402#post-id-51402