Can SymPy recognize the derivative of a product?
Asked Answered
S

2

7

In the program below, SymPy does not seem to understand that the integrand is the derivative of a product. Is there a way to make it return u*v?

import sympy
x = sympy.symbols('x', real=True)
u = sympy.Function('u')
v = sympy.Function('v')
print((u(x) * v(x)).diff(x).integrate(x))

Prints:

> Integral(u(x)*Derivative(v(x), x) + v(x)*Derivative(u(x), x), x)
Skew answered 29/6, 2018 at 9:47 Comment(3)
I tried (u*v).diff(x).integrate(x) and got the same output.Taxiplane
The answer is no.Philtre
@Philtre If not possible using built in SymPy functions, I'm also interested in the possibility of extending the integrate function to make it possible...Skew
D
0

what about sympy.Derivative(u(x)*v(x), x).integrate(x)

note that (u(x)*v(x)).integrate(x).diff(x) is simplyfied to u(x)*v(x).

Disjunct answered 2/7, 2018 at 12:16 Comment(2)
Thanks, but sympy.Derivative(u(x)*v(x), x) does not expand the derivative, so it's not really what I'm looking for...Skew
Derivative(u(x)*v(x), x).doit() will expand the derivative as u(x)*Derivative(v(x), x) + v(x)*Derivative(u(x), x).Clouded
T
0

This isn't implemented yet. The comment on this SymPy issue shows one way you can compute it using dsolve.

In [4]: solve(dsolve(diff(f(x)*g(x), x) - h(x).diff(x), f(x)), h(x))
Out[4]: [-C₁ + f(x)⋅g(x)]
Tigress answered 18/12, 2019 at 23:12 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.