Extracting a function from a standard

41 Views Asked by At

I have a standard and I need create a function to resolve this, for example:

if my $X < 21$ my $Y$ will be $24$ else if my $x < 28$ my $y$ will be $32$ ...

How do I calculate a function for this?

Thanks all.

1

There are 1 best solutions below

8
On BEST ANSWER

You can simply define the function in piecewise terms over its domain:

$$y=f(x) = \left\{\begin{array}{cc} 24, & \mathrm{if}\ x < 21, \\ 32, & \mathrm{if}\ 21 \le x < 28. \\ \end{array}\right.$$

As to whether there is a pattern herein, there is not enough information to decide.

Another way is to use indicator functions, which are defined as $$\mathbf{1}[\chi] = \left\{\begin{array}{cc} 1, & \mathrm{if}\ \chi\ \mathrm{is\ true}, \\ 0, & \mathrm{if}\ \chi\ \mathrm{is\ false}.\end{array}\right.$$

Them you can write $$y=f(x) = 24\cdot\mathbf{1}[x < 21] + 32\cdot\mathbf{1}[21 \le x < 28] + \cdots$$

In programming, sometimes indicator functions are called "boolean variables" (where you might have to map $\mathrm{true} \mapsto 1$, $\mathrm{false} \mapsto 0$.)