Numerical Nonlinear Global Optimization Examples
Finding Multiple Optima, Method 1 | Solve Example |
Finding Multiple Optima, Method 2 | Queens on a Chessboard |
Finding a Nonlinear Fit of Data |
Finding Multiple Optima, Method 1
Here is one way to get multiple minima: call NMinimize multiple times with different random seeds, which will cause different optimization paths to be taken.
Finding Multiple Optima, Method 2
Here is another way to get multiple minima: write the objective function in such a way as to make a list of every point that is visited, then select the points that have objective function values close to the final solution.
Find all the visited points that are close in objective function value to the final solution. Then color them white, color the final solution black, and show them on the contour plot of the function:
Finding a Nonlinear Fit of Data
This plots the points and the solution from FindFit. The solution gets trapped by a local minimum due to the trigonometric functions:
This generates a sum of squares from the data, and uses NMinimize to find the minimum:
This plots the points and the solution from NMinimize:
Solve Example
Solve cannot work with this system of equations because they are highly nonalgebraic:
Give NMinimize a constant objective function, and the equations to be solved as constraints. It finds the solution:
Queens on a Chessboard
countAttacks[vec] converts the vector of real numbers into a permutation of the queens and counts the number of attacks:
Use DifferentialEvolution to fit all the queens on the chessboard so that no queen is attacking another queen. Postprocessing is turned off because it is unlikely to help, given the discrete nature of the problem: