On Mon, Apr 19, 2010 at 12:15 AM, wb <[email protected]> wrote:
> I've tried to do timing of simple 2D integrals using sage/mpmath vs.
> mathematica.
>
> Example:
>
> ===================================================
> sage: version()
> 'Sage Version 4.3.3, Release Date: 2010-02-21'
>
> sage: %time quadgl(lambda x,y: sin(x)*cos(y)/(x**2+y**2+1),[-8, 10],
> [-6,10])
> CPU times: user 15.96 s, sys: 0.02 s, total: 15.98 s
>
> ******* Wall time: 16.00 s ********
>
> mpf('-0.0043118150747524404')
>
> sage: %time quadts(lambda x,y: sin(x)*cos(y)/(x**2+y**2+1),[-8, 10],
> [-6,10])
> CPU times: user 43.77 s, sys: 0.08 s, total: 43.85 s
>
> ****** Wall time: 43.86 s *********
>
> mpf('-0.0043118140088211727')
>
> ========================================================
> Mathematica Version 7.0.0
>
> NIntegrate[Sin[x] Cos[y]/(x^2 + y^2 + 1), {x, -8, 10}, {y, -6, 10}] //
> Timing
>
> {
>
> ****** 2.7881739999999984` ********
>
>
> , -0.004311814008789632`}
>
> This is a typical result. Mathematica seems to be faster typically by
> a factor of 5 and sometimes much more with no tweaking of the method
> of integration. If I play with the method of integration more than an
> order of magnitude of can be reached quite easily for mathematica ...
>
> Am I doing this right?
No. Don't use lambda. Use fast_float:
sage: f(x,y) = sin(x)*cos(y)/(x**2+y**2+1)
sage: import mpmath
sage: time mpmath.quadgl(fast_float(f), [-8, 10],[-6,10])
CPU times: user 0.42 s, sys: 0.01 s, total: 0.42 s
Wall time: 0.44 s
mpf('-0.0043118150747524474')
If f is a symbolic expression, then fast_float(f) returns a version
that is optimized for being called.
> I.e. is this performance difference roughly
> what I should expect for this kind of task?
> Is there another way to do numerical integration in sage?
>
> Regards,
> wb
>
> --
> To post to this group, send email to [email protected]
> To unsubscribe from this group, send email to
> [email protected]
> For more options, visit this group at
> http://groups.google.com/group/sage-support
> URL: http://www.sagemath.org
>
--
William Stein
Professor of Mathematics
University of Washington
http://wstein.org
--
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/sage-support
URL: http://www.sagemath.org