Brent’s method is an optimization algorithm that combines a bisecting algorithm (Dekker’s method) and inverse quadratic interpolation. It can be used for constrained and unconstrained univariate function optimization. The Brent-Dekker method is an extension of the bisection method. It is a root-finding algorithm that combines elements of the secant method and inverse quadratic interpolation. It has reliable and fast convergence properties, and it is the univariate optimization algorithm of choice in many popular numerical optimization packages.

from numpy import arange
from scipy.optimize import minimize_scalar
import matplotlib.pyplot as plt

def obj_fun(x):
    return (x - 2.0) * x * (x + 2.0)**2.0

result = minimize_scalar(obj_fun, method='brent')
opt_x, opt_y = result['x'], result['fun']
print('Optimal x: %.6f' % opt_x)
print('Optimal y: %.6f' % opt_y)
print('Total Evaluations n: %d' % result['nfev'])
x_min, x_max = -3.0, 2.0
x = arange(x_min, x_max, 0.1)
y = [obj_fun(x) for x in x]
plt.plot(x, y)
plt.plot([opt_x], [opt_y], 'o', color='r')
plt.xlabel('x')
plt.ylabel('y')
plt.savefig("ex436.png", dpi=100)
plt.show()

Discover more from Tips and Hints for Aerospace Engineers

Subscribe now to keep reading and get access to the full archive.

Continue reading