Thread Subject: CONSTRAINTS FOR FMINCON

Subject: CONSTRAINTS FOR FMINCON

From: Isaac

Date: 16 Nov, 2009 12:12:03

Message: 1 of 5

Using fmincon, the objective function (in my case -V'*x) can be inserted simply in the code:

x=fmincon(@(x) -V'*x,zeros(5,1),A,b,Aeq,beq,lb,ub, NON LINEAR CONSTRAINTS?)

but i didn't manage to do the same with the non linear constraints, i tried for example

x=fmincon(@(x) -V'*x,zeros(5,1),A,b,Aeq,beq,lb,ub,@(x) [[],sum(x>0)-2])

but it does not work...

can You help me?

thanks

Subject: CONSTRAINTS FOR FMINCON

From: John D'Errico

Date: 16 Nov, 2009 12:30:20

Message: 2 of 5

"Isaac " <asimov4000@hotmail.com> wrote in message <hdrfij$64j$1@fred.mathworks.com>...
> Using fmincon, the objective function (in my case -V'*x) can be inserted simply in the code:
>
> x=fmincon(@(x) -V'*x,zeros(5,1),A,b,Aeq,beq,lb,ub, NON LINEAR CONSTRAINTS?)
>
> but i didn't manage to do the same with the non linear constraints, i tried for example
>
> x=fmincon(@(x) -V'*x,zeros(5,1),A,b,Aeq,beq,lb,ub,@(x) [[],sum(x>0)-2])
>
> but it does not work...
>
> can You help me?

An anonymous function cannot return TWO
output arguments. Use a regular m-file for that
part.

John

Subject: CONSTRAINTS FOR FMINCON

From: John D'Errico

Date: 16 Nov, 2009 12:44:02

Message: 3 of 5

"John D'Errico" <woodchips@rochester.rr.com> wrote in message <hdrgks$bed$1@fred.mathworks.com>...
> "Isaac " <asimov4000@hotmail.com> wrote in message <hdrfij$64j$1@fred.mathworks.com>...
> > Using fmincon, the objective function (in my case -V'*x) can be inserted simply in the code:
> >
> > x=fmincon(@(x) -V'*x,zeros(5,1),A,b,Aeq,beq,lb,ub, NON LINEAR CONSTRAINTS?)
> >
> > but i didn't manage to do the same with the non linear constraints, i tried for example
> >
> > x=fmincon(@(x) -V'*x,zeros(5,1),A,b,Aeq,beq,lb,ub,@(x) [[],sum(x>0)-2])
> >
> > but it does not work...
> >
> > can You help me?
>
> An anonymous function cannot return TWO
> output arguments. Use a regular m-file for that
> part.
>
> John

Having said that too quickly, I forgot this trick

@(x) deal([],sum(x>0)-2)

At the same time, it matters not, because your
constraints are not differentiable, something that
fmincon will want to see.

John

Subject: CONSTRAINTS FOR FMINCON

From: Isaac

Date: 16 Nov, 2009 14:20:19

Message: 4 of 5

"John D'Errico" <woodchips@rochester.rr.com> wrote in message <hdrhei$16c$1@fred.mathworks.com>...
> "John D'Errico" <woodchips@rochester.rr.com> wrote in message <hdrgks$bed$1@fred.mathworks.com>...
> > "Isaac " <asimov4000@hotmail.com> wrote in message <hdrfij$64j$1@fred.mathworks.com>...
> > > Using fmincon, the objective function (in my case -V'*x) can be inserted simply in the code:
> > >
> > > x=fmincon(@(x) -V'*x,zeros(5,1),A,b,Aeq,beq,lb,ub, NON LINEAR CONSTRAINTS?)
> > >
> > > but i didn't manage to do the same with the non linear constraints, i tried for example
> > >
> > > x=fmincon(@(x) -V'*x,zeros(5,1),A,b,Aeq,beq,lb,ub,@(x) [[],sum(x>0)-2])
> > >
> > > but it does not work...
> > >
> > > can You help me?
> >
> > An anonymous function cannot return TWO
> > output arguments. Use a regular m-file for that
> > part.
> >
> > John
>
> Having said that too quickly, I forgot this trick
>
> @(x) deal([],sum(x>0)-2)
>
> At the same time, it matters not, because your
> constraints are not differentiable, something that
> fmincon will want to see.
>
> John

thanks John.
Yes anyway You are right: fmincon does not work.
How can i work with non diffentiable constraints?

thanks

Subject: CONSTRAINTS FOR FMINCON

From: Alan Weiss

Date: 16 Nov, 2009 20:57:02

Message: 5 of 5

Isaac wrote:

> thanks John.
> Yes anyway You are right: fmincon does not work.
> How can i work with non diffentiable constraints?
>
> thanks

Use a different solver. patternsearch from the Genetic Algorithm and
Direct Search Toolbox might be able to help.

Alan Weiss
MATLAB mathematical toolbox documentation

Tags for this Thread

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.

rssFeed for this Thread

Contact us at files@mathworks.com