Minimizes a smooth multivariate function f(x), subject to arbitrary constraints, using sequential quadratic programming (SQP). The second form allows for specifying the derivatives of both the objective and constraints. |
||
Syntax |
x, f, c, dh, oh, ch = FMinCon(objFunc, conFunc, lb, ub, con_ub, init, maxIter, sqp_eps, deriv, gmax, userdata) x, f, c, dh, oh, ch = FMinCon(objFunc, gradFunc, conFunc, jacFunc, lb, ub, con_ub, init, maxIter, sqp_eps, gmax, userdata) |
|
Arguments |
Name |
Description |
objFunc |
Name of the user defined objective function. It must return a real number or one element vector. See Comments. |
|
gradFunc |
The name of the user defined objective derivative function. It must return a vector that has a length equal to the number of design variables. If the vector has one element, then a real number may be returned instead. See Comments section. |
|
conFunc |
Name of the user defined constraint function. It must return a vector of real numbers. If the vector has one element, then a real number may be returned instead. See Comments section. |
|
jacFunc |
The name of the user defined constraint Jacobian function. It must return a matrix with the number of rows equal to the number of constraints and the number of columns equal to the number of design variables. If the matrix has one element, then a real number may be returned instead. See Comments. |
|
lb |
The vector of lower bounds of the design variables. The length is the number of variables. |
|
ub |
The vector of upper bounds of the design variables. |
|
con_ub |
The vector of upper bounds of the constraint function output variables. |
|
init (optional) |
The vector of initial estimates for the design variables. The length is the number of variables. If it is empty or omitted, the midpoints of the bounding intervals are used. |
|
maxIter (optional) |
A one element vector containing the maximum number of iterations allowed. If it is empty or omitted, it defaults to 25. |
|
sqp_eps (optional) |
A one element vector containing a tolerance value in the SQP algorithm. If it is empty or omitted, it defaults to 0.0001. |
|
deriv (optional) |
A one element vector containing an integer to indicate the numerical derivative type to use. It equals 1 for forward differences and 2 for central differences. If it is empty or omitted, it defaults to 2. |
|
gmax (optional) |
A one element vector containing the constraint violation margin. If it is empty or omitted, it defaults to 0.5. |
|
userdata(optional) |
Data matrix that is passed to the user defined function at each iteration. This can be used to supply data that are defined outside the function. It can be omitted or empty. |
|
Output |
Name |
Description |
x |
The location of the function minimum. It may be only a local minimum. |
|
f |
The minimum value of the function. |
|
c |
A vector containing the constraint function values at the function minimum. It will have the same orientation as con_ub. |
|
dh |
A matrix containing the design variable history. Each column of the matrix contains the iteration step values for a design variable. |
|
oh |
A row vector containing the objective function history at each iteration step. |
|
ch |
A matrix containing the constraint function history. Each column of the matrix contains the iteration step values for a design variable. It is omitted from the outputs if there are no input constraints. |
|
Example 1 |
Find the minimum of a paraboloid, subject to x + 3y > = 22 and x + 5y > = 32. f(x,y) = (x-3)^2 - 5(x-3)(y-2) + 4(y-2)^2 + 6. The problem is defined with a lower bound which must be reformulated as an upper bound. |
|
Syntax// define the objective function function ObjFunc(x, d) { return 2*(x(1)-d(1))^2 - 5*(x(1)-d(1))*(x(2)-d(2)) + 4*(x(2)-d(2))^2 + 6 }
// define the objective function function ConFunc(x) { // note the negation to reformulate as upper bound return [-x(1) - 3*x(2), -x(1) - 5*x(2)] }
// find the minimum lowerBound = [-10, -10] upperBound = [10, 10] conUpBound = [-22, -32] // note the negation userData = [3, 2]
x,f = FMinCon("ObjFunc", "ConFunc", lowerBound, upperBound, conUpBound, [], [50], [1.0e-5], [], [0.6], userData) |
||
Resultx = 7 5 f = 14 |
||
Example 2 |
Modify the previous example to use the analytical gradient vector and the constraint Jacobian matrix. |
|
Syntax// define the gradient function function GradFunc(x) { out = [0, 0] out(1) = 4*(x(1)-3) - 5*(x(2)-2) out(2) = -5*(x(1)-3) + 8*(x(2)-2) return out }
// define the Jacobian function function ConJac(x) { return [-1, -3; -1, -5] }
// find the minimum x, f = FMinCon("ObjFunc", "GradFunc", "ConFunc", "ConJac", lowerBound, upperBound, conUpBound, [], [50], [1.0e-5], [0.6], userData) |
||
Resultx = 7 5 f = 14 |
||
Comments |
FMinCon is designed to work with objective functions that have continuous gradients. Otherwise, the chances of success may be greater using GA. The user defined functions get called by the solver until the objective is no longer decreasing based on the given tolerance. They accept a vector of the same size as lb for the variable values as the first argument. Optionally, they can take a data matrix as the second argument. If the functions that compute the gradient and Jacobian are omitted, the vector and matrix will be computed internally with numerical derivatives. Optionally, they can take a data matrix as the second parameter. The output vector x will have the same orientation as the input vector init. If the vector of initial estimates is omitted, the output vector will have the same orientation as the vector of lower bounds. However, the vector for the design variables that is passed to the user functions will be a column vector. |
|
See Also: |