In Chapter 3, we learned how to define a mathematical function as a callable symbolic expression. Since we'll be working with callable symbolic expressions extensively in this chapter, let's learn a little more about how to use them. Enter the following code into an input cell in a worksheet, and evaluate the cell:
var('a, b, c, x') f(x) = a * x^2 + b * x + c # A callable symbolic expression print("f(x):") f.show() print("Variables in f: {0} Arguments in f: {1}".format( f.variables(), f.arguments())) print("Type of f: {0}".format(type(f))) g(x) = f.derivative(x) print("g(x):") g.show() print("Variables in g: {0} Arguments in g: {1}".format( g.variables(), g.arguments())) g_plot = plot(g(a=1, b=-1), (-1, 1)) g_plot.axes_labels(['x', 'g(x)']) show(g_plot, figsize=(3,3), aspect_ratio=1.0)
The output is shown below: