-2
$\begingroup$

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.

$\endgroup$
  • 2
    $\begingroup$ Can you come up with a minimal working example? $\endgroup$ – Öskå Jan 8 '14 at 18:49
  • $\begingroup$ The only error that I can find is that you used Set instead of SetDelayed in the definition of f $\endgroup$ – Dr. belisarius Jan 8 '14 at 19:08
  • 2
    $\begingroup$ 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 $\endgroup$ – Dr. belisarius Jan 8 '14 at 19:10
  • 1
    $\begingroup$ @bobthechemist Ok. Try Google translate with something more interesting todotango.com/english/las_obras/letra.aspx?idletra=1039 $\endgroup$ – Dr. belisarius Jan 8 '14 at 19:59
  • 2
    $\begingroup$ @belisarius, I'll delete it in a few minutes too...!: هل تعرف جوجل ترجمة؟ $\endgroup$ – Murta Jan 9 '14 at 0:48
1
$\begingroup$

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

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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