Function constraint (o2scl)

O2scl : Function List

inline double o2scl::constraint(double x, double center, double width, double height)

Constrain x to be within width of the value given by center.

Defining \( c= \) center, \( w= \) width, \( h= \) height, this returns the value \( h (1+|x-c-w|/w) \) if \( x>c+w \) and \( h (1+|x-c+w|/w) \) if \( x<c-w \) . The value near \( x=c-w \) or \( x=c+w \) is \( h \) (the value of the function exactly at these points is zero) and the value at \( x=c-2w \) or \( x=c+2w \) is \( 2 h \) .

It is important to note that, for large distances of x from center, this only scales linearly. If you are trying to constrain a function which decreases more than linearly by making x far from center, then a minimizer may ignore this constraint.