Thread Subject: nonlinear constraint help

Subject: nonlinear constraint help

From: Simone

Date: 17 Sep, 2009 23:13:03

Message: 1 of 8

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

Subject: nonlinear constraint help

From: Alan Weiss

Date: 18 Sep, 2009 12:35:15

Message: 2 of 8

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

Subject: nonlinear constraint help

From: Matt

Date: 18 Sep, 2009 15:12:02

Message: 3 of 8

"Simone " <simonematool@gmail.com> wrote in message <h8ufpv$2iq$1@fred.mathworks.com>...
> 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?
====================

Yes.


>
> 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
==============

Yes.

 (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?
================

If your variables decompose as [x,y] where x and y are vectors, then neither your objective function f(x,y) nor your constraints Ci(x,y) have to have an explicit dependence on both x and y, even if they both take x and y as input arguments.


However, if f(x,y) is independent of y, i.e. can theoretically be written f(x), that gives the algorithm more freedom in finding a y that satisfies Ci(x,y)>=0. If it's important to distinguish between more than one possible solution for y, you must of course add more constraints....

Subject: nonlinear constraint help

From: Simone

Date: 18 Sep, 2009 15:29:03

Message: 4 of 8

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

Subject: nonlinear constraint help

From: Simone

Date: 18 Sep, 2009 16:07:01

Message: 5 of 8

Thanks a lot Matt for your answer, as you probably saw I was asnswering Alan already so only when I had already posted my reply I saw yours, sorry for the double post but I thank you for your answer, but then, if adding more variables can be done, do you think can it be that MATLAB gives me an error saying that the index exceeds matrix dimension in the nonlinear constraint because I add more variables in the nonlinear constraint or am I doing something else wrong??? Like the number of columns of A should be equal to the total number of variables, does it matter???

Thanks a lot again,

Best Regards,

Simone




"Matt " <xys@whatever.com> wrote in message <h90802$61u$1@fred.mathworks.com>...
> "Simone " <simonematool@gmail.com> wrote in message <h8ufpv$2iq$1@fred.mathworks.com>...
> > 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?
> ====================
>
> Yes.
>
>
> >
> > 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
> ==============
>
> Yes.
>
> (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?
> ================
>
> If your variables decompose as [x,y] where x and y are vectors, then neither your objective function f(x,y) nor your constraints Ci(x,y) have to have an explicit dependence on both x and y, even if they both take x and y as input arguments.
>
>
> However, if f(x,y) is independent of y, i.e. can theoretically be written f(x), that gives the algorithm more freedom in finding a y that satisfies Ci(x,y)>=0. If it's important to distinguish between more than one possible solution for y, you must of course add more constraints....

Subject: nonlinear constraint help

From: Alan Weiss

Date: 18 Sep, 2009 16:58:13

Message: 6 of 8

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

Subject: nonlinear constraint help

From: Matt

Date: 18 Sep, 2009 17:49:05

Message: 7 of 8

"Simone " <simonematool@gmail.com> wrote in message <h908vv$b5f$1@fred.mathworks.com>...
> 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?
=========================

No.

You must define both myobj(X) and myconstr(X) so that the input vector X is of length 3*n+1 and contains all variables that ever appear in the problem. It is not necessary that myobj() and myconstr actually use all 3*n+1 components of X. It is okay if they just use the first 2*n+1 of them.

You must also modify A and Aeq so that they have 3*n+1 columns. The columns 2*n+2 through 3*n+1 should be zero.

Similarly, you must extend ub and lb to be of length 3*n+1...

Subject: nonlinear constraint help

From: Simone

Date: 18 Sep, 2009 21:05:22

Message: 8 of 8

Dear Matt,
thanks a lot again, I will try!
Best regards,
Simone


"Matt " <xys@whatever.com> wrote in message <h90h6h$59s$1@fred.mathworks.com>...
> "Simone " <simonematool@gmail.com> wrote in message <h908vv$b5f$1@fred.mathworks.com>...
> > 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?
> =========================
>
> No.
>
> You must define both myobj(X) and myconstr(X) so that the input vector X is of length 3*n+1 and contains all variables that ever appear in the problem. It is not necessary that myobj() and myconstr actually use all 3*n+1 components of X. It is okay if they just use the first 2*n+1 of them.
>
> You must also modify A and Aeq so that they have 3*n+1 columns. The columns 2*n+2 through 3*n+1 should be zero.
>
> Similarly, you must extend ub and lb to be of length 3*n+1...

Tags for this Thread

Everyone's Tags:

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Tag Activity for This Thread
Tag Applied By Date/Time
nonlinear const... Simone 17 Sep, 2009 19:14:05
rssFeed for this Thread
 

MATLAB Central Terms of Use

NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Terms prior to use.

Contact us at files@mathworks.com