# [Maxima] Double integration.

Stavros Macrakis macrakis at alum.mit.edu
Thu Jan 12 10:04:48 CST 2012

```As Alexander says, you don't need the temporary variable etc.

Also, if you explicitly quote everything, you are less likely to have bad
surprises.  Something like this:

0),x,0,1)[1]),y,0,1));
(%o27)         [0.49999763949292, 3.4177098928722671E-9, 735, 0]
(%i28) cnt;
(%o28)                              621243

Note the number of function evaluations for a very simple case!  Note also
that the result is not very accurate, and that the error estimate is way
off.  I imagine there are better routines for this kind of integration.
Obviously in this case it is easy to transform to a single integral (even
analytical), but presumably you want to handle more complicated integrands.

-s

On Thu, Jan 12, 2012 at 05:38, Alexander Klimov <alserkli at inbox.ru> wrote:

> Hi.
>
> On Thu, 12 Jan 2012, Constantine Frangos wrote:
> > (1) Its not clear why the function definition I am using does not
> > work. According to the Maxima 5.24 manual, paragraph 20.4, the
> > integrand can be the name of a Maxima function, presumably defined by
> > the user in a file, for example, integrand.mac
>
> Your function does not always return a number. Consider your original
> definition:
>
> (%i1) ind(x,y) := block([s],if is(x*x + y*y <= 1) then (s : 1) else (s :
> 0),return(s))\$
>
> Let us see how it works
>
> (%i2) trace(ind);
> (%o2)                                [ind]
>
> If one gives numerical arguments, then your function returns the
> number which is assigned to "s"
>
> (%i3) ind(0,1);
> 1 Enter ind [0, 1]
> 1 Exit  ind 1
> (%o3)                                  1
>
> but with symbols as arguments nothing is assigned to "s" and thus the
> function returns just a symbol "s"
>
> (%i4) ind(x1,x2);
> 1 Enter ind [x1, x2]
> 1 Exit  ind s
> (%o4)                                  s
>
> and this is exactly what happens when you use it in integration
>
> 1 Enter ind [x1, x2]
> 1 Exit  ind s
> COERCE-FLOAT-FUN: no such Lisp or Maxima function: s
>  -- an error. To debug this try: debugmode(true);
>
> > (2) Are there perhaps other Maxima numerical integration functions
> > that may perform better ?
>
> As I said, it is better to
>
> > >  use a simple integral:
> > >
> > > (%o4)          [3.141592653589797, 2.000470900043183e-9, 399, 0]
>
> the problem with indicators is that while they may be suitable for
> rule which is only good if the function is similar to a polynomial.
>
> --
> Regards,