Ask Your Question
3

How can I Integrate the dirac_delta and heaviside functions in sage?

asked 2011-03-31 13:56:34 -0500

rtrwalker gravatar image

updated 2011-04-28 11:29:27 -0500

Kelvin Li gravatar image

Is it possible to integrate the dirac_delta and the heaviside function in sage. I can't seem to do it. For the dirac_delta I've tried the following code:

reset()
var('x,a')
integral(x^2*dirac_delta(-a + x), x, -infinity, +infinity)

from which, after evaluating, I get:

integrate(x^2*dirac_delta(-a + x), x, -Infinity, +Infinity)

i.e. the integration is not performed. I am expecting a^2.

For the heaviside fucntion I've tried:

reset()
var('x,x1,x2')
k(x,x1,x2)=heaviside(x-x1)*heaviside(x2-x)
integrate(k(x,x1,x2),x,-infinity,infinity)

from which, after evaluating, I get:

integrate(heaviside(-x + x2)*heaviside(x - x1), x, -Infinity, +Infinity)

I am expecting x2-x1. Am I doing something wrong or is it just not possible to do these integrations in sage?

edit retag flag offensive close merge delete

2 answers

Sort by ยป oldest newest most voted
2

answered 2011-03-31 20:04:06 -0500

DSM gravatar image

Sympy can handle the delta but not the Heaviside product:

sage: import sympy
sage: x,a = sympy.var("x a")
sage: sympy.integrate(x^2*sympy.DiracDelta(x -a), (x,-sympy.oo, sympy.oo))
a**2
sage: 
sage: x,x1,x2 = sympy.var('x,x1,x2')
sage: k=sympy.Heaviside(x-x1)*sympy.Heaviside(x2-x)
sage: sympy.integrate(k,(x, -sympy.oo, sympy.oo))
Integral(Heaviside(x2 - x)*Heaviside(x - x1), (x, -oo, oo))

Unfortunately because of interface gaps algorithm='sympy' doesn't work:

sage: reset()
sage: var("a x")
(a, x)
sage: integral(x^2*dirac_delta(-a + x), x, -infinity, +infinity,algorithm='sympy')
ERROR: An unexpected error occurred while tokenizing input
The following traceback may be corrupted or invalid
The error message is: ('EOF in multi-line statement', (534, 0))
[...]
NotImplementedError: SymPy function 'dirac_delta' doesn't exist

The monkeypatch doesn't take much, though:

sage: reset()
sage: import sympy
sage: sympy.dirac_delta = sympy.DiracDelta
sage: sage.rings.infinity.MinusInfinity._sympy_ = lambda self: -sympy.oo
sage: var("a x")
(a, x)
sage: integral(x^2*dirac_delta(-a + x), x, -infinity, +infinity,algorithm='sympy')
a^2

A better fix would be to improve sage.symbolic.expression_conversions.sympy and add more functions to the translation table. But I have the impression that sympy-style integration is considered a dead end, which is strange to me because at least I can understand the code, whereas I wouldn't know where to begin to fix a maxima issue.

edit flag offensive delete link more

Comments

No, we should totally support that if it helps improve our stuff! Please feel free to add more functions to the tables and cc: me to review the ticket.

kcrisman gravatar imagekcrisman ( 2011-04-01 04:28:45 -0500 )edit
1

answered 2011-03-31 16:06:09 -0500

kcrisman gravatar image

Maxima doesn't know how to integrate the Dirac function, so neither does Sage. From their docs:

Currently only laplace knows about the delta function.

Sage actually even mentions this use case in the manual.

But after all, it's not a function. You can integrate against it is all, but there is no symbolic integral, I guess.

I think that something similar is true for the Heaviside function.

That doesn't mean it couldn't be implemented, but there are no tickets open for this.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

Stats

Asked: 2011-03-31 13:56:34 -0500

Seen: 2,539 times

Last updated: Mar 31 '11