0

Define a sequence of function recursively:

f[n_, x_] := D[Exp[x] f[n - 1, x], x]
f[0, x_] = 1

Then, the following Manipulate command does not work:

Manipulate[Plot[f[n, x], {x, 0, 10}], {n, 1, 10, 1}]

It says that

General::ivar: 0.0002042857142857143` is not a valid variable.

I also found out that the problem is due to the differentiation in f[n_,x_]. If I don't have differentiation operation, then everything works fine. Also, I found out that the definition f itself is not a problem, since f[2,x] gives the correct answer $2e^{2x}$.

How can I fix the problem?

Michael E2
  • 235,386
  • 17
  • 334
  • 747
Laplacian
  • 1,053
  • 3
  • 8

1 Answers1

0

Your function definition cannot evaluate for numeric arguments. Note

Clear["Global`*"]

f[n_, x_] := D[Exp[x] f[n - 1, x], x] f[0, x_] = 1;

f[1, 2]

enter image description here

Delay the variable being given a value until after the differentiation

Clear["Global`*"]

f[n_Integer?Positive, x_] := Module[{t}, D[Exp[t] f[n - 1, t], t] /. t -> x]; f[0, x_] = 1;

f[1, 2]

(* E^2 *)

Manipulate[ LogPlot[f[n, x], {x, 0, 10}, AxesLabel -> {x, f[n, x]}], {{n, 1}, 1, 10, 1, Appearance -> "Labeled"}]

enter image description here

Bob Hanlon
  • 157,611
  • 7
  • 77
  • 198