# Plotting a function and its first and second derivatives in the Same Coordinate System
# Lauri Ruotsalainen, 2010
@interact
def func_deriv_interact(
function = input_box(default=x^5-3*x^3+1, label="Function:"),
x_range = input_box(default=(-2,2), label="Range (x)"),
y_range = input_box(default=(-8,8), label="Range (y)")
):
f(x) = function
df(x) = derivative(f(x), x)
ddf(x) = derivative(df(x), x)
plots = plot(f(x), x_range, thickness=1.5) + plot(df(x), x_range, color="green") + plot(ddf(x), x_range, color="red")
if y_range == (0,0):
show(plots, xmin=x_range[0], xmax=x_range[1])
else:
show(plots, xmin=x_range[0], xmax=x_range[1], ymin=y_range[0], ymax=y_range[1])
html("<center>$\color{Blue}{f(x) = %s}$</center>"%latex(f(x)))
html("<center>$\color{Green}{f'(x) = %s}$</center>"%latex(df(x)))
html("<center>$\color{Red}{f''(x) = %s}$</center>"%latex(ddf(x)))
|
|
Click to the left again to hide and once more to show the dynamic interactive window
|