I'm trying to construct a function which satisfies the following:
$$ \begin{align} f(x) = 0 & \qquad x \leq 0\\ f(x) = x & \qquad 0 \lt x \lt 1\\ f(x) = 1 & \qquad x \geq 1\\ \end{align} $$
Sadly I only have the very basic operators at my disposal: + - / *. I also have grouping operators ( ).
I've managed to come close using the Butterworth function:
$$f(x) = \frac{x}{1+\frac{2x-1}{1}+\frac{2x-1}{1}+\frac{2x-1}{1}+…}$$
This (approximately) satisfies my first two conditions, but not the third one. I'm sure there's a way to modify this function to satisfy all three, but I don't have the skills.
EDIT:
I'd like to be able to handle the range of -600 < x < 120. For accuracy, I don't have a definite target. Perhaps to start with if f(x)
could be <0.01
when x < -0.01
and f(x)
could be >0.99
when x > 1.01
? I know that higher accuracy will result in a longer expression, so if I understand how to build the expression I can experiment to find an appropriate balance between brevity & accuracy.
If it makes your answer easier to read, feel free to include exponentiation by a constant value. I don't have access to any exponential operations, but I can easily convert them into repeated multiplication myself as long as the exponent is constant.