Status: Accepted
Owner: asmeurer
Labels: Type-Defect Priority-Medium Integration EasyToFix
New issue 2276 by asmeurer: integrate() should use the ode module's
undetermined coefficients solver when possible
http://code.google.com/p/sympy/issues/detail?id=2276
So my comment 8 from issue 2219 made me realize something. Consider the
following:
In [242]: integrate(x**2*exp(x)*sin(x), x)
Out[242]:
x 2 x x 2 x
ℯ ⋅sin(x) x ⋅ℯ ⋅sin(x) cos(x)⋅ℯ x x ⋅cos(x)⋅ℯ
- ───────── + ──────────── - ───────── + x⋅cos(x)⋅ℯ - ────────────
2 2 2 2
In [245]: dsolve(f(x).diff(x) - x**2*exp(x)*sin(x), f(x),
hint='nth_linear_constant_coeff_undetermined_coefficients')
Out[245]:
x 2 x x 2
x
ℯ ⋅sin(x) x ⋅ℯ ⋅sin(x) cos(x)⋅ℯ x x ⋅cos(x)⋅ℯ
f(x) = C₁ - ───────── + ──────────── - ───────── + x⋅cos(x)⋅ℯ -
────────────
2 2 2 2
In [246]: %timeit integrate(x**2*exp(x)*sin(x), x)
1 loops, best of 3: 10.7 s per loop
In [247]: %timeit dsolve(f(x).diff(x) - x**2*exp(x)*sin(x), f(x),
hint='nth_linear_constant_coeff_undetermined_coefficients')
1 loops, best of 3: 232 ms per loop
dsolve() is way faster because it just computes the necessary form of the
integral and solves for the undetermined coefficients. No complicated
integration algorithm is needed.
So I think if the integral has the correct form, that internally
integrate(expr, x, x, ...) should use dsolve's internal undetermined
coefficient algorithms for solving f(x).diff(x, x, …) - expr. All the
necessary stuff is already in ode.py, including the function that checks if
expr is of the correct form.
--
You received this message because you are subscribed to the Google Groups
"sympy-issues" group.
To post to this group, send email to sympy-issues@googlegroups.com.
To unsubscribe from this group, send email to
sympy-issues+unsubscr...@googlegroups.com.
For more options, visit this group at
http://groups.google.com/group/sympy-issues?hl=en.