I want to create an algortihm in MATLAB which calculates a specific function and then takes integral of it to get a specific value. The dimensions of the "result" is based on the "size" paramater in the beginning of the code. For example, if size = 100, result will be a 100x100 matrix. Because of the high dimension size and useage of integral() function, runtime gets very long. I think, it is mostly because of the runtime of integral() function. Is there a way to optimize the runtime of this algortihm. Complexity and memory usage is not a problem, only improvements in runtime are needed.
size = 100;
y = zeros(2,size);
y(1,:) = 10*(randn(1,size) + 1i*randn(1,size));
y(2,:) = randn(1,size) + 1i*randn(1,size);
result = zeros(size);
for j=1:size
for i=1:size
fun = @(x) sin(x)*(y(1,i)-y(1,j)) + cos(x)*(y(2,i)-y(2,j));
result(i,j) = integral(fun,0,100);
end
end