Coordinate riseAlgorithm(Coordinate ascent) and c ++ programming implementation
Programming implementation:
# include
using namespace STD; # define F (x1, x2, X3) (-X1 * x1-2 * X2 * x2-3 * X3 * X3 + 2 * X1 * X2 + 2 * X1 * x3-4 * X2 * X3 + 6) int main () {double X1 = 1; double X2 = 1; double X3 = 1; double f0 = f (x1, x2, X3); double err = 1.0e-10; while (true) {x1 = x2 + X3; x2 = 0.5 * x1-x3; X3 = 1.0/3 * x1-2.0/3 * X2; double Ft = f (x1, x2, X3 ); if (ABS (ft-f0)
Experiment results:
Note: The method for solving the minimum value of a function is basically the same as this method. In addition, this algorithm is not very sensitive to the selection of initial values. It is very suitable for solving some problems.Source code download: http://download.csdn.net/detail/nuptboyzhb/4909729Discussion:
First, this algorithm cannot compute functions without the maximum and minimum values. However, in practice, if there is no maximum value or minimum value, the model is incorrect.
Second:ProgramIt is indeed impossible to know whether it is the maximum value or the minimum value. Because the maximum and minimum solutions are the same, they are obtained through partial guidance. However, the goal of solving many practical problems is clear.
Third: When a function has multiple maximum values and multiple minimum values, or a local minimum value (maximum value), the calculation result of the algorithm has a great relationship with the selection of the initial value, when the initial value is near the local optimal value, the result is the local optimal value. To find the global optimal value as much as possible,
You can randomly select multiple groups of initial values for iteration, and then select the optimal solution.