Finding Relative (Local) Extrema
In this example, we find the maximum or minimum value of a function on a closed, bounded interval. 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]. The steps to minimize a function on a closed, bounded interval are:
1) Find the derivative of the function (diff)
2) Find the critical values by solving the derivative = 0 (solve)
3) Substitute the appropriate critical values and endpoints into the function (subs)
After loading the symbolic package into Python, we define T as a symbolic variable and define D as our expression. As always, we follow the steps above with the appropriate Python commands, looking up the details in the online help when necessary. Since we want to substitute all the values in step 3 into the same function, we can create a list of these numbers, which we will call candidates, and use list comprehension to compute them all at once. So yvals is the list of numbers found by substituting T=i into D for i in candidates. When we print yvals, we see the minimum difference is about 1.65 degrees when the temperature is about 75.66 degrees. Of course, looking at the endpoints, we see this model is not realistic for extreme values, but will suffice for our purposes.