Got Questions? Get Answers.
Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
dblquad tolerance error?

Subject: dblquad tolerance error?

From: Alberto

Date: 22 May, 2011 13:57:04

Message: 1 of 3

can anyone explain me why this happens?:
the exact result of he following integral should be 0.25.

tol=1e-4;
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=1e-5;
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=1e-6;
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=1e-7;
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

Subject: dblquad tolerance error?

From: Roger Stafford

Date: 22 May, 2011 18:45:07

Message: 2 of 3

"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=1e-4;
> 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=1e-5;
> 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=1e-6;
> 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=1e-7;
> 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

Subject: dblquad tolerance error?

From: Alberto

Date: 22 May, 2011 19:12:03

Message: 3 of 3

"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=1e-4;
> > 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=1e-5;
> > 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=1e-6;
> > 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=1e-7;
> > 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

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us