Function constraint (o2scl)¶
-
inline double o2scl::constraint(double x, double center, double width, double height)¶
Constrain
x
to be withinwidth
of the value given bycenter
.Defining
center
,width
,height
, this returns the value if and if . The value near or is (the value of the function exactly at these points is zero) and the value at or is .It is important to note that, for large distances of
x
fromcenter
, this only scales linearly. If you are trying to constrain a function which decreases more than linearly by makingx
far fromcenter
, then a minimizer may ignore this constraint.