i am trying to implement a recursive difference equation step by step, by implementing rules, similar to Rojo's method in this thread: How can I evaluate only a single step of a recursive function?
But the rules are not applied to my function, I think because it contains more than one variable. This is important for the answer, since one of the variables is integrated over. The other variable is decremented, which is what I want to iterate step-wise:
Clear[f, frules];
frules = {f[n_, x_] -> (n - 1) x^n Cos[x] f[n - 1, x] + Integrate[Sin[x] f[n - 1, x], x]};
f[3] /. frules
f[3] /. frules /. frules
f[m] /. frules
This just gives $f[3]$, or $f[m]$, without implementing the recursion.
I'm specifically interested in the symbolic expressions after 1,2,...p steps. How to start from a given integer value $m$ and write the expression after $p$ decrements of 1?
The mathematical expression should be well posed because I can incrementally increment the function, with a given starting value:
f[n_, x_] := (n - 1) x^n Cos[x] f[n - 1, x] + Integrate[Sin[x] f[n - 1, x], x]
f[0, x] = 1;
Gives well defined functions for f[1], f[2], f[3], etc. E.g. $f[1] = -Cos[x]$ , $f[2] = \frac{1}{2} (1 - 2 x^2) Cos[x]^2 $ , etc.
myf[0, x_, _] = 1; myf[n_Integer, x_, k_Integer] /; k >= 1 := With[{next = myf[n - 1, x, k - 1]}, myf[n, x, k] = (n - 1)*x^n*Cos[x]*next + Integrate[Sin[x]*next, x]]; myf[2, x, 2] Part[(seq = RecurrenceTable[{f[n] == (n - 1) x^n Cos[x] f[n - 1] + Integrate[Sin[x] f[n - 1], x], f[0] == 1}, f, {n, 2, 2}] // FullSimplify) , 1]They really do give different results for the function, and not by a constant... – StevieP Jul 14 '22 at 02:04