# Matplotlib compatibility patch for Pyodide
import matplotlib
if not hasattr(matplotlib.RcParams, "_get"):
matplotlib.RcParams._get = dict.get
Unconstrained optimization using scipy#
In this chapter, we’ll cover how to apply scipy.optimize.minimize to unconstrained optimization problems. As a reminder, unconstrained optimization considers:
with:
\(x\): the design variable of length \(n\)
\(f\): the objective function.
Method#
In this course, we’re making use of the function scipy.optimize.minimize. The documentation of this function is available here:
https://docs.scipy.org/doc/scipy-1.15.0/reference/generated/scipy.optimize.minimize.html [The SciPy community, 2024]. In this course we’ll cover only the relevant parts.
For unconstrained optimization we need to run at least scipy.optimize.minimize(fun, x0, ...) with:
fun, the objective function \(f\left(x\right)\) to be minimized.funis a callable. Thescipy.optimize.minimizefunction takes care of defining and inputting our design variable \(x\).x0, the initial guess for our design variable \(x\). It needs to be andarraywith length \(n\)
The function scipy.optimize.minimize outputs an object scipy.optimize.OptimizeResult. with:
scipy.optimize.OptimizeResult.xthe optimized solution of the design variable \(x\). It is andarraywith length \(n\)scipy.optimize.OptimizeResult.success, a indication whether or not the optimizer was executed successfully. It is abool, indicatingTrueorFalsescipy.optimize.OptimizeResult.message, a message describing the cause of termination of the optimization algorithm. It is astr.scipy.optimize.OptimizeResult.fun, the values of the optimized objective function \(f\). It is aintorfloatscipy.optimize.OptimizeResult.nit, the number of iteration performed by the optimizer. It is aint
Exercise 8