I have a variable x produced by a simulation tool that is -100 < x < 100. Now, I want to find an efficient way to change x value (reduce or increase depending on whether it's negative or positive) in order to have: 0 < x < 2.
I need to stepwise change x and check every time if condition (0 < x < 2) is fulfilled. If yes, I want to get value of x. If not, I want to continue changing value of x. As said, this can be done with a "while" loop. However, it might take many iterations if x is close to +- 100 and the step is small. Since for each iteration I batch run a simulation that takes minutes to finish, I am looking for a more efficient way.
There must be an algorithm that can evaluate the difference and adjust step. Can anyone help?