Interval and percentage algorithm

64 Views Asked by At

I have a problem that I can not solve. I want to create the following algorithm: For an interval [a, b]. If a variable x (between a and b) is close to the center of the interval we will output 100% and if we move away from the center the value decreases to 95% when we arrive in both sides of the interval.

1

There are 1 best solutions below

0
On BEST ANSWER

$$f(x)=\begin {cases} 1-0.05\frac{\frac{a+b}2-x}{\frac {b-a}2}& x\le \frac {a+b}2\\ 1-0.05\frac{x-\frac{a+b}2}{\frac {b-a}2}& x\gt \frac {a+b}2 \end{cases}$$