From: ss4johnny Hall on
These comments and the documentation don't seem to refer to gradients in the nonlinear constraints. I got multiple nonlinear constraints to work, but the gradients don't seem to (they do in the one variable case). For instance I have defined a vector x with five elements and I have two nonlinear constraints. When I set up the gradient, the example in the documentation clearly shows that you have the gradient in row 1 with the partial derivatives for each variable in each column. However, when I run the optimization it tells me that the matrix needs to be 5 by 2, rather than 2 by 5. Then, when I run the optimization it gives me results that don't match what happens when I don't use the gradients.

Any help on this would be appreciated.
From: Alan Weiss on
On 5/27/2010 2:54 AM, ss4johnny Hall wrote:
> These comments and the documentation don't seem to refer to gradients in
> the nonlinear constraints. I got multiple nonlinear constraints to work,
> but the gradients don't seem to (they do in the one variable case). For
> instance I have defined a vector x with five elements and I have two
> nonlinear constraints. When I set up the gradient, the example in the
> documentation clearly shows that you have the gradient in row 1 with the
> partial derivatives for each variable in each column. However, when I
> run the optimization it tells me that the matrix needs to be 5 by 2,
> rather than 2 by 5. Then, when I run the optimization it gives me
> results that don't match what happens when I don't use the gradients.
> Any help on this would be appreciated.

As explained in the documentation
http://www.mathworks.com/access/helpdesk/help/toolbox/optim/ug/brhkghv-11.html#brhkghv-16
each column of the gradient matrix should correspond to one constraint.
So for two constraints and 5 dimensions, the constraint gradient should
be 5 by 2 (5 rows, 2 columns).

If you want to check that you computed the gradient correctly, turn on
the DerivativeCheck option as described here:
http://www.mathworks.com/access/helpdesk/help/toolbox/optim/ug/f12471.html#br5u_mf

Alan Weiss
MATLAB mathematical toolbox documentation
From: ss4johnny Hall on
Alan Weiss <aweiss(a)mathworks.com> wrote in message <htli5m$8n0$1(a)fred.mathworks.com>...
> On 5/27/2010 2:54 AM, ss4johnny Hall wrote:
> > These comments and the documentation don't seem to refer to gradients in
> > the nonlinear constraints. I got multiple nonlinear constraints to work,
> > but the gradients don't seem to (they do in the one variable case). For
> > instance I have defined a vector x with five elements and I have two
> > nonlinear constraints. When I set up the gradient, the example in the
> > documentation clearly shows that you have the gradient in row 1 with the
> > partial derivatives for each variable in each column. However, when I
> > run the optimization it tells me that the matrix needs to be 5 by 2,
> > rather than 2 by 5. Then, when I run the optimization it gives me
> > results that don't match what happens when I don't use the gradients.
> > Any help on this would be appreciated.
>
> As explained in the documentation
> http://www.mathworks.com/access/helpdesk/help/toolbox/optim/ug/brhkghv-11.html#brhkghv-16
> each column of the gradient matrix should correspond to one constraint.
> So for two constraints and 5 dimensions, the constraint gradient should
> be 5 by 2 (5 rows, 2 columns).
>
> If you want to check that you computed the gradient correctly, turn on
> the DerivativeCheck option as described here:
> http://www.mathworks.com/access/helpdesk/help/toolbox/optim/ug/f12471.html#br5u_mf
>
> Alan Weiss
> MATLAB mathematical toolbox documentation

Seems your right. Was a little late at night when I was writing that. I'll try that derivative check option.
From: ss4johnny Hall on
I re-ran it with the DerivativeCheck and the derivatives were calculated correctly. The problem was using the interior point algorithm instead of the active-set algorithm. Not sure what the best way to adapt the problem so that it returns to interior-point (or even if that's a good idea). interior-point produced the right solution with the one constraint, just not he second.