Function constraint (o2scl)¶
-
inline double o2scl::constraint(double x, double center, double width, double height)¶
Constrain
xto be withinwidthof the value given bycenter.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
xfromcenter, this only scales linearly. If you are trying to constrain a function which decreases more than linearly by makingxfar fromcenter, then a minimizer may ignore this constraint.