Hi,

I'm not sure how to do the substitution, but why do you expect
 obj_function.diff(x) to be
Derivative(Theta(U(x), x), x) + Derivative(U(x), x)* Derivative(Theta(U(x),
x), U(x)) ?

I think the answer you are getting from sympy is not correct.
obj_function.diff(x) should be the same as Derivative(Theta(U(x), x), x),
but that is not what sympy is giving.
See, https://github.com/sympy/sympy/issues/8510

CSymPy is giving,
Derivative(U(x), x)*Subs(Derivative(Theta(_x, x), _x), (_x), (U(x))) +
Subs(Derivative(Theta(U(x), _x), _x), (_x), (x))
which I think should be the correct answer.

Here what  Subs(Derivative(Theta(U(x), _x), _x), (_x), (x)) means is
partial differentiate Theta with respect to the second variable and replace
the first variable with U(x) and the second with x.
(D[2](Theta)(U(x), x) is the equivalent in Maple syntax or Derivative[0,
1][Theta][U[x], x] in Mathematica syntax)

Isuru Fernando


On Fri, May 1, 2015 at 8:16 PM, Miguel Angel Salazar de Troya <
salazardetr...@gmail.com> wrote:

> Hello
>
> I have this derivative of a function that has an argument which is also a
> function
>
> # Declaration
> x = symbols('x')
> U, Theta = symbols('U Theta', cls=Function)
>
> # Function to derive
> obj_function = Theta(U(x),x)
>
> # Derivative
> gradient_obj_function = obj_function.diff(x)
>
> And this is the output I obtain
>
> Derivative(Theta(U(x), x), x) + Derivative(U(x),
> x)*Subs(Derivative(Theta(_xi_1, x), _xi_1), (_xi_1,), (U(x),))
>
> How can I replace Subs(Derivative(Theta(_xi_1, x), _xi_1), (_xi_1,),
> (U(x),)) with Derivative(Theta(U(x), x), U(x)) ?
> I found this post, 
> https://groups.google.com/forum/#!searchin/sympy/"chain$20rule"/sympy/OfF5PklJtmY/t1FPWt3n8xIJ,
> but it was not clear to me how this has to be done.
>
> Thanks
> Miguel
>
> --
> 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 sympy+unsubscr...@googlegroups.com.
> To post to this group, send email to sympy@googlegroups.com.
> Visit this group at http://groups.google.com/group/sympy.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/sympy/5d9dfd23-be1a-4a08-9289-43562d0062f5%40googlegroups.com
> <https://groups.google.com/d/msgid/sympy/5d9dfd23-be1a-4a08-9289-43562d0062f5%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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 sympy+unsubscr...@googlegroups.com.
To post to this group, send email to sympy@googlegroups.com.
Visit this group at http://groups.google.com/group/sympy.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sympy/CA%2B01voNocna%3D5Frerhb5Fy8nU59zdSPXnaO6A5SEXwp2cRZTeg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to