In many of cases in science and engineering one comes across definition of functions which are bounded to certain extent to the values of function parameters. You can imagine many such functions such as step function which has magnitude 1 if the x value is equal or greater than 0.

Another simple example is the following:

Here when the function variable x is between 0 and pi we have sin(x) and otherwise zero.

How to implement such function in python?

We implement the function using if else statement. The following python code implements the above definition of function.

from math import pi, sin

def f(x):

if 0<= x <= pi:

return sin(x)

else:

return 0

Now if we were to use the function we get the following results:

f(2)

Out[2]: 0.9092974268256817

f(4)

Out[3]: 0

f(1)

Out[4]: 0.8414709848078965

Consider the unit step function as follows:

Implementing this unit step function is even more easier. We can write this function in python as follows:

def u(t):

if t >= 0:

return 1

else:

return 0

Using this function we get the following.

u(0)

Out[6]: 1

u(-1)

Out[7]: 0

u(2)

Out[8]: 1

So in this way we can implement bounded functions in python programming language.

## No Comment to " Implementing bounded functions in python "