# Integration of matrix-valued function using MATLAB

I need to compute the integral $\int_{\mathbb{R}^3}f(x)\, dx$, where $f$ is a matrix-valued function $f:\mathbb{R}^3\to\mathbb{R}^{3\times 3}$. How do I do that using MATLAB? The function $f$ is implemented in a seperate file. It takes as input three vectors, giving the $x$-, $y$-, and $z$-coordinates of the points in which is has to be evaluated. As output it gives a 5D array.

If I just write integral3(@f,-1,1,-1,1,-1,1) for instance, I get the error Integrand output size does not match the input size.

• What prevents you to perform the integration component-wisely? – Shuhao Cao Aug 9 '13 at 18:08
• Apparently, the function given to integral3 should take three 2D arrays, which in my opinion seems a little strange. And my function take three vectors. – torbonde Aug 10 '13 at 18:51

I would write this as a comment to the answer by @Mohammad Bazrafshan but since i dont have enough reputation i will write it as an answer.

What he suggested works, the official documentation for it can be found here:

http://www.mathworks.com/help/matlab/ref/integral.html#inputs

You can see that the integral function has the potential to integrate array-valued functions, like vectors and matrices.

What it does is component-wise integration of the elements of the array, so it is the same as going through all elements of the array with a loop and performing integration of many scalar-valued functions.

use command "integral" and then set the following input argument: 'ArrayValued',true

• This answer is pretty short. But the downvoter may expand on why it is not useful. Does the suggestion work or not? – Jan Sep 19 '14 at 7:56