Message Boards Message Boards

Include the Tangent Line with the point slider?


Consider the following code:

f[x_] := E^x;
        y[a_, 1/2 _] := f[a] + f'[a]*(x - 1/2);
         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
23 days ago

Welcome to Wolfram Community! Please make sure you know the rules:

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
23 days ago

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
22 days ago

I might use Series to compute the tangent line:

f[x_] := E^x;
 With[{tl = Normal@Series[f[x], {x, a, 1}]},
   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
22 days ago

Group Abstract Group Abstract