A piecewise function is one that has different forms on different regions of its domain. For example:
# | x for 2<x<3
# f(x) = | -x for 3<x<4
# | 0 everywhere else
This patch implements piecewise functions by allowing you to specify a separate range on x over which samples are generated. So the above function could be plotted as:
plot dummy=0, [*:2] 0, [2:3] x, [3:4] -x, [4:*] 0
A range specifier in front of a datafile name or other non-sampled plot element is ignored.
For backwards compatibility, a range specifier at the very start of a plot command is interpreted as a global request for the plot limits. I.e. it overrides "set xrange; set yrange; etc". Unfortunately this means that if you want to limit the sampling range of the first function plotted, you must add a junk definition at the beginning so that the sampling range is not mistaken for the global plot range. I used "dummy=0" in the example above, but any definition would do the job.
The patch includes full documentation and a new demo "piecewise.dem". I have attached the output from this demo as a pdf file.
Questions:
- Is there a better way to avoid ambiguity when a range specifier is the first thing in the plot command?
Maybe require that the sampling range always looks like [sample=MIN:MAX]?
(That's legal now, by the way, but it doesn't do anything special)
- The number of samples in each range is the same. Is that OK?
- I only added this to 'plot', not 'splot'. Does anyone see a need for limiting the sampling grid limits in 3D?
Individual sampling ranges for functions in a plot command
output from the demo