# Making a secant line slide along a curve with Manipulate

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.

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


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:

• 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! – Chris K Feb 12 at 21:48

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]
Manipulate[
Plot[
function[x],
{x, 0, 8 \[Pi]},
Epilog -> {
Line[{{0, 0}, {a, function[a]}}],
Red,
Point@{{0, 0}, {a, function[a]}}
}
],
{a, 0, 8 \[Pi]}]


• 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. – AislinnSi Feb 12 at 21:11
• @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}}. – MassDefect Feb 13 at 0:58