Contact
CoCalc Logo Icon
StoreFeaturesDocsShareSupport News AboutSign UpSign In
| Download

All published worksheets from http://sagenb.org

Views: 168742
Image: ubuntu2004

This program runs an interactive grapher. Given a function, it will try to compute the first and second derivatives, the plot them in different colors.

This first cell contains an example of what will be done with the interactive grapher.

# Example f(x) = x*(x+3)*(x-1)*(x-3)^2 Xmin = -4 Xmax = 4 # Set up the derivatives of the given function df(x) = derivative(f(x)) d2f(x) = derivative(df(x)) # Set Range Ymin = min(min(f.find_minimum_on_interval(Xmin,Xmax)), min(df.find_minimum_on_interval(Xmin,Xmax)), min(d2f.find_minimum_on_interval(Xmin,Xmax))) Ymax = max(max(f.find_maximum_on_interval(Xmin,Xmax)), max(df.find_maximum_on_interval(Xmin,Xmax)), max(d2f.find_maximum_on_interval(Xmin,Xmax))) # Set up the graphs of the function and derivatives P = plot(f, Xmin, Xmax) P = P + plot(df, Xmin, Xmax, color = 'red') P = P + plot(d2f, Xmin, Xmax, color = 'green') # Graph it all html("Original function in blue, 1st derivative in red, 2nd derivative in green") show(P, Xmin, Xmax, Ymin, Ymax )
Original function in blue, 1st derivative in red, 2nd derivative in green

Interactive Grapher

@interact def _(f = input_box(default=x, label = 'Function:'), Xmin = input_box(default=-10, label = 'xmin:'), Xmax = input_box(default=10, label = 'xmax:')): # Set up the derivatives of the given function df(x) = derivative(f(x)) d2f(x) = derivative(df(x)) # Set Range Ymin = min(min(f.find_minimum_on_interval(Xmin,Xmax)), min(df.find_minimum_on_interval(Xmin,Xmax)), min(d2f.find_minimum_on_interval(Xmin,Xmax))) Ymax = max(max(f.find_maximum_on_interval(Xmin,Xmax)), max(df.find_maximum_on_interval(Xmin,Xmax)), max(d2f.find_maximum_on_interval(Xmin,Xmax))) # Set up the graphs of the function and derivatives P = plot(f, Xmin, Xmax) P = P + plot(df, Xmin, Xmax, color = 'red') P = P + plot(d2f, Xmin, Xmax, color = 'green') # Graph it all html("Original function in blue, 1st derivative in red, 2nd derivative in green") show(P, Xmin, Xmax, Ymin, Ymax )