Skip to content

Commit

Permalink
integrate some widgets
Browse files Browse the repository at this point in the history
  • Loading branch information
thomas--graf committed Nov 28, 2018
1 parent b9ecaef commit ca05253
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 0 deletions.
27 changes: 27 additions & 0 deletions source/background/functions/00_basic_notation.mdown
Expand Up @@ -50,6 +50,33 @@ for _ in range(10):
print("The output of random_output({}) is {}".format(5, random_output(5)))
```

```python
import random
import re
import ipywidgets
from ipywidgets import Button, Layout

from IPython.display import display

# a programming function that is not a mathematical function
def random_output(number):
# randomly choose between two outputs
if random.choice([True, False]):
return 2 * number
else:
return 3 * number

b = ipywidgets.Button(description='Click to run randomization',
layout=Layout(width='50%', height='80px'))
display(b)

def on_button_clicked(b):
for _ in range(10):
print("The output of random_output({}) is {}".format(5, random_output(5)))

b.on_click(on_button_clicked)
```

## Domains and co-domains

Every function has a **domain** and a **co-domain**.
Expand Down
26 changes: 26 additions & 0 deletions source/background/functions/01_monotonicity.mdown
Expand Up @@ -39,6 +39,32 @@ for func in [f, g, h, i]:
plt.show()
```

```python
import numpy as np
import matplotlib.pyplot as plt
import ipywidgets
from ipywidgets import Button, Layout

from IPython.display import display

f = lambda x: 2*x
g = lambda x: x**2
h = lambda x: 2*x - 2**(x - 5) + 2**10
i = lambda x: x/2 - 2**x

b = ipywidgets.Button(description='Show graphs',
layout=Layout(width='50%', height='80px'))
display(b)

def on_button_clicked(b):
for func in [f, g, h, i]:
values = np.linspace(-10, 10)
plt.plot(values, func(values))
plt.show()

b.on_click(on_button_clicked)
```

A function is monotonic iff it does not change direction: once it goes up, it cannot go down, and the other way round.
Among the functions above, only the first and the last are monotonic.

Expand Down

0 comments on commit ca05253

Please sign in to comment.