Mathematica Stack Exchange is a question and answer site for users of Mathematica. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have pasted my Mathematica code below. For some reason, the default value for h, or Δx, while set to 4.5 in the code, keeps displaying at -4 instead. I have been over and over this example, and I don't understand why this is happening. If someone would be willing to help me to understand what is going on here and how to fix it, I would really appreciate it.

  f[x_] = 2.195^x - 1;
       Text["  approximation of the derivative f'(x) :  " <> 
         ToString[(f[a + h] - f[a])/h]], Green, 15]}]},
       Text["  derivative: f'(x) \[TildeTilde] " <> 
         ToString[D[f[x], x] /. x -> a]], Red, 15]}]},
        f[a] + (D[f[t], t] /. t -> a)*(x - a), 
        f[a] + ((f[a + h] - f[a])/h)*(x - a)}, 
     {x, -0.5, 6.5}, 
     PlotStyle -> {Blue, Red, Green},
     PlotRange -> {{-0.5, 6.25}, {-50, 130}}, Axes -> True, 
     AxesOrigin -> {0, -50}, 
     AxesLabel -> {"time (sec)", "distance (ft)"},
     ImageSize -> 450,
     Prolog -> {
       {Line[{{a + h, f[a + h]}, {a, f[a + h]}}]},
       {Line[{{a, f[a + h]}, {a, f[a]}}]}, 
       {PointSize[.02], Blue, Point[{a, f[a]}]},
       {Blue, Text["(x,f(x))", {a + .3, f[a] - 5}]}, 
       {Text["Δx", {a + h/2, f[a + h] - 5}]}, 
       {Text["f(x+Δx) - f(x)", {a + .6, f[a] - (f[a] - f[a + h])/2}]}, 
       {PointSize[.02], Green, Point[{a + h, f[a + h]}]}, 
       {Green, Text["(x+Δx,f(x+Δx))", {a + h - .4, f[a + h] + 7}]}}]}}], 
  {{a, 1, "x"}, 0, 6},
  {{h, 4.5, "Δx"}, -a, 6 - a},
  TrackedSymbols -> {a, a + h},
  SaveDefinitions -> True]
share|improve this question
Where is the definition of h and delta x? – s0rce Mar 16 '13 at 0:36
Why track {a, a + h} and not {a, h}? The former causes infinite re-evaluation (notice flashing cell bracket). – István Zachar Mar 16 '13 at 8:39
Did you clear all variables a and h before the Manipulate? Did you tested it with a fresh kernel? Your problem is not reproducible, I got h = 4.5, as expected. – István Zachar Mar 16 '13 at 8:44

I think the problem is with SaveDefinitions->True. Change this to SaveDefinitions->False, save, and then run... it will probably be OK. Then add SaveDefinitions->True back at the end. This should always be the very last thing you do. (In other words, the problem is that an old definition is conflicting with the new one. Enabling SaveDefinitions at the end will fix this)

Also, you should probably move the function definition outside the manipulate (and add the colon to use SetDelayed instead of Set):

 f[x_] := 2.195^x - 1;
 Manipulate[ ... ]
share|improve this answer
Thanks, bill s - this seems to have solved my problem! And István, thanks for pointing out the a+h - this got copied from somewhere else, and I hadn't noticed... – cww Mar 18 '13 at 3:33

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.