i have a code that outpus an array of data every time step, here are 2 time steps:
My objective is to find the coordinates and value of the minimum of that hole. As you can see there are multiple local minima. I want to find the most minimal value of all this value will correspond to the finest hole (around v=0.15
) on the left of the wide hole (around v=0.35
).
I have an algorithm that uses another function to find a value to start the search for the minimum, which is f-f0
(f0
is a Gaussian), this gives me a function like this:
I first find the value of the minimum of the f-f0
function, then i use that coordinate to find the local minimum on the f
function.
The minimum i find it with a super simple finder. It consists in taking that starting value, then create a new array with the left and right values, finding the minimum of this array, if the minimum i got is the same as the one i got in the previous step then those are the coordinates of the minimum, if not repeat.
This method allows me to find the closes local minimum to the starting position, and because it is symmetric (i add the same amount of points to the left and right) i always get the minimum to the left of the starting position (ie. the wide hole). However i don't want that one, i want the deepest hole. Some times the deepest corresponds to the one i calculate (ie. red function), other times it doesn't correspond to the deepest (ie. blue curve).
Note: I'm doing this in Fortran, however if you don't know Fortran you can just give me the idea/algorithm, or write it out in python,i can translate it to Fortran.
Thank you.
I found a solution after thinking a little bit.
Previously i searched for the minimum of the f-f0
function, now instead i search for the minimum and the maximum of f-f0
. The reason of this is that this function will always have the maximum at the farthest end from the maximum of f
and the minimum at the closest of f
. This is due to the symmetry of the Gaussian function, therefore if the hole is on the left of the maximum of f
(ie this exemple) then the max will be to the left of the minimum of f-f0
, and in the hole is to the right of the max of f
then the maximum will be to the right of the minimum of f-f0
.
After finding these 2 points i get their coordinates using MINLOC(f-f0)
and MAXLOC(f-f0)
. Then i create a new array of size |imin-imax|
where i copy the points of f
corresponding tho those coordinates. (I create a new array because i do other things with this array, but it is not necessary. I what you need is just the minimum then just shorten the limits of the array instead as f(imin:imax)
)
I then search for the minimum of this new array and the coordinates. which i then transform to the real coordinates for the position on f
.
At the end i get both the value of the minimum of f
and the value of its coordinate v
.