## Demo of interactive widgets in IPython.  

For more information and examples, see:

<http://nbviewer.ipython.org/github/ipython/ipython/blob/2.x/examples/Interactive%20Widgets/Index.ipynb> 

Using widgets requires IPython 2.0, see <http://ipython.org/install.html> for installation advice.  

(Not available on SageMathCloud yet.)


```
%pylab inline
```

    Populating the interactive namespace from numpy and matplotlib



```
from IPython.html.widgets import interact, interactive, fixed
from IPython.display import display

```

## An example function to plot $\sin(2\pi kx)$ as a function of $x$ for given wave number $k$.


```
def plot_sine(k):
    x = linspace(-2,2,1000)
    plot(x,sin(2*pi*k*x))
                
```

For one particular $k$:


```
plot_sine(2)
```

Make it interactive with a slider bar for $k$ between 0 and 5 by steps of 0.1:


```
w = interactive(plot_sine, k=(0,5,0.1))
display(w)
```

## An example with SymPy:


```
import sympy as S
S.init_printing() 
x = S.symbols('x')
```


```
def expand_power(n):
    f = (x + 1)**n
    f2 = S.expand(f)
    display(f2)
        
```


```
expand_power(3)
```


```
w = interactive(expand_power, n=(1,10,1))
display(w)
```

4e121884ff916677a03084007527f9e8d1c83afa
ipynb
Jupyter Notebook
uwhpsc/labs/lab13/widgets_demo.ipynb
philipwangdk/HPC
e2937016821701adb80ece5bf65d43d1860640c0
MIT
uwhpsc/labs/lab13/widgets_demo.ipynb
philipwangdk/HPC
e2937016821701adb80ece5bf65d43d1860640c0
MIT
uwhpsc/labs/lab13/widgets_demo.ipynb
philipwangdk/HPC
e2937016821701adb80ece5bf65d43d1860640c0
MIT
Qwen/Qwen-72B
1. YES
2. YES