Contact
CoCalc Logo Icon
StoreFeaturesDocsShareSupport News AboutSign UpSign In
| Download

All published worksheets from http://sagenb.org

Views: 168733
Image: ubuntu2004

Animation: Difference Quotient

Lauri Ruotsalainen, 2010

# Animation: Difference Quotient # Lauri Ruotsalainen, 2010 def difference_quotient(f, range, a, x0): f(x) = f fmax = f.find_maximum_on_interval(range[0], range[1])[0] fmin = f.find_minimum_on_interval(range[0], range[1])[0] f_height = fmax - fmin measure_y = fmin - 0.1*f_height measure_0 = line2d([(x0, measure_y), (a, measure_y)], rgbcolor="black") measure_1 = line2d([(x0, measure_y + 0.02*f_height), (x0, measure_y-0.02*f_height)], rgbcolor="black") measure_2 = line2d([(a, measure_y + 0.02*f_height), (a, measure_y-0.02*f_height)], rgbcolor="black") text_x0 = text("x0", (x0, measure_y - 0.05*f_height), rgbcolor="black") text_a = text("a", (a, measure_y - 0.05*f_height), rgbcolor="black") measure = measure_0 + measure_1 + measure_2 + text_x0 + text_a tanf(x) = (f(x0)-f(a))*(x-a)/(x0-a)+f(a) fplot = plot(f(x), x, range[0], range[1]) tanplot = plot(tanf(x), x, range[0], range[1], rgbcolor=(1,0,0)) points = point([(x0,f(x0)), (a,f(a))], pointsize=20, rgbcolor="#005500") dashline = line2d([(x0,f(x0)), (x0,f(a)), (a,f(a))], rgbcolor="#005500", linestyle="--") composite = fplot + tanplot + points + dashline + measure return composite v = [] for x0 in srange(3,6.7,0.2): v.append(difference_quotient("sin(x)", (0,10), 6.7, x0)) a = animate(v, xmin = 0, xmax = 10, ymin = -1, ymax = 1) a.show(delay=40)