MATLAB: Double Integral of Several Functions where Integrand is in Symbolic Array Format

double integralintegrationsymbolic mathSymbolic Math Toolboxvpaintegral

Is there a way to calculate several double integrals simultaneously if the integrand function is first written in symbolic math format? I tried the vpaintegral function in the following way but it didn't work.
Z(x,y)=[f1(x,y) f2(x,y) ...]
INT=vpaintegral(Z,x,[x_start x_end],y,[y_start y_end])
where fi(x,y) are first calculated in a separate symbolic math routine and then assigned to the function Z.

Best Answer

Hi Saeid,

In order to perform integration of symbolic functions, you can use the int function from Symbolic Math Toolbox. This function can directly operate on a matrix of symbolic functions too. If you need to do a double integration (say integrate w.r.t x and y), you need to use the int function twice, first integrate your function w.r.t x and then integrate the result hence obtained w.r.t y (or vice-versa). For example, to perform the double integral of f(x,y) =xy over the region (x = 0 to x = 1 and y = 0 to y =1), we can use:

    syms x y
    f = x*y;
    value = int(int(f,x,0,1),y,0,1)
    value =
          1/4

Here the inner integral is w.r.t to x and the outer integral is w.r.t y.

The same applies for a matrix of symbolic functions also, for example

    syms x y
    A = [x + y, x^2 + y^2; x - y, x^2 - y^2];
    value = int(int(A,x,0,1),y,0,1)
    value = 
           [ 1, 2/3]
           [ 0,   0]