#! /usr/bin/env python # def broyden ( m, x ): #*****************************************************************************80 # ## BROYDEN computes the two dimensional modified Broyden function. # # Discussion: # # This function has a global minimizer: # # X = ( -0.511547141775014, -0.398160951772036 ) # # for which # # F(X) = 1.44E-04 # # Start the search at # # X = ( -0.9, -1.0 ) # # Licensing: # # This code is distributed under the GNU LGPL license. # # Modified: # # 23 January 2016 # # Author: # # John Burkardt # # Reference: # # Charles Broyden, # A class of methods for solving nonlinear simultaneous equations, # Mathematics of Computation, # Volume 19, 1965, pages 577-593. # # Jorge More, Burton Garbow, Kenneth Hillstrom, # Testing unconstrained optimization software, # ACM Transactions on Mathematical Software, # Volume 7, Number 1, March 1981, pages 17-41. # # Parameters: # # Input, integer M, the number of variables. # # Input, real X(M), the argument of the function. # # Output, real F, the value of the function at X. # f1 = abs ( ( 3.0 - x[0] ) * x[0] - 2.0 * x[1] + 1.0 ) f2 = abs ( ( 3.0 - 2.0 * x[1] ) * x[1] - x[0] + 1.0 ) p = 3.0 / 7.0 f = f1 ** p + f2 ** p return f def broyden_test ( ): #*****************************************************************************80 # ## BROYDEN_TEST works with the Broyden function. # # Licensing: # # This code is distributed under the GNU LGPL license. # # Modified: # # 23 January 2016 # # Author: # # John Burkardt # import numpy as np import platform from compass_search import compass_search from r8vec_print import r8vec_print print ( '' ) print ( 'BROYDEN_TEST:' ) print ( ' Python version: %s' % ( platform.python_version ( ) ) ) print ( ' Test COMPASS_SEARCH with the Broyden function.' ) m = 2 delta_tol = 0.00001 delta = 0.3 k_max = 20000 x = np.array ( [ -0.9, -1.0 ] ) r8vec_print ( m, x, ' Initial point X0:' ) print ( '' ) print ( ' F(X0) = %g' % ( broyden ( m, x ) ) ) x, fx, k = compass_search ( broyden, m, x, delta_tol, delta, k_max ) r8vec_print ( m, x, ' Estimated minimizer X1:' ) print ( '' ) print ( ' F(X1) = %g, number of steps = %d' % ( fx, k ) ) # # Demonstrate correct minimizer. # x = np.array ( [ -0.511547141775014, -0.398160951772036 ] ) r8vec_print ( m, x, ' Correct minimizer X*:' ) print ( '' ) print ( ' F(X*) = %g' % ( broyden ( m, x ) ) ) # # Terminate. # print ( '' ) print ( 'BROYDEN_TEST' ) print ( ' Normal end of execution.' ) return if ( __name__ == '__main__' ): from timestamp import timestamp timestamp ( ) broyden_test ( ) timestamp ( )