|
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
|