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:
Matlab's Quadl results wrong

Subject: Matlab's Quadl results wrong

From: Innocent

Date: 31 Jul, 2011 20:24:11

Message: 1 of 5

I need help to figure out why using matlab's quad function to solve a simple double inetgral results in a wrong answer.

the integral is:

int_0^1 log int_0^1 (x+y) dx dy,

using the following function

function z=intlog(y) n=length(y); z=zeros(size(y)); for j=1:n a=0;b=0; fy=@(x)(x+y(j)) z(j)=quadl(fy,a,b) end return

the correct answer is -1.3333... but running the above function in the command window as:q=quad(@intlog,0,1) gives the solution -0.0452.

Subject: Matlab's Quadl results wrong

From: Roger Stafford

Date: 31 Jul, 2011 21:34:10

Message: 2 of 5

"Innocent " <2400163@uwc.ac.za> wrote in message <j14dlb$kqq$1@newscl02ah.mathworks.com>...
> I need help to figure out why using matlab's quad function to solve a simple double inetgral results in a wrong answer.
>
> the integral is:
>
> int_0^1 log int_0^1 (x+y) dx dy,
>
> using the following function
>
> function z=intlog(y) n=length(y); z=zeros(size(y)); for j=1:n a=0;b=0; fy=@(x)(x+y(j)) z(j)=quadl(fy,a,b) end return
>
> the correct answer is -1.3333... but running the above function in the command window as:q=quad(@intlog,0,1) gives the solution -0.0452.
- - - - - - - - - - - -
  The correct solution is actually 1/2*log(27/4)-1 = -0.045228748 .

  The integrand of the outer integral is:

 log(int_0^1 x+y dx) = log( (1^2/2+1*y)-(0^2/2+0*y) ) = log(1/2+y) .

Then doing integration by parts:

 int_0^1 log(1/2+y) dy =
  (1/2+1)*log(1/2+1)-(1/2+0)*log(1/2+0) - int_0^1 (1/2+y)/(1/2+y) dy
  = 3/2*log(3/2) - 1/2*log(1/2) - 1
  = 1/2*log((3/2)^3/(1/2)) -1 = 1/2*log(27/4 - 1 = -0.045228748

Roger Stafford

Subject: Matlab's Quadl results wrong

From: Jan Simon

Date: 1 Aug, 2011 00:50:28

Message: 3 of 5

Dear Innocent,

> I need help to figure out why using matlab's quad function to solve a simple double inetgral results in a wrong answer.

There are two questions about this at MATLAB Answers and one here. Three people and Matlab replied the correct correct result.
This is not an efficient method to solve an integral.

Kind regards, Jan

Subject: Matlab's Quadl results wrong

From: Silibelo Kamwi

Date: 1 Aug, 2011 09:50:11

Message: 4 of 5

Thanks Roger, The answer from matlab is correct, my working was wrong as i missed inetgrating by parts, my calculus is rust i guess.

Thanks indeed.
Innocent



"Roger Stafford" wrote in message <j14hoi$m1$1@newscl02ah.mathworks.com>...
> "Innocent " <2400163@uwc.ac.za> wrote in message <j14dlb$kqq$1@newscl02ah.mathworks.com>...
> > I need help to figure out why using matlab's quad function to solve a simple double inetgral results in a wrong answer.
> >
> > the integral is:
> >
> > int_0^1 log int_0^1 (x+y) dx dy,
> >
> > using the following function
> >
> > function z=intlog(y) n=length(y); z=zeros(size(y)); for j=1:n a=0;b=0; fy=@(x)(x+y(j)) z(j)=quadl(fy,a,b) end return
> >
> > the correct answer is -1.3333... but running the above function in the command window as:q=quad(@intlog,0,1) gives the solution -0.0452.
> - - - - - - - - - - - -
> The correct solution is actually 1/2*log(27/4)-1 = -0.045228748 .
>
> The integrand of the outer integral is:
>
> log(int_0^1 x+y dx) = log( (1^2/2+1*y)-(0^2/2+0*y) ) = log(1/2+y) .
>
> Then doing integration by parts:
>
> int_0^1 log(1/2+y) dy =
> (1/2+1)*log(1/2+1)-(1/2+0)*log(1/2+0) - int_0^1 (1/2+y)/(1/2+y) dy
> = 3/2*log(3/2) - 1/2*log(1/2) - 1
> = 1/2*log((3/2)^3/(1/2)) -1 = 1/2*log(27/4 - 1 = -0.045228748
>
> Roger Stafford

Subject: Matlab's Quadl results wrong

From: Silibelo Kamwi

Date: 1 Aug, 2011 09:56:28

Message: 5 of 5

Thanks for pointing me in the right direction.

regards
Innocent


"Jan Simon" wrote in message <j14t8k$qj4$1@newscl02ah.mathworks.com>...
> Dear Innocent,
>
> > I need help to figure out why using matlab's quad function to solve a simple double inetgral results in a wrong answer.
>
> There are two questions about this at MATLAB Answers and one here. Three people and Matlab replied the correct correct result.
> This is not an efficient method to solve an integral.
>
> Kind regards, Jan

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