Scroll to Top

Virtual Math Learning Center

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

Finding Absolute (Global) Extrema in Python

Author: David Manuel

In this video, it is demonstrated how to use Python find the absolute maximum and minimum on a closed and bounded interval. The presenter uses Python to find the derivative, solve when the derivative equals zero to find the critical values, and then substitutes the critical values and endpoints into the function to find the absolute minimum.

Transcript 18

Problem: Suppose the relative humidity in College Station on a given June day is 70%.  According to meteorology models, the difference between the actual temperature \(T\) and the heat index \(H\) is approximately given by \[D = H-T = 0.00694T^2 - 10.505T + 399.05.\]  The record low and high temperatures for College Station in June are 53 and 107 degrees Fahrenheit respectively.  At what temperature on this interval is the difference the smallest, and what is that difference?  In mathematical terms, we want to minimize \(H\) on the domain \(T\) in \([53, 107].\)

Python Code:
from sympy import *

T=symbols('T')
D=.0694*T**2-10.505*T+399.05
dD=diff(D,T)
critvals=solve(dD,T)
print(critvals)

candidates=[53,critvals[0],107]
yvals=[D.subs(T,i) for i in candidates]
print(yvals)

print('The minimum distance is', yvals[1],'degrees when T is about 75.68 degrees.')

Open Python Notebook File

See more videos from this section