In [1]:
from __future__ import print_function
from IPython.html.widgets import interact, interactive, fixed
from IPython.html import widgets
In [4]:
def f(a, b, c, d, **kwargs):
x=np.linspace(-10, 10, 20)
y = a*(x**3) + b*(x**2) + c*x + d
title="$f(x) = (%s)x^{3} + (%s)x^{2} + (%s)x + (%s)$" % (a,b,c,d)
plt_arrays(x,y, title=title, **kwargs)
In [6]:
#This function plot x, y and adds a title
def plt_arrays(x, y, title="", color="red", linestyle="dashed", linewidth=2):
fig = plt.figure()
axes = fig.add_subplot(111)
axes.plot(x,y, color=color, linestyle=linestyle, linewidth=linewidth)
axes.set_title(title)
axes.grid()
plt.show()
In [7]:
#Define Constants
a=0.25
b=2
c=-4
d=0
f(a, b, c, d)
In [8]:
i = interact(f,
a=(-10.,10),
b=(-10.,10),
c=(-10.,10),
d=(-10.,10),
color = ["red", "blue", "green"],
linestyle=["solid", "dashed"],
linewidth=(1,5)
)
In [10]:
def f2(p, **kwargs):
a = p[0]
b = p[1]
c = p[2]
d = p[3]
x=np.linspace(-10, 10, 20)
y = a*(x**3) + b*(x**2) + c*x + d
title="$f(x) = (%s)x^{3} + (%s)x^{2} + (%s)x + (%s)$" % (a,b,c,d)
plt_arrays(x,y, title=title, **kwargs)
In [11]:
i2 = interact(f2,
p=(-10.,10),
color = ["red", "blue", "green"],
linestyle=["solid", "dashed"],
linewidth=(1,5)
)
In [12]:
@interact(x=True, y=1.0)
def g(x, y):
print(x, y)
In [13]:
x = [1,2,3,4]
In [19]:
for n, val in enumerate(x):
globals()["var%d"%n] = val
In [27]:
def manyArgs(*arg):
print("I was called with the following arguments:")
for i,val in enumerate(arg):
print(val)
In [28]:
manyArgs(1,3,'dog',[1,2])
In [26]:
help(enumerate)
In [ ]: