0

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?

artificial_f
  • 15
  • 1
  • 4

1 Answers1

0

Are you looking for something similar to this question?

The top answer of the linked questions shows you, how to transform an interval from range [a, b] to range [c, d]. In your case, from [-100, 100] to [0, 2].

NicoHahn
  • 23
  • 5
  • Not really. 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 I am looking for a more efficient way. – artificial_f Jun 03 '22 at 16:09