I need to create a slider that displays the secant line of the function (defined as functionsecant) using the Manipulate function in mathematica, but I can't get it to work and I can't find any tutorials breaking down how the function works and how your supposed to put in input. (I am brand new to Mathematica)

This is what I thought would work, but apparently it doesn't.

 Plot[function[x], functionsecant[x], {x, -10, 10}, 
  PlotRange -> {{-5, 5}, {-5, 5}}, 
  Epilog -> {Red, PointSize[.015], Point@{p, functionsecant[p]}}], {p, 0, 

And it's supposed to plot the secant line from (0,0) to (a,f(a)). How exactly do I do this? I'm at my wit's end D:

  • $\begingroup$ Welcome to Mathematica.SE, AislinnSi! I suggest the following: 1) As you receive help, try to give it too, by answering questions in your area of expertise. 2) Take the tour and check the faqs! 3) When you see good questions and answers, vote them up by clicking the gray triangles, because the credibility of the system is based on the reputation gained by users sharing their knowledge. Also, please remember to accept the answer, if any, that solves your problem, by clicking the checkmark sign! $\endgroup$
    – Chris K
    Commented Feb 12, 2019 at 21:48

1 Answer 1


You're not too far off. First, if you want to plot multiple functions, they should be surrounded by curly braces {function[x], functionsecant[x]}. Second, unless I'm missing something, I don't think you need functionsecant. If you get rid of functionsecant and turn the functionsecant[p] in your Epilog to function[p], you should end up with a red dot that indicates the end position of your secant line.

You can turn this into a line by adding Line[{{0, 0}, {p, function[p]}}] into your Epilog. Here's an example to help you out:

function[x_] := Sin[x]
  {x, 0, 8 \[Pi]},
  Epilog -> {
    Line[{{0, 0}, {a, function[a]}}],
    Point@{{0, 0}, {a, function[a]}}
 {a, 0, 8 \[Pi]}]

Secant line to a sine function.

  • $\begingroup$ Thank you very much for this! Also, is there a way to set the range? I plugged this into mathematica and it was too big but PlotRange wasn't working where I thought it would. $\endgroup$ Commented Feb 12, 2019 at 21:11
  • $\begingroup$ @AislinnSi You can change the range by adding this as an option right before Epilog: PlotRange -> {{xmin, xmax}, {ymin, ymax}} where the xmin etc. are values that you choose. For the graph I made, I might do PlotRange -> {{0, 8 Pi}, {-1, 1}}. $\endgroup$
    – MassDefect
    Commented Feb 13, 2019 at 0:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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