#! /usr/bin/env python # def powell ( m, x ): #*****************************************************************************80 # ## POWELL computes the Powell singular quartic function. # # Discussion: # # This function has a global minimizer: # # X* = ( 0.0, 0.0, 0.0, 0.0 ), F(X*) = 0. # # Start the search at # # X = ( 3.0, -1.0, 0.0, 1.0 ) # # Licensing: # # This code is distributed under the GNU LGPL license. # # Modified: # # 23 January 2016 # # Author: # # John Burkardt # # Reference: # # Michael Powell, # An Iterative Method for Finding Stationary Values of a Function # of Several Variables, # Computer Journal, # Volume 5, 1962, pages 147-151. # # 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 = x[0] + 10.0 * x[1] f2 = x[2] - x[3] f3 = x[1] - 2.0 * x[2] f4 = x[0] - x[3] f = f1 * f1 + f2 * f2 + f3 * f3 + f4 * f4 return f def powell_test ( ): #*****************************************************************************80 # ## POWELL_TEST works with the Powell 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 ( 'POWELL_TEST:' ) print ( ' Python version: %s' % ( platform.python_version ( ) ) ) print ( ' Test COMPASS_SEARCH with the Powell function.' ) m = 4 delta_tol = 0.00001 delta = 0.3 k_max = 20000 x = np.array ( [ 3.0, -1.0, 0.0, 1.0 ] ) r8vec_print ( m, x, ' Initial point X0:' ) print ( '' ) print ( ' F(X0) = %g' % ( powell ( m, x ) ) ) x, fx, k = compass_search ( powell, 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.0, 0.0, 0.0, 0.0 ] ) r8vec_print ( m, x, ' Correct minimizer X*:' ) print ( '' ) print ( ' F(X*) = %g' % ( powell ( m, x ) ) ) # # Terminate. # print ( '' ) print ( 'POWELL_TEST' ) print ( ' Normal end of execution.' ) return if ( __name__ == '__main__' ): from timestamp import timestamp timestamp ( ) powell_test ( ) timestamp ( )