Out[111]: 0.1*y + cos(y)
A necessary but not sufficient condition for a global minimum is that both partial
derivatives are zero. As stated before, there is no guarantee of a symbolic solution. Both
algorithmic and (multiple) existence issues come into play here. However, we can solve
the two equations numerically, providing “educated” guesses based on the global and local
minimization efforts from before:
In [ 112 ]: xo = sy.nsolve(del_x, -1.5)
xo
Out[112]: mpf(‘-1.4275517787645941’)
In [ 113 ]: yo = sy.nsolve(del_y, -1.5)
yo
Out[113]: mpf(‘-1.4275517787645941’)
In [ 114 ]: f.subs({x : xo, y : yo}).evalf()
# global minimum
Out[114]: -1.77572565314742
Again, providing uneducated/arbitrary guesses might trap the algorithm in a local
minimum instead of the global one:
In [ 115 ]: xo = sy.nsolve(del_x, 1.5)
xo
Out[115]: mpf(‘1.7463292822528528’)
In [ 116 ]: yo = sy.nsolve(del_y, 1.5)
yo
Out[116]: mpf(‘1.7463292822528528’)
In [ 117 ]: f.subs({x : xo, y : yo}).evalf()
# local minimum
Out[117]: 2.27423381055640
This numerically illustrates that zero partial derivatives are necessary but not sufficient.
SYMBOLIC COMPUTATIONS
When doing mathematics with Python, you should always think of SymPy and symbolic computations. Especially
for interactive financial analytics, this can be a more efficient approach compared to non-symbolic approaches.