Assuming that you are simply trying to โpower-searchโ to calculate this at a certain level of prcision, you need your algorithm to basically find any value where both neighbors are greater than the current value of your cycle.
To simplify this, let me say that you have an array of numbers and you want to find the indices of the three local minima. Here is a simple algorithm for this:
public void Test() { var ys = new[] { 1, 2, 3, 4, 5, 4, 3, 2, 1, 2, 3, 4, 5, 4, 3, 4, 5, 4 }; var indices = GetMinIndices(ys); } public List<int> GetMinIndices(int[] ys) { var minIndices = new List<int>(); for (var index = 1; index < ys.Length; index++) { var currentY = ys[index]; var previousY = ys[index - 1]; if (index < ys.Length - 1) { var neytY = ys[index + 1]; if (previousY > currentY && neytY > currentY)
So basically, you pass in the function (ys) functions that you calculated for the input array (xs) (not shown) to your result array. What you get from this function are the minimal indexes. So, in this example, you return 8, 14, and 17.
source share