DiracDelta 没有给出正确的结果 [英] DiracDelta not giving correct result
本文介绍了DiracDelta 没有给出正确的结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我必须在复杂的积分中使用 dirac delta 并希望看到它如何处理一个简单的案例,但它返回了错误的答案.任何线索我在下面做错了什么?
I have to use dirac delta in a complicated integral and was hoping to see how it works with a simple case but it returns the wrong answer. Any clue what I did wrong in the following?
from sympy import DiracDelta
from scipy import integrate
def f(x):
return x*DiracDelta(x-1)
b, err = integrate.quad(f, 0, 5)
print b
这会返回 0.0
而它不应该.
This returns 0.0
while it shouldn't.
推荐答案
看来 sympy
功能与 scipy
集成不兼容.一个需要使用 sympy
集成.以下给出正确答案
It seems sympy
functions are not compatible with scipy
integrate. One needs to use sympy
integrate. The following gives the correct answer
from sympy import *
x = Symbol('x')
print integrate(x*DiracDelta(x-1), (x, 0, 5.0))
虽然,我不确定 sympy.integrate
是否和 scipy.integrate
一样强大和通用.
Although, I am not sure if sympy.integrate
is as powerful and versatile as scipy.integrate
.
这篇关于DiracDelta 没有给出正确的结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文