A mathematical integer range function

138 Views Asked by At

I want a function f(x) that uses the constants a, b, M, N and,

Always, a < b

If x < a then f(x) = M

If x > b then f(x) = N

Else, f(x) = x

(x, a, b, M, N all are integers.)

a plot created using paint app , where a=3, b=10, M=5, N=9

Above image shows a plot created using paint app , where a=3, b=10, M=5, N=9

In words, it is a function that takes an integer. If it is on a certain range, it outputs the same integer. Else, it outputs a pre chosen number according to whether the integer is larger or lower than the specified range.

What will be the equation to get that outputs?
(I want an equation of the function, there can be more than one)

2

There are 2 best solutions below

0
On

Functions aren't magic and they don't need nor always have special names or formulas. The function you want is:

$f (x)=M $ if $x>a $

$f (x)=N$ if $x <b$

$f (x)=x$ otherwise.

That's it. That IS your function. There is nothing more that needs to be said.

0
On

If you don't like to write down explicit cases (although there's nothing wrong with doing so), you can also use the Iverson bracket to write your function as $$f(x) = M\,[x<a] + N\,[x>b] + x\,[a\le x\le b]$$