On Wed, Jan 12, 2011 at 9:45 AM, Sebastian Schubert
<address@hidden> wrote:
Hi,
I have a non-linear, non-quadratic function to minimize with some
constraints and sqp might be usable. However, I don't fully understand
the manual. From the first part, especially,
---------------
Function File: [X, OBJ, INFO, ITER, NF, LAMBDA] = sqp (X, PHI, G,
H, LB, UB, MAXITER, TOLERANCE)
Solve the nonlinear program
min phi (x)
x
subject to
g(x) = 0
h(x) >= 0
lb <= x <= ub
---------------
it looks like there is only a constraint for every single element of x
seperately (lb(1)<=x(1)<=ub(1), lb(2)<=x(2)<=ub(2), lb(3)<=x(3)<=ub(3),
...). One of my constraints is 0 <= x(i) <= 1 so I do need this. In
addition, I also need sum(x) = 1. With qp I was able to implement this
but is this also possible with sqp? The manual speaks of "the equality
and inequality constraint functions (which) must be of the form
r = f (x)
in which X is a vector and R is a vector." How is this connected to the
first part of the doc cited above?
Thank you
Sebastian
Short answer: the documentation is using vector shorthand; g and h are vector-valued functions, lb and ub are vectors the size of x.
Longer answer: The lb, ub should both be vectors the same size as your vector x. The functions g and h in the help file are vector-valued functions, and the right-hand-sides are really zero vectors whose length is the number of corresponding constraints. In other words, your g(x) and h(x) functions should include all your constraints at once.
So lb, ub should be vectors the same size as x, which will give you lb(i)<=x(i)<=ub(i), so in your case let
lb = zeros(size(x)); ub = ones(size(x));
I believe you can just make your g function an anonymous function:
g = @(x) sum(x) - 1;
if it's your only equality constraint. If there are others you'll have to make a function file for it.