[SciPy-User] Problems with scipy.integrate.quad and sinusoidal weights

josef.pktd at gmail.com josef.pktd at gmail.com
Fri Sep 28 08:13:07 EDT 2012


On Fri, Sep 28, 2012 at 4:51 AM, Per Nielsen <evilper at gmail.com> wrote:
> 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? :)

the weight function is automatically added

>>> integrate.quad(lambda x: np.exp(-x)*np.sin(100*x), 0., 10., args=())
Warning: The maximum number of subdivisions (50) has been achieved.
  If increasing the limit yields no improvement it is advised to analyze
  the integrand in order to determine the difficulties.  If the position of a
  local difficulty can be determined (singularity, discontinuity) one will
  probably gain from splitting up the interval and calling the integrator
  on the subranges.  Perhaps a special-purpose integrator should be used.
(0.0099990111781434986, 0.00068140460275433325)

>>> integrate.quad(lambda x: np.exp(-x), 0., 10., args=(), weight='sin', wvar=100.)
(0.0099987410521618428, 7.0983734843630013e-10)

(I never used wvar before, just guessing

Josef

> Cheers,
> Per
>
>
>
> _______________________________________________
> SciPy-User mailing list
> SciPy-User at scipy.org
> http://mail.scipy.org/mailman/listinfo/scipy-user
>



More information about the SciPy-User mailing list