5  Adaptive sampling

Plot function

function doplot(xy)
    f = lines(xy)
    scatter!(xy, color=:darkred, markersize=5)
    return f
end;

Linear function

x = parameter(R)
sample1d(x, -1, 1) |> doplot

Parabola

sample1d(x^2, -1, 1) |> doplot

Curved in one region

sample1d(x^100, 0, 1) |> doplot

Singular point

sample1d(sin(1.0 / x), 0.0, 0.05, maxangle=0.05, npoints=21) |> doplot
@time size(sample1d(sin(1.0 / x), 0.0, 0.05, maxangle=0.1), 2)
  0.427318 seconds (392.50 k allocations: 8.108 MiB, 90.84% gc time, 1.85% compilation time)
8479

Multiple curvatures

sample1d(sin(30 * sin(x)), 0, 2pi) |> doplot

Discontinuity

sample1d(1 / x, 0, 1, yscale=1e-5) |> doplot

Insert root

sample1d(-0.3 + x, -1, 1, ir=true) |> doplot

Non smooth function

sample1d(x -> abs(x), -1, 1) |> doplot

Local peak

a = 0.01
sample1d(x + a / (a + x^2), -1, 1) |> doplot

Circle

sample1d(ParametricCurve(cos(x), sin(x)), 0, 2pi) |> doplot