Per Nielsen
2012-09-28 08:51:58 UTC
Hi all,
I am getting some strange (wrong or highly unaccurate) results when I try
to use scipy.integrate.quad to integrate highly oscillatory functions.
Please consider the following code:
In [40]: from scipy.integrate import quad
In [41]: from math import exp, sin, cos
In [42]: fsin = lambda x: exp(-x) * sin(100*x)
In [43]: quad(fsin, 0., 10., args=(), weight='sin', wvar=100.)
Out[43]: (0.4974066723952844, 0.0005303917238325333)
In [44]: quad(fsin, 0., 10., args=())
Out[44]: (0.0099990111781435, 0.0006814046027542903)
where the last line, without the weight function gives the correct result.
I have looked at the documentain for quad at:
https://github.com/scipy/scipy/blob/master/scipy/integrate/quadpack.py#L134
and to me this should be the way to integrate fsin. Am I misunderstanding
the arguments or whats going on? :)
Cheers,
Per
I am getting some strange (wrong or highly unaccurate) results when I try
to use scipy.integrate.quad to integrate highly oscillatory functions.
Please consider the following code:
In [40]: from scipy.integrate import quad
In [41]: from math import exp, sin, cos
In [42]: fsin = lambda x: exp(-x) * sin(100*x)
In [43]: quad(fsin, 0., 10., args=(), weight='sin', wvar=100.)
Out[43]: (0.4974066723952844, 0.0005303917238325333)
In [44]: quad(fsin, 0., 10., args=())
Out[44]: (0.0099990111781435, 0.0006814046027542903)
where the last line, without the weight function gives the correct result.
I have looked at the documentain for quad at:
https://github.com/scipy/scipy/blob/master/scipy/integrate/quadpack.py#L134
and to me this should be the way to integrate fsin. Am I misunderstanding
the arguments or whats going on? :)
Cheers,
Per