7
$\begingroup$

We wish to draw a plot of Sin[x] function associated with a series of vectors stemming from horizontal axes and end to the mentioned function. Same as:

enter image description here

where \Pi/n is the distance between each vector.

I do not know how do I draw vectors, while I simply can draw the Sin[x]. Of course, we are not restricted to the Sin[x] function. We may have any arbitrary function instead of Sin[x].

$\endgroup$

1 Answer 1

16
$\begingroup$
f[x_] := Tanh[x];
t = Table[
   Arrow[{{x, 0}, {x, f[x]}}], {x, -2 \[Pi], 2 \[Pi], \[Pi]/12}];
Plot[f[x]
 , {x, -2 \[Pi], 2 \[Pi]}
 , PlotStyle -> {Thin, Black}
 , AspectRatio -> 3/10
 , ImageSize -> Large
 , Epilog -> {Red, Arrowheads[0.02], t}
 ]

enter image description here

For Sin[x];

enter image description here


For functions with a wide y-plotrange, the arrowheads may start to look ugly where it hugs the x-axis. In that case, t can be slightly modified. A general solution may be elusive as the plot range determines it.

f[x_] := x^3 + 1;
t = Table[
   If[Abs[f[x]] > 40, Arrow[{{x, 0}, {x, f[x]}}]], {x, -2 \[Pi], 
    2 \[Pi], \[Pi]/12}];

enter image description here

$\endgroup$

Your Answer

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

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