1

I want to create a table with numerical values of a function derivative by using the following code:

f[x_, a_] := f[x, a] = Tanh[a (1 - Cos[x])];
g[x_, a_] := g[x, a] = D[f[x, a], x];
pderivative = Table[{x, Evaluate[g[x, 5]]}, {x, - π,  π, 2 π/500.}]

When I look at the result, it's not what I expect. Any trick to fix this? enter image description here

Bob Lin
  • 445
  • 2
  • 8
  • g = D[f[x, a], x]; pderivative = Table[{x, g /. a -> 5}, {x, -\[Pi], \[Pi], 2 \[Pi]/500.}] – Alex Trounev Nov 05 '18 at 10:48
  • 2
  • As mentioned by Henrik in this comment, memoization for functions with real arguments is usually rather pointless as the chances that exactly the same pops up somewhere else are rather low. 2. Don't abuse SetDelayed(:=). Related: https://mathematica.stackexchange.com/a/181586/1871
  • – xzczd Nov 05 '18 at 11:20