Using the built-in MATLAB profiler, the biggest computational load is in the evaluations of integral(). Which is no surprise since it is notoriously slow inside for loops, let alone inside a double for-loop inside a recursive function, when there are much more efficient ways of integration.
Below, I've rewritten your code to exclude for loops and calculate everything as efficiently as I could come up with. Also, I shifted n down by one compared to your code to be more consistent with the equations you provided.
plot(t,x,'-b','LineWidth',2);
if n < 0 || ~isscalar(n) || fix(n)~=n
error('"n" must be a non-negative integer.');
x(i,idx1) = 2*cumtrapz(t(idx1),u(idx1));
function u = control(n,t)
u(idx2) = cumtrapz(t(idx2), x(n,idx2));
Edit: My apologies, I forgot the
upper bound on the integral of
. It is highlighted in the comments above.