Say I wanted to integrate
f=@(x) [1,0];
integral2( @(x,y) f(x)*f(y)' ,0,1,0,1 );
But this gives the error
Integrand output size does not match the input size.
Even though f is a vector, I am taking the dot product so the input size is 1x1. Ideally I want to use vector notation to compute dot products in the integrand, because I have a much more complex inner product which would be a pain to write out by hand. For 1D integrals you can set arrayvalued to true, but not for 2D.
How do I numerically double integrate a function containing a dot product?
While your question provides wrong code, something like this reproduces your error:
The error is simply because your integral function is not in the format that
integral2accepts. Your function needs to accept array inputs, and return array outputs of corresponding value.i.e.
Just rewrite your function so it can be evaluated in more than one
[x,y]pair at the same time, make it a vectorized function. Remember that the input does not need to be an anonymous function defined in one line, you are free to write a full function in a separate file, and use that forintegral2.