| Genetic Algorithm and Direct Search Toolbox | ![]() |
Find the minimum of a function using a pattern search
Syntax
x = patternsearch(@fun, x0)
x = patternsearch(@fun, x0, A, b)
x = patternsearch(@fun, x0, A, b, Aeq, beq)
x = patternsearch(@fun, x0, A, b, Aeq, beq, lb, ub)
x = patternsearch(@fun, x0, A, b, Aeq, beq, lb, ub, options)
x = patternsearch(problem)
[x, fval] = patternsearch(@fun, x0, ...)
[x, fval, exitflag] = patternsearch(@fun, x0, ...)
[x, fval, exitflag, output] = patternsearch(@fun, x0, ...)
Description
patternsearch finds the minimum of a function using a pattern search.
x = patternsearch(@fun, x0) solves unconstrained problems of the form
where fun is a MATLAB function that computes the values of the objective function f(x), and x0 is an initial point for the pattern search algorithm. The function patternsearch accepts the objective function as a function handle of the form @fun or as an inline function. patternsearch returns a local minimum x to the objective function. The function fun accepts a vector input and returns a scalar function value.
x = patternsearch(@fun, x0, A, b) finds a local minimum x to the function fun, subject to the linear inequality constraints represented in matrix form by
If the problem has m linear inequality constraints and n variables, then
x = patternsearch(@fun, x0, A, b, Aeq, beq) finds a local minimum x to the function fun, subject to the constraints
where Aeq x = beq represents the linear equality constraints in matrix form. If the problem has r linear equality constraints and n variables, then
If there are no inequality constraints, pass empty matrices, [], for A and b.
x = patternsearch(@fun, x0, A, b, Aeq, beq, lb, ub) finds a local minimum x to the function fun subject to the constraints
where
represents lower and upper bounds on the variables. If the problem has n variables, lb and ub are vectors of length n. If lb or ub is empty (or not provided), it is automatically expanded to -Inf or Inf, respectively. If there are no inequality or equality constraints, pass empty matrices for A, b, Aeq and beq.
x = patternsearch(@fun, x0, A, b, Aeq, beq, lb, ub, options) finds a local minimum x to the function fun, replacing the default optimization parameters by values in the structure options. You can create options with the function psoptimset. Pass empty matrices for A, b, Aeq, beq, lb, ub, and options to use the default values.
x = patternsearch(problem) finds the minimum for problem, a structure that has the following fields:
objective -- Objective function
X0 -- Starting point
Aineq -- Matrix for the inequality constraints
Bineq -- Vector for the inequality constraints
Aeq -- Matrix for the equality constraints
Beq -- Vector for the equality constraints
LB -- Lower bound for x
UB -- Upper bound for x
options -- Options structure created with psoptimset
randstate -- Optional field to reset the state of rand
randnstate -- Optional field to reset the state of randn
You can create the structure problem by exporting a problem from the Pattern Search Tool, as described in Importing and Exporting Options and Problems.
[x, fval] = patternsearch(@fun, x0, ...) returns the value of the objective function fun at the solution x.
[x, fval, exitflag] = patternsearch(@fun, x0, ...) returns exitflag, which describes the exit condition of patternsearch. If
exitflag > 0, patternsearch converged to a solution x.
exitflag = 0, patternsearch reached the maximum number of function evaluations or iterations.
exitflag < 0, patternsearch did not converge to a solution.
[x, fval, exitflag, output] = patternsearch(@fun, x0, ...) returns a structure output containing information about the search. The output structure contains the following fields:
function -- Objective function
problemtype -- Type of problem: unconstrained, bound constrained or linear constrained
pollmethod -- Polling method
searchmethod -- Search method used, if any
iteration -- Total number of iterations
funccount -- Total number of function evaluations
meshsize -- Mesh size at x
message -- Reason why the algorithm terminated
Example
Given the following constraints
the following code finds the minimum of the function, lincontest6, that is provided with the toolbox:
A = [1 1; -1 2; 2 1]; b = [2; 2; 3]; lb = zeros(2,1); [x, fval, exitflag] = patternsearch(@lincontest6,... [0 0],A,b,[],[],lb) Optimization terminated: Next Mesh size (9.5367e-007)less than 'TolMesh.' x = 0.6667 1.3333 fval = -8.2222 exitflag = 1
See Also
psearchtool, psoptimget, psoptimset
| gatool | psearchtool | ![]() |
| © 1994-2009 The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |