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)
user541686
  • 205,094
  • 128
  • 528
  • 886
Rastapopoulos
  • 487
  • 2
  • 18

2 Answers2

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).

Wajih
  • 905
  • 9
  • 13
  • Thanks, but `sympy.Derivative(u(x)*v(x), x)` does not expand the derivative, so it's not really what I'm looking for... – Rastapopoulos Jul 02 '18 at 12:29
  • `Derivative(u(x)*v(x), x).doit()` will expand the derivative as `u(x)*Derivative(v(x), x) + v(x)*Derivative(u(x), x)`. – smichr Jul 07 '19 at 17:44
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)]
asmeurer
  • 86,894
  • 26
  • 169
  • 240