Your comments suggest that you need to find a better method to estimate ik+1 given ik. No knowledge of values in data
would yield to the naive algorithm:
At each iteration for n
, leave i
at previous value, and see if the abs(data[start]-data[end])
value is less than e
. If it is, leave i
at its previous value, and find your new one by incrementing it by 1 as you do now. If it is greater, or equal, do a binary search on i
to find the appropriate value. You can possibly do a binary search forwards, but finding a good candidate upper limit without knowledge of data
can prove to be difficult. This algorithm won't perform worse than your current estimation method.
If you know that data
is kind of smooth (no sudden jumps, and hence a smooth plot for all i
values) and monotonically increasing, you can replace the binary search with a search backwards by decrementing its value by 1 instead.