Given a pure function, e.g. f=Sin[#]&
, it is possible to plot it with introducing an arbitrary local variable, e.g.,
Plot[f[x],{x,0,1}]
However, the introduction of a variable x
seems unnecessary. Is it possible to plot this without specifying a name for the variable? If not, is there a good reason why this functionality doesn't exist?
Answer
Yes, you can plot it, but not using Plot
. For example, you could map the function over a range of values and then use ListLinePlot
:
With[{xmin = 0, xmax = 4π},
ListLinePlot[f/@Subdivide[##,100],DataRange->{##}]&[xmin,xmax]
]
This uses the new function Subdivide
with 100
plot points.
The reason why Plot
requires you to specify a dummy variable is that it takes expressions and not functions as its argument. Therefore, the plot variable is not identifiable by a slot, and you need to specify it by naming the plot variable.
Comments
Post a Comment