Arc length for a spline

Note that you an pass a rtol = 0.0002 to quadgk for this as well.

It is possible to pass all the knots to QuadGK to use in a single call with a pre-allocated buffer, though it’s still probably better to just use a fixed-order rule, which can be evaluated allocation-free.

However, I’m concerned that your test data, formed by just uniformly sampling a semicircle, may be deceiving you, because it is too smooth. If you call quadgk_count to see the evaluation points, you’ll see that it is doing the whole integral with just a single 15-point Gaussian quadrature rule.

If you really have data that smooth, you probably shouldn’t be using splines at all — you should use something like Chebyshev polynomial interpolation — I’m assuming that such smooth data must be synthetically generated (i.e. be the output of a computer program) so that you can choose your x points.

Whereas if you are using a spline for something like experimental data with noise, the kinks at the knots have a much more noticeable effect. For example, if you generate your data with x, y = cos.(t), sin.(t) .+ randn.() .* 0.01, then quadgk requires 13245 evaluations (for the default 1e-8 tolerance).

1 Like