-2

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.

Starlight
  • 57
  • 6
  • 2
    Can you come up with a minimal working example? – Öskå Jan 08 '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 08 '14 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 – Dr. belisarius Jan 08 '14 at 19:10
  • @belisarius do you think the (ahem) American monoglots lurking here can't use google translate? – bobthechemist Jan 08 '14 at 19:49
  • 1
    @bobthechemist Ok. Try Google translate with something more interesting http://www.todotango.com/english/las_obras/letra.aspx?idletra=1039 – Dr. belisarius Jan 08 '14 at 19:59
  • I understand it is a lot of code but I put everything to make it easier to understand the part that me is difficult – Starlight Jan 08 '14 at 23:27
  • The code that you are giving is working.., if I follow you, and stop me if I'm wrong, you want to feed the function f[x] with an InputField? – Öskå Jan 08 '14 at 23:39
  • Exactly, I want the function to which I calculate the tangent and that the graph is inserted into the inputField – Starlight Jan 08 '14 at 23:50
  • This is related: 35444. BTW if you create a good minimal example, that makes it easier to understand where you're having problem. Posting too much code makes it harder. In fact, this code is not related at all to what you're trying to do. It's just a piece of code that works. – C. E. Jan 09 '14 at 00:00
  • A piece of code that I need to adapt him to the role that is received in the inputfield is to that figure the tangent and the one plot (the calculation of the tangent function was serving) – Starlight Jan 09 '14 at 00:12
  • 2
    @belisarius, I'll delete it in a few minutes too...!: هل تعرف جوجل ترجمة؟ – Murta Jan 09 '14 at 00:48

1 Answers1

1

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).

C. E.
  • 70,533
  • 6
  • 140
  • 264