Message Boards Message Boards

Include the Tangent Line with the point slider?

Posted 7 years ago

Consider the following code:

f[x_] := E^x;
        y[a_, 1/2 _] := f[a] + f'[a]*(x - 1/2);
        Manipulate[
         Show[Plot[ {y[x, 1/2], f[x]}, {x, -2, 4}, {1/2, -2, 4}, 
           PlotStyle -> {Thickness[0.003], Blue}, PlotRange -> {0, 60}], 
          Graphics[{Green, PointSize[0.02], Point[{a, E^a}]}]], {a, -2, 4}]

This is what I have so far not sure if I'm heading towards the right direction

POSTED BY: Julian Rivera
3 Replies

I might use Series to compute the tangent line:

f[x_] := E^x;
Manipulate[
 With[{tl = Normal@Series[f[x], {x, a, 1}]},
  Show[
   Plot[{tl, f[x]}, {x, -2, 4}, PlotStyle -> {Thickness[0.003], Blue}, PlotRange -> {0, 60}], 
   Graphics[{Green, PointSize[0.02], Point[{a, E^a}]}]
   ]
  ],
 {a, -2, 4}]
POSTED BY: Michael Rogers

What, exactly, do you want to illustrate? Just a single tangent line to the curve with a point moving along the curve? (or that but with the point moving along the tangent?) Or do you want a moving tangent line as you move points along the curve?

Whichever you want, there are some problems with your code. Before using Manipulate, it's a good idea to try the graphics you want in a static mode, with a fixed value for the control variable(s).

  • your code

    y[a_, 1/2 _] := f[a] + f'[a]*(x - 1/2)
    

makes no sense to me: on the left-hand side you seem to have two arguments, the first being a; but what is the second argument? you have 1/2 _, with a space between the fraction and the pattern symbol _; what is that supposed to mean? Moreover, you have an x on the right-hand side but no x as an argument.

  • your Plot code

    Plot[ {y[x, 1/2], f[x]}, {x, -2, 4}, {1/2, -2, 4} (* options *)]
    

makes no sense: you seem to want to plot two functions of variable x, namely, y[x, 1/2] and f[x], but then after the domain list {x, -2, 4} (which is fine) you have the mysterious list {1/2, -2, 4}.

Once you straighten all that out, you can try to put it inside the Manipulate.

I also suggest that you not directly use f'[a] but rather compute ahead of time, once and for all, the derivative functions, say:

fp[x_] = f'[x]

And then use that in the right-hand side

f[a] + fp[a] (x - 1/2)

(or whatever it is that you really are trying to get there).

Note also that there is no earthly reason to include the explicit * symbol for multiplication in f[a] + f'[a] * (x - 1/2) or similar symbolic expression; explicit multiplication signs are needed in Mathematica only between actual numbers.

POSTED BY: Murray Eisenberg

Welcome to Wolfram Community! Please make sure you know the rules: https://wolfr.am/READ-1ST

The rules explain how to format your code properly. If you do not format code, it may become corrupted and useless to other members. Please EDIT your posts and make sure code blocks start on a new paragraph and look framed and colored like this.

int = Integrate[1/(x^3 - 1), x];
Map[Framed, int, Infinity]

enter image description here

POSTED BY: Moderation Team
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract