Funciton Tool
Description
This interact lets the user input functions f and g, an x and y range for them to be plotted on, some constant a and then select from a list of various combinations or transformations of f, g and a to observe the plot of the results.
Sage Cell
Code
x = var('x')
@interact
def _(f=sin(x), g=cos(x), xrange=input_box((0,1)), yrange='auto', a=1,
action=selector(['f', 'df/dx', 'int f', 'num f', 'den f', '1/f', 'finv',
'f+a', 'f-a', 'f*a', 'f/a', 'f^a', 'f(x+a)', 'f(x*a)',
'f+g', 'f-g', 'f*g', 'f/g', 'f(g)'],
width=15, nrows=5, label="h = "),
do_plot = ("Draw Plots", True)):
try:
f = SR(f); g = SR(g); a = SR(a)
except TypeError as msg:
print(msg[-200:])
print("Unable to make sense of f,g, or a as symbolic expressions.")
return
if not (isinstance(xrange, tuple) and len(xrange) == 2):
xrange = (0,1)
h = 0; lbl = ''
if action == 'f':
h = f
lbl = 'f'
elif action == 'df/dx':
h = f.derivative(x)
lbl = '\\frac{df}{dx}'
elif action == 'int f':
h = f.integrate(x)
lbl = '\\int f dx'
elif action == 'num f':
h = f.numerator()
lbl = '\\text{numer(f)}'
elif action == 'den f':
h = f.denominator()
lbl = '\\text{denom(f)}'
elif action == '1/f':
h = 1/f
lbl = '\\frac{1}{f}'
elif action == 'finv':
h = solve(f == var('y'), x)[0].rhs()
lbl = 'f^{-1}(y)'
elif action == 'f+a':
h = f+a
lbl = 'f + a'
elif action == 'f-a':
h = f-a
lbl = 'f - a'
elif action == 'f*a':
h = f*a
lbl = 'f \\times a'
elif action == 'f/a':
h = f/a
lbl = '\\frac{f}{a}'
elif action == 'f^a':
h = f^a
lbl = 'f^a'
elif action == 'f^a':
h = f^a
lbl = 'f^a'
elif action == 'f(x+a)':
h = f(x+a)
lbl = 'f(x+a)'
elif action == 'f(x*a)':
h = f(x*a)
lbl = 'f(xa)'
elif action == 'f+g':
h = f+g
lbl = 'f + g'
elif action == 'f-g':
h = f-g
lbl = 'f - g'
elif action == 'f*g':
h = f*g
lbl = 'f \\times g'
elif action == 'f/g':
h = f/g
lbl = '\\frac{f}{g}'
elif action == 'f(g)':
h = f(g)
lbl = 'f(g)'
pretty_print(html('<center><font color="red">$f = %s$</font></center>'%latex(f)))
pretty_print(html('<center><font color="green">$g = %s$</font></center>'%latex(g)))
pretty_print(html('<center><font color="blue"><b>$h = %s = %s$</b></font></center>'%(lbl, latex(h))))
if do_plot:
P = plot(f, xrange, color='red', thickness=2) + \
plot(g, xrange, color='green', thickness=2) + \
plot(h, xrange, color='blue', thickness=2)
if yrange == 'auto':
show(P, xmin=xrange[0], xmax=xrange[1])
else:
yrange = sage_eval(yrange)
show(P, xmin=xrange[0], xmax=xrange[1], ymin=yrange[0], ymax=yrange[1])
Options
none
Tags
Primary Tags:
Secondary Tags:
A list of possible tags can be found at The WeBWorK Open Problem Library. For linear algebra tags see the Curated Courses Project.
Related Cells
Any related cells go here. Provide a link to the page containing the information about the cell.
Attribute
Permalink:
Author:
Date: 22 Jul 2020 23:08
Submitted by: Zane Corbiere