I am trying to define a recursive function with a subscript. Something similar would be $f_{n+1}(x) = \int 3 x f_{n}(x)dx$. I've tried lists, For
function, NestList
, and RecurrenceTable
. What do you recommend?
-
$\begingroup$ See the tutorial Functions That Remember Values They Have Found. $\endgroup$– Michael E2Apr 23 at 1:10
-
$\begingroup$ Related/duplicate: mathematica.stackexchange.com/questions/89231/… $\endgroup$– Michael E2Apr 23 at 15:15
2 Answers
Assume some $f_1(x)$ and then define a univariate recursion in terms of n
:
f[1] := x + 1;
f[n_Integer /; n >= 2] := f[n] = Integrate[3 x f[n - 1], x]
For example:
f[5]
27/560 ((35 x^8)/8 + (16 x^9)/9)
Continuing with corey979's approach
Clear["Global`*"]
f[1] := x + 1;
f[n_Integer /; n >= 2] := f[n] = Integrate[3 x f[n - 1], x] // Simplify
Generating a sequence from the recursion
seq = f /@ Range[6] // FullSimplify
(* {1 + x, (3 x^2)/2 + x^3, 3/40 x^4 (15 + 8 x), 9/560 x^6 (35 + 16 x),
(3 x^8 (315 + 128 x))/4480, (9 x^10 (693 + 256 x))/98560} *)
Using FindSequenceFunction
directly doesn't work. To simplify the problem, break the sequence into its component parts
seq2 = Simplify[seq/(x^(2 (# - 1)) & /@ Range[6])]
(* {1 + x, 3/2 + x, 9/8 + (3 x)/5, 9/16 + (9 x)/35, 27/128 + (3 x)/35,
81/1280 + (9 x)/385} *)
seq3 = Coefficient[#, x] & /@ seq2
(* {1, 1, 3/5, 9/35, 3/35, 9/385} *)
seq4 = seq2 - x*seq3
(* {1, 3/2, 9/8, 9/16, 27/128, 81/1280} *)
The original sequence is then represented by
f2[n_, x_] = (FindSequenceFunction[seq4, n] +
FindSequenceFunction[seq3, n]*x) x^(2 n - 2) // FunctionExpand //
FullSimplify
(* (6^(-1 + n) x^(-2 + 2 n) *
(Sqrt[π] x Gamma[n] + 2 Gamma[1/2 + n]))/(Sqrt[π] Gamma[2 n]) *)
Verifying that f == f2
over a much broader range than the original sequence
And @@ Simplify[Table[f[n] == f2[n, x], {n, 1, 40}]]
(* True *)
f2
is not limited to integer values of n
Plot3D[f2[n, x], {n, 1/2, 10}, {x, 0, 2},
AxesLabel -> (Style[#, 14] & /@ {"n", "x", "f"}),
ClippingStyle -> None,
ImageSize -> Medium]
EDIT: More succinctly, to go from seq
to f2
f2[n_, x_] = (Total[FindSequenceFunction[#, n] & /@
Transpose[List @@@ (seq // Expand)]] // FunctionExpand // FullSimplify)
(* (6^(-1 + n) (x^2)^(-1 + n) *
(Sqrt[π] x Gamma[n] + 2 Gamma[1/2 + n]))/(Sqrt[π] Gamma[2 n]) *)