Hello, I'm having some problems with integral2 and the arrayfun function. In my problem, I have a function that takes as inputs vectors of size 5000×1 (lets say it uses only 3 vectors), and returns a vector of size 5000×1. This function has multiple inputs and cannot be separated, and I have to integrate over two dimensions (vectors), and the other vectors have information relative to each individual in every element. I'm trying to do write my function with arrayfun, and then integrate with integrate2, but I get the following error:
"Error using arrayfun All of the input arguments must be of the same size and shape. Previous inputs had size 5000 in dimension 1. Input #3 has size 1"
I have "tested" the function using vectors and I have no problem. Here is a minimal working example:
Y=mvnrnd(0,1,5000);normal=@(y,f1,f2) exp(y+f1+f2);g= @(f1,f2) arrayfun(normal,Y,f1,f2);test=g(zeros(5000,1),zeros(5000,1));T = integral2(@(f1,f2)g(f1,f2),-inf,inf,-inf,inf);
Does somebody knows how to solve it? I am also considering doing this using the integral function with the 'ArrayValued' option, in order to avoid using arrayfun, but I haven't found a way to do this. I also have tried using the int function, but I have problems integrating over symbolic vectors.
Thanks in advance for your answers.
Best Answer