Wolfram ResearchPRODUCTSPURCHASEFOR USERSCOMPANYOUR SITES
THIS IS DOCUMENTATION FOR AN OBSOLETE PRODUCT.
SEE THE DOCUMENTATION CENTER FOR THE LATEST INFORMATION.

Documentation / Mathematica / Built-in Functions / Numerical Computation / Optimization /

Further Examples: NMinimize

Finding Multiple Optima, Method 1

Here we define a function with a whole ring of minima.

In[47]:=

This makes a table of solutions by using different random seeds.

In[50]:=

Out[50]=

Here we turn the solutions into points and plot them on the ContourPlot of the function.

In[51]:=

Finding Multiple Optima, Method 2

Here is another way to get multiple minima: we will write our 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 our final solution.

Here we define a function with a whole ring of minima.

In[55]:=

Reap returns the solution from NMinimize and the points sown by the EvaluationMonitor.

In[58]:=

Out[59]=

Here we find all the visited points that are close in objective function value to the final solution. We then color them white, the final solution black, and plot them on the ContourPlot of the function.

In[60]:=

Finding a Nonlinear Fit of Data

This defines a model based on five random parameters.

In[65]:=

Out[67]=

Here we create a function from the model and parameters, and generate sample points over the interval .

In[68]:=

This plots the points and the solution from FindFit. The solution gets trapped by a local minimum due to the trigonometric functions.

In[70]:=

Here we generate a sum of squares from the data, and use NMinimize to find the minimum.

In[73]:=

Out[74]=

This plots the points and the solution from NMinimize.

In[75]:=

Solve Example

In[77]:=

Solve cannot work with this system of equations because they are highly nonalgebraic.

In[78]:=

Out[78]=

Here we give NMinimize a constant objective function, and the equations to be solved as constraints. It finds the solution.

In[79]:=

Out[79]=

Queens on a Chessboard

In[80]:=

attackQ[pos1, pos2] is True if and only if pos1 is attacking pos2.

In[81]:=

countAttacks[vec] converts the vector of real numbers into a permutation of the queens and counts the number of attacks.

In[82]:=

Given a permutation, this shows the arrangement.

In[83]:=

Here we use DifferentialEvolution to fit all the queens on the chessboard so that no queen is attacking another queen. Post-processing is turned off because it is unlikely to help, given the discrete nature of the problem.

In[84]:=

Out[86]=

This shows the solution.

In[87]:=



Any questions about topics on this page? Click here to get an individual response.Buy NowMore Information


 © 2009 Wolfram Research, Inc.  Terms of Use  Privacy Policy | [ja] |
Sign up for our newsletter: