# Dummy variable in nested integral operator

I am trying to make a nested integral operator where the output function of one step must be applied to the dummy variable to be integrated in the next step. Here my code:

w[x_] := Cos[x];
f[t_, n_] := Nest[Integrate[w[t - s] #, {s, 0, t}] &, 1, n];


Observe that, in one step, the output function is applied in $t$ and not $s$. Therefore, in the next integration, $t$ is just a constant, but it must be integrated as well. How can I fix this?

• In the simplest form, you want something like f[0, t_] := 1; f[n_Integer?Positive, t_] := Integrate[Cos[t - s] f[n - 1, s], {s, 0, t}]. The more efficient method involves using the method in this answer. – J. M. is away Nov 9 '17 at 1:06
• Does changing # to ((#) /. t -> s) in f get you what you need? – Edmund Nov 9 '17 at 1:15
• @J.M., it worked! Thank you for your answer. – Pierre Nov 10 '17 at 19:34
• @Edmund, thank you for your tip too! – Pierre Nov 10 '17 at 19:35