Search code examples
matlabintegral

Double integral - Matlab


Trying to find double integral of that function: enter image description here

Matlab code:

x = -1:0.05:1;
y = 0:0.05:1;
[x,y] = meshgrid(x);
F = sqrt((x).^2.*y) * ((sin((x).^2 .* (y).^2)).^3) - ((cos((x).^3.*(y).^3)).^5);
surfl(x,y,F);
colormap summer;
shading interp;
dblquad('sqrt((x).^2.*y) * (sin((x).^2 .* (y).^2)).^3 - (cos((x).^3.*(y).^3)).^5', -1, 1, 0, 1)

Errors:

Untitled Error using surf (line 57) X, Y, Z, and C cannot be complex.

Error in surfl (line 129) h = surf(cax,x,y,z);

Error in Untitled (line 5) surfl(x,y,F);

How can I solve these errors?


Solution

  • In this line:

    [x,y] = meshgrid(x);
    

    You are basically doing:

    [x,y] = meshgrid(x, x);
    

    So basically x and y both go from -1 to 1 and since the equation has a sqrt(x.^2 .* y), you will get complex numbers. To generate a mesh using x, y with the bounds you specified for x,y use:

    [x,y] = meshgrid(x, y);