I am looking for an efficient way of getting 60 to 80 samples of an arbitrary f(x) such that the distance between adjacent samples are approximately equal. My first attempt is based on a first order approximation at different points.
f[x_]:=1-8 x^2+8 x^4;
dist=0.15;
xs=Most@NestWhileList[#+Sqrt[dist^2/(1+f'[#]^2)]&,-1.0,#<1.0&];
smpls={#,f[#]}&/@xs;
Plot[f[x],{x,-1,1},Epilog->{AbsolutePointSize@5,Red,Point[smpls]}]
In the image above, the distance between samples is too large when my algorithm gets to a value where f'[x] is close to zero. I can get much better results with my next approach.
hack=2.2;
xs=Most@NestWhileList[#+Min[hack*dist^2,Sqrt[dist^2/(1+f'[#]^2)]]&,-1.0,#<1.0&];
smpls={#,f[#]}&/@xs;
Plot[f[x],{x,-1,1},Epilog->{AbsolutePointSize@5,Red,Point[smpls]}]
The spacing of the second samples are close enough to evenly spaced. The problem is that the value assigned to 'hack' should be adjusted for each example. Is there better way to make such samples of an arbitrary function?









distancemeaning here?EuclideanDistanceorArcLength? – cvgmt Jan 14 '24 at 01:50