"Roger Stafford" wrote in message <irbljj$k0v$1@newscl01ah.mathworks.com>...
> "Alberto" wrote in message <irb4ng$af4$1@newscl01ah.mathworks.com>...
> > can anyone explain me why this happens?:
> > the exact result of he following integral should be 0.25.
> >
> > tol=1e4;
> > m=1;n=8;
> > SS_SS=@(r,s) sin(m*pi*r).*sin(n*pi*s).*sin(m*pi*r).*sin(n*pi*s);
> > int=dblquad(SS_SS,0,1,0,1,tol)
> >
> > int =
> >
> > 0.148124475845163
> >
> > %%____________________________________________________
> >
> > tol=1e5;
> > m=1;n=8;
> > SS_SS=@(r,s) sin(m*pi*r).*sin(n*pi*s).*sin(m*pi*r).*sin(n*pi*s);
> > int=dblquad(SS_SS,0,1,0,1,tol)
> >
> > int =
> >
> > 0.249994642535650
> >
> >
> > in the first case the error is much more than the tolerance i decided
> > the same happens in this case:
> >
> > tol=1e6;
> > m=1;n=9;
> > SS_SS=@(r,s) sin(m*pi*r).*sin(n*pi*s).*sin(m*pi*r).*sin(n*pi*s);
> > int=dblquad(SS_SS,0,1,0,1,tol)
> >
> > int =
> >
> > 0.358850282303449
> > %%____________________________________________________
> >
> > tol=1e7;
> > m=1;n=9;
> > SS_SS=@(r,s) sin(m*pi*r).*sin(n*pi*s).*sin(m*pi*r).*sin(n*pi*s);
> > int=dblquad(SS_SS,0,1,0,1,tol)
> >
> > int =
> >
> > 0.250000001116561
> >
> > i'm using matlab R2011a
>          
> I won't try to defend 'dblquad'. It really should perform better than that. However here is my guess as to the cause of its errant behavior. With n set at 8 there is a considerable amount of variation throughout the area of integration from your sine squared of n*pi*s factor and with a low tolerance it hasn't felt the "need" to sample the integrand with fine enough resolution to fully live up to its supposed tolerance. With n equal to 9 this variation is even more pronounced.
>
> I would think that when you have an integrand with a large amount of variation you would start out being pessimistic as to tolerance and only reduce it to lower values when they prove to be adequate. Remember that 'dblquad' has no direct way of being sure it is living up to its tolerance. If you get essentially the same results with two different tolerance settings, you probably are on safe ground.
>
> Perhaps you ought to try 'quad2d' which is newer and appears to have a much more sophisticated error tolerance provision. Nevertheless even with this function I would recommend caution with respect to difficult integrands.
>
> Roger Stafford
Thanks a lot for your quick reply. i'll try out you method. for now i've seen that using quadl as method for integration
int=dblquad(SS_SS,0,1,0,1,tol,@quadl)
gives better results even if it's a little slower
Alberto Bava
