I need to perform a double integration using experimental data, but my integration limits are the same for each integral, in this case, the time. Mathematically I need to calculate:
E [ a0+ ∫0T a(t)dt ] = a + limTx → ∞ (1/T) ∫0T ∫0t a dt dT
After some search, I reached to:
T = 0:0.1:600;
x = T;
A = rand(1,length(T)); % my data
pp_int = spline(T,A );
DoubleIntegration = integral(@(x)arrayfun(@(T )(integral(@(T ) ppval(pp_int,T ),0, T )),x),0,T(end) );
The code took so long to run and give huge values. I think my problem is that Matlab might have trouble dealing with the splines, but I have no idea how to solve that.
First of all, you should not use the same letter for a bunch of things; your code is pretty hard to read because one has to figure out what T means at every instance.
Second, pure math helps: after a change of variables and simple computation, the double integral becomes a single integral:
∫0T ∫0x a(t) dt dx = ∫0T ∫tT a(t) dx dt = ∫0T (T-t)*a(t) dt
I used non-random data on a smaller range for demonstration:
Output:
Same result, 3800 times faster.