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.Sun, 24 May 2020 05:00:55 +0200general implicit differentiationhttps://ask.sagemath.org/question/51519/general-implicit-differentiation/Recently i have been helped to write an implicit function differentiator (nice neologism isn't it). Here is the code
def implicit_derivative(V):
var("dw1, dw2")
V_w1 = diff(V, w1)
V_w2 = diff(V, w2)
# Differential
dV = V_w1 * dw1 + V_w2 * dw2
# Dérivée du premier ordre
sol=solve(dV==0, dw2)
impder=(sol[0]/dw1)
return impder
This work without difficulty for $V$ function of $w_1$ and $w_2$. But if my variables are $x$ and $y$ or say $\chi$ and $\zeta$. It will not work. I have not found the mechanism to define a general function not dependant of the name of its arguments. And here there is a second problem to find thway to associate the increase d... to its correlative argument that is if I use $\chi$ as the first variable $d\chi$ must substitute to $dw_1$.Sat, 23 May 2020 17:11:32 +0200https://ask.sagemath.org/question/51519/general-implicit-differentiation/Answer by tmonteil for <p>Recently i have been helped to write an implicit function differentiator (nice neologism isn't it). Here is the code</p>
<pre><code>def implicit_derivative(V):
var("dw1, dw2")
V_w1 = diff(V, w1)
V_w2 = diff(V, w2)
# Differential
dV = V_w1 * dw1 + V_w2 * dw2
# Dérivée du premier ordre
sol=solve(dV==0, dw2)
impder=(sol[0]/dw1)
return impder
</code></pre>
<p>This work without difficulty for $V$ function of $w_1$ and $w_2$. But if my variables are $x$ and $y$ or say $\chi$ and $\zeta$. It will not work. I have not found the mechanism to define a general function not dependant of the name of its arguments. And here there is a second problem to find thway to associate the increase d... to its correlative argument that is if I use $\chi$ as the first variable $d\chi$ must substitute to $dw_1$.</p>
https://ask.sagemath.org/question/51519/general-implicit-differentiation/?answer=51520#post-id-51520You can see which symbolic variables are used by the input `V` with `V.variables()`. Then, you can define the corresponding derivation symbols by looking to their string representation, add the letter `'d'` in front of them, and make them symbols with `SR.var` function. So, the following should work:
def implicit_derivative(V):
w1, w2 = V.variables()
dw1 = SR.var('d{}'.format(w1))
dw2 = SR.var('d{}'.format(w2))
V_w1 = diff(V, w1)
V_w2 = diff(V, w2)
# Differential
dV = V_w1 * dw1 + V_w2 * dw2
# Dérivée du premier ordre
sol=solve(dV==0, dw2)
impder=(sol[0]/dw1)
return impder
Sat, 23 May 2020 18:31:29 +0200https://ask.sagemath.org/question/51519/general-implicit-differentiation/?answer=51520#post-id-51520Comment by Cyrille for <p>You can see which symbolic variables are used by the input <code>V</code> with <code>V.variables()</code>. Then, you can define the corresponding derivation symbols by looking to their string representation, add the letter <code>'d'</code> in front of them, and make them symbols with <code>SR.var</code> function. So, the following should work:</p>
<pre><code>def implicit_derivative(V):
w1, w2 = V.variables()
dw1 = SR.var('d{}'.format(w1))
dw2 = SR.var('d{}'.format(w2))
V_w1 = diff(V, w1)
V_w2 = diff(V, w2)
# Differential
dV = V_w1 * dw1 + V_w2 * dw2
# Dérivée du premier ordre
sol=solve(dV==0, dw2)
impder=(sol[0]/dw1)
return impder
</code></pre>
https://ask.sagemath.org/question/51519/general-implicit-differentiation/?comment=51527#post-id-51527Thanks. Very nice code. Therer is a little 'bmol' look at the result of this
χ, ζ =var('chi zeta')
V=function('V')(χ, ζ)
implicit_derivative(V)Sun, 24 May 2020 05:00:55 +0200https://ask.sagemath.org/question/51519/general-implicit-differentiation/?comment=51527#post-id-51527