Finding the minimum of a function on a closed interval with Python
<p>Updated: How do I find the minimum of a function on a closed interval [0,3.5] in Python? So far I found the max and min but am unsure how to filter out the minimum from here. </p>

<pre><code>import sympy as sp

x = sp.symbols('x')

f = (x**3 / 3) - (2 * x**2) + (3 * x) + 1

fprime = f.diff(x)

all_solutions = [(xx, f.subs(x, xx)) for xx in sp.solve(fprime, x)]

print (all_solutions)
</code></pre>

<p><a href="http://i.stack.imgur.com/88Dzj.jpg" rel="nofollow"><img src="http://i.stack.imgur.com/88Dzj.jpg" alt="Interactive Python session"></a></p>

<p>The f.subs commands show two ways of displaying the value of the given function at x=3.5, the first as a rational approximation, the second as the exact fraction.</p>

<p><a href="http://i.stack.imgur.com/xrVic.png" rel="nofollow"><img src="http://i.stack.imgur.com/xrVic.png" alt="Graph produced by plot command"></a></p>

python numpy sympy