With optimization, we are looking to determine a maximum or minimum value of a function over several variables. So, let's use an equation with an interesting curve in it:
If we take that curve and plot it to see if there is an apparent minimum value, we can use a script like the following that generates a plot as the result. (The %mathplotlib inline makes the plot appear inline of the Jupyter session, rather than creating the plot in a new window.)
%matplotlib inline from scipy import optimize import matplotlib.pyplot as plt import numpy as np def f(x): return x**4 - x**3 + x**2 + 1 x = np.linspace(-100, 50, 100) plt.plot(x, f(x));
Running this script in Jupyter, we see there is a natural minimum at x = 0.