On Tuesday, 29 November 2022 21:17:18 PST Nikita Zlobin via gnuplot-info wrote:
I like the idea.
The program already does something of the sort to insure that a function
is evaluated at x=0 even if regular subdivision of the x-axis range would
not generate a sample point there. If the location of the function's
extrema are known in advance, those special values of x could be added
to the sample set. Unfortunately the program does not in general know
how many or where such extrema are expected.
On the other hand, for periodic functions such as the example you show there
is another option. Set the sampling range to span exactly one period and
plot as many periods as needed to fill the desired x range.
For your function abs(sqrt(sin(x)))
unset key
set sample 99 # odd number advised
set xrange [-8:8]
f(x) = abs(sqrt(sin(x)))
offset(i) = t + i * 2*pi
plot for [i=-2:2] [t=0:2*pi] '+' using (offset(i)):(f(offset(i))) lt 1
99 samples is sufficient to give a reasonably smooth plot;
199 samples is even better.
Ethan
> I tried to plot «sqrt( sin(x) )» and noticed, that at 1000 samples with xrange [-8:8] lines break at visible distance from X axis. Even 10000 samples is not enough, and only 100k or 1m samples is more or less fine. Of course, it’s not good for vector documents like svg, eps or whatever latex terminals generate.
>
> This problem of open ends could solved by adding point between existing and non-existing neighbor points and adjusting its place with subdivide and conquer approach.
>
> Ideally this point could use one of reserved position for non-existing point, thus reducing chance of points number growth.
>
> Also, if points number growth is not problem, there could be second threshold to use for middle subdivisions, just to keep visually good resolution. This would allow to use minimum necessary points in the best way. In case if threshold for middle subdivisions is not specified, it could be calculated horizontal distance (may be multiplied by 2).
>
> --
> Nikita Zlobin
|