Did you mean this?
>>> var('r:4 m2')
(r0,r1,r2,r3,m2)(r0,r1,r2,r3,m2)
>>> m=sqrt(m2)
>>> _m2 = r0**2 + r1**2 + r2**2
>>> m.diff(m2)*_m2.diff(r0)
r0√m2r0m2
>>> (m.diff(m2)*_m2.diff(r0)).xreplace({m2:_m2})
r0√r20+r21+r22r0r02+r12+r22
Without the chain rule this can be computed as:
>>> sqrt(r0**2 + r1**2 + r2**2).diff(r0)
r0√r20+r21+r22r0r02+r12+r22
On Monday, February 19, 2018 at 1:25:34 PM UTC-6, mohab meshref wrote:
>
> so i am implementing a simple chain rule differentiation , given two
> functions m2 , m
> with:
>
> m2 = r0**2 + r1**2 + r2**2
>
> m= m2**(0.5)
>
> i want to get the differentiation of (m wrt r0), so i calculate: diff(m
> wrt m2) * diff (m2 wrt r0).
>
> expected output:
> r0 * m2**(-0.5).
>
> sympy output:
> 1.0*r0*m2(r0**2 + r1**2 + r2**2)**(-0.5)*Subs(Derivative(m(_xi_1), _xi_1),
> (_xi_1,), (m2(r0**2 + r1**2 + r2**2)**0.5,))*Subs(Derivative(m2(_xi_1),
> _xi_1), (_xi_1,), (r0**2 + r1**2 + r2**2,))
>
> ---------------------------------------------------------------
>
> first thing i want to know is why instead of writing just m2 it has to
> write this (m2(r0**2 + r1**2 + r2**2)) ?
> second, why is this term (Subs(Derivative(m(_xi_1), _xi_1), (_xi_1,),
> (m2(r0**2 + r1**2 + r2**2)**0.5,))*Subs(Derivative(m2(_xi_1), _xi_1),
> (_xi_1,), (r0**2 + r1**2 + r2**2,))) here?
> and what does it actually means?
>
> Here's my code:
>
> import sympy as sp
>
> r0, r1, r2, t0 = sp.symbols(
> "r0,r1,r2,t0", real=True)
>
> m2, m = sp.symbols('m2, m', cls=sp.Function)
>
> m2 = m2(r0**2 + r1**2 + r2**2)
>
> m = m(m2 ** (0.5))
>
> dm2r0 = sp.Derivative(m2,r0)
>
> dmm2 = sp.Derivative(m,m2)
>
> dmr0 = dmm2 * dm2r0
>
> print("dmr0:\n"+str(dmr0.doit())+"\n\n")
>
>
--
You received this message because you are subscribed to the Google Groups
"sympy" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/sympy.
To view this discussion on the web visit
https://groups.google.com/d/msgid/sympy/5b82f245-2d56-4651-b2e0-41fc65291748%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.