MATLAB: Using integral2 on a matrix with function handler components

function handler matrixintegral2

Let's say that I have the following function: A = @(x,y) [x,x+y;x-y,y]; and I want to calculate the following integral: Q = integral2(A,0,2,3,5) How can I do this? How can I access and use the function that is defined inside the component i and j of my matrix? I cannot use e_i*A*e_j' because it is still matrix.
P.S. Here I know my function, but in my code I have a product of two different function handler matrix, thus I do not know my function s.t. I know here.

Best Answer

It seems that integral2 doesn’t take matrix integrands, but integral will, with the 'ArrayValued',true option.
This looks slightly strange, but see if it does what you want it to:
A = @(x,y) [x, x+y; x-y, y];
Q = integral(@(y) integral(@(x)A(x,y) ,0,2, 'ArrayValued',true), 3,5, 'ArrayValued',true)
It does produce the correct results with the matrix in your example. (Hand-calculating them to check it is fairly straightforward, if slightly tedious.)
Q =
4.0000e+000 20.0000e+000
-12.0000e+000 16.0000e+000