Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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;

Manipulate[
  DynamicModule[{f = Sin[x^2]}, 
  Column[{InputField[Dynamic[f]], Dynamic[Plot[f, {x, -5, 5}]]}]]
  If[h == 0, h = .001];
   Grid[
     {{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]}]}}]},
      {Row[ 
       {If[t1, 
       Style[Text[
      "Pendiente-tangente =" <> ToString[D[f[t], t] /. t -> a]], 
      Blue, 20]],
     Style[
     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
2  
Can you come up with a minimal working example? –  Öskå Jan 8 at 18:49
    
The only error that I can find is that you used Set instead of SetDelayed in the definition of f –  belisarius Jan 8 at 19:08
2  
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 –  belisarius Jan 8 at 19:10
    
@belisarius do you think the (ahem) American monoglots lurking here can't use google translate? –  bobthechemist Jan 8 at 19:49
1  
@belisarius, I'll delete it in a few minutes too...!: هل تعرف جوجل ترجمة؟ –  Murta Jan 9 at 0:48
show 6 more comments

1 Answer 1

up vote 1 down vote accepted

Basically, you're trying to do this:

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

screenshot

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
add comment

Your Answer

 
discard

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.