Scroll to Top

Virtual Math Learning Center

Virtual Math Learning Center Texas A&M University Virtual Math Learning Center

Finding Intervals of Increase/Decrease and Concavity in Python

Author: David Manuel

In this video, it is shown how to plot a function in Python to try to determine where the function is increasing and decreasing and where it is concave up or down. The presenter then shows how to take the first derivative in Python, and use it to determine the intervals where the function is increasing and decreasing. It is also mentioned how to alter this technique to find the intervals where the function is concave up and concave down.

Transcript 19

Problem: Analyze the graph of \begin{align*}y=&2x^7-21x^6-36x^5+3x^4\\ &-38x^3+24x^2 \end{align*} and find where the function is increasing or decreasing and where the function is concave upward or downward.

Python Code: 
Analyze the graph of y=2x^7-21x^6-36x^5+3x^4-38x^3+24x^2

from sympy import *

x=symbols('x')
y=2*x**7-21*x**6-36*x**5+3*x**4-38*x**3+24*x**2

matplotlib notebook

plot(y,(x,-10,10),ylim=[-10,10])

dy=diff(y,x)
# To find concavity, repeat this process but use dy=diff(y,x,2) to get the second derivative
cvals=solve(dy,x)
cvalsfloat=[i.evalf() for i in cvals]
print(cvalsfloat)

matplotlib notebook

plot(dy,(x,-2,11),ylim=[-10,10])

print('The function is increasing from(-∞,-1.625),(0,0.35),(10,253,∞)')
print('and decreasing from (-1.625,0) and (0.35,10.253)')

Open Python Notebook File

See more videos from this section