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+|xcw|/w) if x>c+w and h(1+|xc+w|/w) if x<cw . The value near x=cw or x=c+w is h (the value of the function exactly at these points is zero) and the value at x=c2w or x=c+2w is 2h .

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.