Path: news.mathworks.com!not-for-mail
From: Alan Weiss <aweiss@mathworks.com>
Newsgroups: comp.soft-sys.matlab
Subject: Re: nonlinear constraint help
Date: Fri, 18 Sep 2009 12:58:13 -0400
Organization: The MathWorks, Inc.
Lines: 70
Message-ID: <h90e75$jfh$1@fred.mathworks.com>
References: <h8ufpv$2iq$1@fred.mathworks.com> <h8vuq3$5ng$2@fred.mathworks.com> <h908vv$b5f$1@fred.mathworks.com>
NNTP-Posting-Host: weissa.dhcp.mathworks.com
Mime-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit
X-Trace: fred.mathworks.com 1253293093 19953 172.31.57.141 (18 Sep 2009 16:58:13 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Fri, 18 Sep 2009 16:58:13 +0000 (UTC)
User-Agent: Thunderbird 2.0.0.23 (Windows/20090812)
In-Reply-To: <h908vv$b5f$1@fred.mathworks.com>
Xref: news.mathworks.com comp.soft-sys.matlab:571441


Simone, I am still not 100% sure I understand you, but I will make a 
guess at what you are asking.

You might be asking how to include the l0 and l matrices in your 
constraint function. You should include them exactly as described in the 
documentation:

function [c, ceq] = myconstr(x,l0,l)
c = [l(1,1)./l0.*x(2).*x(2*n+2)+...+l(1,n)./l0.*x(n+1).*x(3*n+1) 
-x(2*n+2).*x(n+2)-	x(3*n+1).*x(2*n+1) ]
ceq=[]

Load l and l0 into your MATLAB workspace, and define
constr = @(x)myconstr(x,l0,l)

Use constr as follows:

[x, fval, exitflag]=fmincon(@myobj,xs,A,b,Aeq,beq,lb,ub,constr);

If this is not what you were asking, please ask again, using more 
examples of exactly what you are trying to do and your syntax.

Alan Weiss
MATLAB mathematical toolbox documentation

Simone wrote:
> Dear Alan and all,
> 
> thanks a lot for the answer and sorry for my little clarity, I am gonna try again.
> So the idea is that I have a series of linear constraints called, as usual, with the A= matrix, b=vector, Aeq=matrix and beq= vector. I never specified in my use of MATLAB (which until recently has been mostly with linear programming) the name of the variables that satisfy these constraints, then I have a nonlinear constraint in which are both the variables present in the linear constraints and other objects (that I am interested in as a solution) in something like this:
> function [c, ceq] = myconstr(x,l0,l)
> c = [l(1,1)./l0.*x(2).*x(2*n+2)+...+l(1,n)./l0.*x(n+1).*x(3*n+1) -x(2*n+2).*x(n+2)-	x(3*n+1).*x(2*n+1) ]
> ceq=[]
> l0 and l are data given. I assumed that the variables of the system in the linear constraints are all in the vector x as given in the example from the Mathworks website (and I'm calling also my solution x as per below command). In the linear part I have 2*n+1 variables in the constraints so I started calling these new variables I would like to pass onto the system with x(2*n+2) until x(3*n+1), is it possible to do this?
> The following is the way I call the optimization function:
> [x, fval, exitflag]=fmincon(@myobj,xs,A,b,Aeq,beq,lb,ub,@myconstr);
> 
> Hoping this is clearer and can help you to help me,
> 
> Hoping you have a great weekend,
> 
> Best Regards,
> 
> Simone
> 
> 
> 
> 
> Alan Weiss <aweiss@mathworks.com> wrote in message <h8vuq3$5ng$2@fred.mathworks.com>...
>> I am sorry, I do not understand what you are asking. Perhaps you can 
>> include an example of the type of parameters you would like to include, 
>> and an example of the syntax you use to call your optimization function.
>>
>> Alan Weiss
>> MATLAB mathematical toolbox documentation
>>
>> Simone wrote:
>>> Hello to all,
>>>
>>> I have two maybe very dumb questions but I cannot get my head around these: I have a problem subject to 18 linear constraints and 1 nonlinear constraint. In this last one appear in part variables present also in the linear ones and other variables.
>>>  Questions: 
>>> 1. from the nonlinear constraint to recall the variables present in the linear constraints, I'm calling them with x(position), given the example here http://www.mathworks.com/access/helpdesk/help/toolbox/optim/index.html?/access/helpdesk/help/toolbox/optim/ug/brhkghv-7.html&http://www.mathworks.com/matlabcentral/newsreader/view_thread/256555 is this correct? the name of the solution in my function where I call fmincon is x.
>>>
>>> 2. the second question is if I can add more variables to be solved for in the nonlinear constraint, but these would be only in this constraint (they are multiplied by the other variables present also in the linear constraints so they should be identified, isn't it?). I have seen the documentation on how to pass parameters in the nonlinear constraints but not variables, is this possible?
>>>
>>> Thanks a lot for your help in advance,
>>>
>>> Best Regards,
>>>
>>> Simone