I have two functions qMultiple1 and qMultiple2 with the same goal . The function qMultiple2 much faster than qMultiple1, the difference is that Integrate[u[t],..] in qMultiple1 is inside of the function and in qMultiple2 is outside. How can be modified qMultiple1 (including Integrate inside it) in order to be as faster as qMultiple2 (I have copied the function below and I have added the notebook with the same functions). Thank you
qMultiple1[inputdata_, {ff_, tt_}, ts_] :=
Module[{u, uc, tau, r, rr, rt, bi, t1, ti, Ti, t2, t3},
u[t2_] = ff /. tt -> t2; uc[t3_] = Integrate[u[tau], {tau, 0, t3}] ;
r[t1_, Ti_] := Piecewise[{{0, t1 < 0}, {uc[t1], 0 <= t1 <= Ti},
{uc[t1] - uc[t1 - Ti], t1 > Ti}}]; rr[bi_, ti_, Ti_] := (bi/Ti)*r[t1 - ti, Ti];
rt = rr @@@ inputdata /. t1 -> ts; Total[rt]];
qMultiple2[inputdata_, {ff_, tt_}, ts_] :=
Module[{ tau, uc, r, rr, rt, bi, t1, ti, Ti, t2, t3},
uc[t2_] = ff /. tt -> t2; r[t1_, Ti_] := Piecewise[{{0, t1 < 0}, {uc[t1], 0 <= t1 <= Ti},
{uc[t1] - uc[t1 - Ti], t1 > Ti}}]; rr[bi_, ti_, Ti_] := (bi/Ti)*r[t1 - ti, Ti];
rt = rr @@@ inputdata /. t1 -> ts; Total[rt]];
u[t_] = 1/2 E^(-0.5 t) - 1/2 E^(-2 t);
inputs = {{100, 0, 10}, {30, 15, 10}, {15, 30, 5} };
Plot[qMultiple1[inputs, {u[t], t}, t1], {t1, 0, 50}] // AbsoluteTiming
u1[t3_] = Integrate[u[tau], {tau, 0, t3}] ;
Plot[qMultiple2[inputs, {u1[t], t}, t1], {t1, 0, 50}] // AbsoluteTiming
Guillermo