Search code examples
octavenumerical-integration

I am trying to evaluate double integral on octave


So I have need to evaluate double integral on octave[![question][1]][1]

>> x1 = 1;
>> x2 = 0;
>> y1 = 2;
>> y2 = 0;
>> f = @(x,y) (y-x)./((x+y).^3);
>> integral2(f,x2,x1,y2,y1);

I entered the above code but it gives me error: "Maximum number of sub-tiles reached, accuracy may be low" and gives NAN as answer. Any solutions? This is the integral I need to evaluate: https://i.sstatic.net/Xv5AM.png


Solution

  • You can define a function f for your integrand:

    f = @(x,y) (y-x)./(x+y).^3

    Note the element-wise ./ and .^ functions to avoid matrix operations. Now use the dblquad function:

    dblquad(f,0,2,0,1)

    where those last four input arguments are your integration limits for x and y. You can also specify a different tolerance and an integrator function with additional input arguments, but the defaults work fine in this case. I obtained the answer you were expecting with this method.

    For a single-line operation, you can skip creating the integrand function by using

    dblquad( @(x,y) (y-x)./(x+y).^3 , 0 , 2 , 0 , 1 )