# vectorized an arbitrary function

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:

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].

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}
]


For Sin[x];

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}];