Mathematica: Arc Length Speed
WolframLang. Arc Length Speed
WolframLang. Arc length using NIntegrate is faster than builtin ArcLength with machine number input.
(* 2024-03-30 my arc length function, originally written around 1995. *) Clear[ xnArcLength, xnArcLength2]; xnArcLength::usage = "xnArcLength[{fx, fy}, {t, a, b} ] return arc length of the curve {fx, fy} from a to b using NIntegrate."; xnArcLength[ parametrizedCurve_?VectorQ, {t_Symbol, tmin_, tmax_}]:= NIntegrate[ Evaluate@ Sqrt @ Total @ ( D[ parametrizedCurve, t]^2 ) , {t, N@ tmin, N@ tmax} ] xnArcLength2::usage = "xnArcLength2[{fx, fy}, {t, a, b} ] return arc length of the curve {fx, fy} from a to b using NDSolve."; xnArcLength2[ parametrizedCurve_?VectorQ, {t_, tmin_, tmax_}]:= Module[ {a,b,s,f}, {a,b} = N@{tmin,tmax}; s = NDSolve[ { f'[t] == Sqrt[Plus@@(D[ parametrizedCurve, t]^2)], f@a == 0 }, f, {t,a,b} ][[1,1,2]]; s[b] ]