I'm tyring to do integrals of the following form:
integrate(f(x)*DiracDelta(x-a, n), (x, -oo, oo))
When n = 0, i.e. DiracDelta has not been differentiated, then I get the correct answer of:
f(a)
When n>0, i.e. DiracDelta had been differentiated n times, then the integral is not calculated, i.e. the input:
integrate(f(x)*DiracDelta(x-a, n), (x, -oo, oo))
is returned.
If I look in sympy.functions.special.delta_functions then the docstring directs me to http://mathworld.wolfram.com/DeltaFunction.html for more info. This webpage indicates that :
integrate(f(x)*DiracDelta(x-a, n), (x, -oo, oo))
should give:
(-1)**n * diff(f(x),x , n).subs(x=a)
I can hack the source code to get what I want. In sympy.integrals.deltafunctions I make two alterations. Firstly in the change_mul function remove the restriction of n only being 0 or ommited. I replace:
if arg.func == DiracDelta and arg.is_simple(x) \
and (len(arg.args) <= 1 or arg.args[1]==0):
with the following:
if arg.func == DiracDelta and arg.is_simple(x):
Secondly, in the deltaintegrate function I replace:
return (rest_mult.subs(x, point)*Heaviside(x - point))
with the following:
try:
n = dg.args[1]
except:
n = 0
return ((-1)**n*sympy.diff(rest_mult, x, n).subs(x, point)*Heaviside(x - point))
It's probably easiest to check:
integrate(sin(x)*DiracDelta(x-a, 0), (x, -oo, oo))
integrate(sin(x)*DiracDelta(x-a, 1), (x, -oo, oo))
integrate(sin(x)*DiracDelta(x-a, 2), (x, -oo, oo))
integrate(sin(x)*DiracDelta(x-a, 3), (x, -oo, oo))
integrate(sin(x)*DiracDelta(x-a, 4), (x, -oo, oo))
should give:
sin(a)
cos(a)
-sin(a)
-cos(a)
sin(a)
Is this OK? (does it break anything else?) Can someone add it to future releases of sympy? I have no idea how to do so. This and resolution of heaviside integrations issue 4795 would be great.
Original issue for #6968: http://code.google.com/p/sympy/issues/detail?id=3869
Original author: https://code.google.com/u/117669915423549560408/
Referenced issues: #4795
sorry those last 5 expexted results are:
sin(a)
-cos(a)
-sin(a)
cos(a)
sin(a)
I forgot the (-1)**n
Original comment: http://code.google.com/p/sympy/issues/detail?id=3869#c1
Original author: https://code.google.com/u/117669915423549560408/
You should make a pull request with this change. See https://github.com/sympy/sympy/wiki/development-workflow (and also GitHub has their own guides).
One comment on your patch. Doing a raw except is usually bad. In this case, just check len(dg.args).
Regarding if it breaks anything, we have an extensive test suite, so you can just run ./bin/test to see for yourself (this will also happen automatically on Travis's test bot when you make a pull request).
**Status:** Valid
**Labels:** Integration
Original comment: http://code.google.com/p/sympy/issues/detail?id=3869#c2
Original author: https://code.google.com/u/[email protected]/
This is resolved with #10923.
Most helpful comment
This is resolved with #10923.