Home > Back-end >  Animate movement of Tangent line across graph
Animate movement of Tangent line across graph

Time:06-23

Background

Hello - I'm a new math's teacher and I've thought on how to illustrate the concept of derivatives. I would like to make a gif or a video (don't really care which one) of a tangent line moving along a graph.

I've tried many different ways, and most of the videos/ posts I've read, shows a graph being constructed as x changes... This is not really what I'm looking for, as following those videos I can also construct my graph. But I want a straight line changing its slope at each point along the graph.

# Define parabola
def f(x):
    return 5*x**3-2*x**2-2*x

# Define parabola derivative
def slope(x):
    return 15*x**2-4*x-2

# Define tangent line
def line(x, x1, y1):
    return slope(x1)*(x - x1)   y1

My question

are there any good examples of how this might be done? maybe videos or codes I could look at for inspiration?

I know my question is a bit vague, but thanks in advance

CodePudding user response:

You could use the FuncAnimation function that matplotlib provides (see doc enter image description here

  • Related