This question already has an answer here:

I would like to draw a function (x/x^2+1), and at a certain point, i'd like to draw a dot along with the tangent line at that specific point.

what I have tried is the following:

Plot[{function[x], function'[x]}, {x, -5, 5}, AxesLabel -> {x, y} LabelStyle -> Direction[Black, Bold]]

However, this plots the original function f(x) and f'(x) simultaneously; how can I achieve the desired result?


marked as duplicate by J. M. will be back soon plotting Mar 13 at 2:19

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

function[x_] := x/(x^2 + 1);

x0 = 1/2; 
Plot[{function[x], function[x0] + function'[x0] (x - x0)}, {x, -5, 5}, 
 AxesLabel -> {x, y}, LabelStyle -> Direction[Black, Bold], 
 Mesh -> {{x0}}, MeshStyle -> Directive[Red, PointSize[Large]]]

enter image description here

  • $\begingroup$ Hey thanks! I'm trying to plot this at point 45, but it doesn't seem to plot the tangent at that point; instead the tangent is on a completely different line with two dots? $\endgroup$ – Jaigus Feb 24 at 6:50
  • $\begingroup$ @Jaigus, there was a typo; fixed now. Mesh -> {{1/2}} should be Mesh -> {{x0}}. $\endgroup$ – kglr Feb 24 at 7:12
  • $\begingroup$ Thanks alot, this works great. $\endgroup$ – Jaigus Feb 24 at 7:25
  • 1
    $\begingroup$ Alternatively: Plot[{function[x], Normal[Series[function[x], {x, x0, 1}]]} // Evaluate, {x, -5, 5}]. $\endgroup$ – J. M. will be back soon Feb 25 at 2:04
  • $\begingroup$ @J.M.iscomputer-less, that's much neater. $\endgroup$ – kglr Feb 25 at 7:04

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