Hi there, I have a little trouble with the following numerical integration problem. At the moment I have created two coefficient matrices A and B which are applied to the function handle fi. Both matrices A and B are of size n x n x n. The function is of the sort:
f = @(t) cos(A*t) + sin(B + sin(2*A*t))
The real function is more complex but I think this is sufficient for the problem I'm having. This function should be integrated, where the upper limit is stored in A at each corresponding position. I already tried arrayfun.
arrayfun(@(x) integral(f, 0, x, 'ArrayValued', true), A, 'UniformOutput', false)
But I don't think that it does what I want it to do, which is simply to numerically integrate for each individual instance of the function in the array with the corresponding upper limit.
It is maybe helpful to state where I'm coming from with this problem. The core problem is that I'm having a function that uses 3 for-loops to accomplish what I'm trying to do without any loops:
for i = 1:h
for j = 1:t
theta_s = theta(j);
for k = 1:v,
To = aux(i,j) * aux2(k);
result = integral(f, 0, To);
Integ2(i,j,k) = aux3(k,j) * result / Integ1(j);
Here theta, aux, aux2, aux3 and Integ1 are arrays, which are passed to the function. To and theta_s are declared as global variables, so that the function f always uses the correct values for the evaluation of the integral.
Since the whole function is called in other for-loops, it takes forever to do it this way and I think there must be a way to solve this loop-free and therefore faster. Maybe I'm just to worked up in the problem and can't see the wood for the trees. Help is greatly appreciated.
Thanks in advance