Simple Tangent Line Grapher
Description
Here is a Sage interact that plots a tangent line to a given function. The xbegin and xend sliders control the endpoints of the graphed curve, and x0 slider controls the point at which the tangent is calculated.
Sage Cell
Code
pretty_print(html('<h2>Tangent line grapher</h2>'))
@interact
def tangent_line(f = input_box(default=sin(x)), xbegin = slider(0,10,1/10,0), xend = slider(0,10,1/10,10), x0 = slider(0, 1, 1/100, 1/2)):
prange = [xbegin, xend]
x0i = xbegin + x0*(xend-xbegin)
var('x')
df = diff(f)
tanf = f(x=x0i) + df(x=x0i)*(x-x0i)
fplot = plot(f, prange[0], prange[1])
print('Tangent line is y = ' + tanf._repr_())
tanplot = plot(tanf, prange[0], prange[1], rgbcolor = (1,0,0))
fmax = f.find_local_maximum(prange[0], prange[1])[0]
fmin = f.find_local_minimum(prange[0], prange[1])[0]
show(fplot + tanplot, xmin = prange[0], xmax = prange[1], ymax = fmax, ymin = fmin)
Options
None
Tags
Primary Tags: Single Variable Calculus: Limits and continuity
Secondary Tags: Limits and continuity: Applications - tangent lines and slopes
Related Cells
None
Attribute
Permalink: https://wiki.sagemath.org/interact/calculus#A_simple_tangent_line_grapher
Author: Marshall Hampton
Date: 19 Jul 2020 02:56
Submitted by: Zane Corbiere