MATLAB: Addition of matrix inside Nested Integral MATLAB

integralmatrixmatrix dimensionnested integral

I have a problem when doing nested integral. the case is like this:
int_fun = @(x) integral(@(y) x + y, 0, 1);
result = integral(@(x) int_fun(x), 1, 100);
this will shows the error matrix dimension must agree at the x + y part. how should i solve this error?
Thanks

Best Answer

When you use integral(), the argument passed will be a vector of arbitrary length. You are then using that vector of arbitrary length in the nested integral() call, which itself gets passed a vector of arbitrary length that might well be different.
int_fun = @(x) arrayfun( @(X) integral(@(y) X + y, 0, 1), x);
Better, of course, would be to use integral2()
integral2( @(x,y) x+y, 1, 100, 0, 1)