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

Adding a textfield to the function that I implemented to represent the tangent or derivative of a function, but I've added so mark errors.

f[x_] = -x^3 + 12 x - 3;   (*Se define la función*)
xmin = -6;
xmax = 6 ;     (* se define el mínimo y el máximo de la función*) 
ainicia = -3 ;(* inicio del punto de tangencia*)
amin = -4.3;
amax = 5; (* se define el punto de tangencia mínimo y máximo*)
hinicia = -1;(*inicio del punto de intersección de la línea secante*)
hmin = -1.3;
hmax = 8.5;

  DynamicModule[{f = Sin[x^2]}, 
  Column[{InputField[Dynamic[f]], Dynamic[Plot[f, {x, -5, 5}]]}]]
  If[h == 0, h = .001];
     {{Plot[{f[x], If[t1, f[a] + (D[f[t], t] /. t -> a)*(x - a)], 
     f[a] + ((f[a + h] - f[a])/h)*(x - a)}, {x, xmin, xmax}, 
     PlotStyle -> {{Thickness[0.005], Black}, {Thickness[0.004], 
     Blue}, {Thickness[0.004], Red}}, 
     PlotRange -> {15*xmin, (8*xmax) + 2}, ImageSize -> {475, 325}, 
     PlotLabel -> Style[Row[{Style["f(x)", Italic], "=",
     ToString[-x^3 + x^2 + 12 x - 3, TraditionalForm]}], 20],
     AxesLabel -> {Style["x", 16, Italic], Style["y", 16, Italic]},
     Prolog -> {{PointSize[0.02], If[t1, Blue, Red], Point[{a, f[a]}]},
      {PointSize[0.02], Red, Point[{a + h, f[a + h]}]}}]},
      "Pendiente-tangente =" <> ToString[D[f[t], t] /. t -> a]], 
      Blue, 20]],
     Text["Pendiente-secante =" <> ToString[(f[a + h] - f[a])/h]], 
     Red, 20]}, "   "]}}],
     {{a, ainicia, "x0"}, amin, amax},
      {{h, hinicia, "h"}, hmin, hmax},
      {{t1, False, "Linea Tangente"}, {True, False}},
      TrackedSymbols -> {a, h, t1}, SaveDefinitions -> True]

I do not like putting the textfield to enter the function, which is shown in the graph and is the same for the tangent.

share|improve this question
Can you come up with a minimal working example? – Öskå Jan 8 '14 at 18:49
The only error that I can find is that you used Set instead of SetDelayed in the definition of f – Dr. belisarius Jan 8 '14 at 19:08
I'll delete this comment in a few minutes. Por favor, trata de incluir solamente el codigo necesario para comprender el problema. Tus preguntas contienen usualmente demasiado código y eso trae como consecuencia que menos usuarios se tomen el trabajo de leer, entender y responder tus preguntas – Dr. belisarius Jan 8 '14 at 19:10
@belisarius do you think the (ahem) American monoglots lurking here can't use google translate? – bobthechemist Jan 8 '14 at 19:49
@belisarius, I'll delete it in a few minutes too...!: هل تعرف جوجل ترجمة؟ – Murta Jan 9 '14 at 0:48
up vote 1 down vote accepted

Basically, you're trying to do this:

 Plot[func, {x, -10, 10}],
 {func, x^2}]


You can add that field to your application but use the symbol f instead of func and it will work for input such as Sin, Exp etc. However it will not work for input such as x^2. This is because you use f[t] and so on instead of the expression itself (Sin is a function but x^2 is just an expression).

To make it work this way you need to stop using functions such as f[t] and simply use f instead where f is not used as a function anywhere, but is assumed to be an expression (such as x^2).

share|improve this answer

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.