Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
fmincon initial point problem

Subject: fmincon initial point problem

From: Haemish

Date: 18 Mar, 2013 14:08:10

Message: 1 of 5

Dear sir,

I have some questions on fmincon initial value problem.

The code belows are very simple one which find the minimum value.

That is finding x^2+y^2+z^2+75 when lb=[0 0 0] and ub=[5 5 5]
with constraint of x+y+z=8

I think that even such a simple problem depends on the initial value strongly.

Initial point [0 0 0] gives the answer [2.667 2.667 2.667] but initial point [0 1 1] gives the answer [0 4 4]. However I know that the answer is [0 3 5] (irrespective the [x y z] sequence).

I think that this is convex quadratic problem but fmincon minimization answer should be found uniquely.

Are there any problems on my probelm definition? And are there any tips to overcome fmincon initial value problem except for random initial value startings?

Sincerely yours

Thank you.

----------------------------- code ----------------------------------------
%main.m
optNLP = optimset( 'UseParallel','always','Algorithm', 'active-set','Display','iter-detailed','TolX',1e-10,'TolFun',1e-15,'TolCon',1e-20,'MaxFunEval',10000,'MaxIter',1000000,'DiffMinChange',1e-15 );
pCOM0 = [0 5 5]';
lb = [0*ones(3,1)];
ub = [5*ones(3,1)];
[popt, Jopt, exitflag,output,labda,grad,hessian] = fmincon( @(p)obj(p), pCOM0,[], [], [], [], lb, ub, @(p)ctr(p), optNLP)

%ctr.m
function [c,ceq] = ctr(p)
    ceq=sum(p)-8;
    c=[];
end

%obj.m
function Y = obj(p)
    Y = -p(1).^2-p(2).^2-p(3).^2+75;
end

Subject: fmincon initial point problem

From: Alan_Weiss

Date: 18 Mar, 2013 14:52:31

Message: 2 of 5

On 3/18/2013 10:08 AM, Haemish wrote:
> Dear sir,
>
> I have some questions on fmincon initial value problem.
>
> The code belows are very simple one which find the minimum value.
>
> That is finding x^2+y^2+z^2+75 when lb=[0 0 0] and ub=[5 5 5]
> with constraint of x+y+z=8
>
> I think that even such a simple problem depends on the initial value
> strongly.
>
> Initial point [0 0 0] gives the answer [2.667 2.667 2.667] but initial
> point [0 1 1] gives the answer [0 4 4]. However I know that the answer
> is [0 3 5] (irrespective the [x y z] sequence).
>
> I think that this is convex quadratic problem but fmincon minimization
> answer should be found uniquely.
> Are there any problems on my probelm definition? And are there any
> tips to overcome fmincon initial value problem except for random
> initial value startings?
>
> Sincerely yours
>
> Thank you.
>
> ----------------------------- code
> ----------------------------------------
> %main.m
> optNLP = optimset( 'UseParallel','always','Algorithm',
> 'active-set','Display','iter-detailed','TolX',1e-10,'TolFun',1e-15,'TolCon',1e-20,'MaxFunEval',10000,'MaxIter',1000000,'DiffMinChange',1e-15
> );
> pCOM0 = [0 5 5]';
> lb = [0*ones(3,1)]; ub =
> [5*ones(3,1)]; [popt, Jopt,
> exitflag,output,labda,grad,hessian] = fmincon( @(p)obj(p), pCOM0,[],
> [], [], [], lb, ub, @(p)ctr(p), optNLP)
>
> %ctr.m
> function [c,ceq] = ctr(p)
> ceq=sum(p)-8;
> c=[];
> end
>
> %obj.m
> function Y = obj(p)
> Y = -p(1).^2-p(2).^2-p(3).^2+75;
> end

You are finding a maximum, not a minimum, with your objective function.
That is the result when you take -sum(p.^2) as the objective instead of
sum(p.^2). See
http://www.mathworks.com/help/optim/ug/writing-objective-functions.html#brhkghv-5

Also, your options settings are not very good. In particular, setting
TolCon to 1e-20 is the same as setting it to zero, which can cause
problems for fmincon. And setting DiffMinChange to 1e-15 makes no sense
at all, leave it at the default value, and use centered finite
differences if you want more accuracy (set FinDiffType to 'centered'). See
http://www.mathworks.com/help/optim/ug/tolerances-and-stopping-criteria.html

Good luck,

Alan Weiss
MATLAB mathematical toolbox documentation

Subject: fmincon initial point problem

From: Matt J

Date: 18 Mar, 2013 16:01:20

Message: 3 of 5

"Haemish " <haemish@hanmail.net> wrote in message <ki774a$5vk$1@newscl01ah.mathworks.com>...
>
> That is finding x^2+y^2+z^2+75 when lb=[0 0 0] and ub=[5 5 5]
> with constraint of x+y+z=8
>[snip]
> I think that this is convex quadratic problem but fmincon minimization answer should be found uniquely.
=============

As a side note, you should probably be using QUADPROG for this, as opposed to FMINCON.

Subject: fmincon initial point problem

From: Haemish

Date: 19 Mar, 2013 02:19:06

Message: 4 of 5

I have got it and sorry for my mistake.

That is finding x^2+y^2+z^2+75 is not the object and -x^2-y^2-z^2+75 is the object as in the code.

Thus the object function is concave and fmincon cannot find a global minimum in the case of concave and minimization is deeply influenced byt the initial point. Is that right?

Sincerely yours, thank you.
----------------------------------------------------------------------
Alan_Weiss <aweiss@mathworks.com> wrote in message <ki79nf$f5q$1@newscl01ah.mathworks.com>...
> On 3/18/2013 10:08 AM, Haemish wrote:
> > Dear sir,
> >
> > I have some questions on fmincon initial value problem.
> >
> > The code belows are very simple one which find the minimum value.
> >
> > That is finding x^2+y^2+z^2+75 when lb=[0 0 0] and ub=[5 5 5]
> > with constraint of x+y+z=8
> >
> > I think that even such a simple problem depends on the initial value
> > strongly.
> >
> > Initial point [0 0 0] gives the answer [2.667 2.667 2.667] but initial
> > point [0 1 1] gives the answer [0 4 4]. However I know that the answer
> > is [0 3 5] (irrespective the [x y z] sequence).
> >
> > I think that this is convex quadratic problem but fmincon minimization
> > answer should be found uniquely.
> > Are there any problems on my probelm definition? And are there any
> > tips to overcome fmincon initial value problem except for random
> > initial value startings?
> >
> > Sincerely yours
> >
> > Thank you.
> >
> > ----------------------------- code
> > ----------------------------------------
> > %main.m
> > optNLP = optimset( 'UseParallel','always','Algorithm',
> > 'active-set','Display','iter-detailed','TolX',1e-10,'TolFun',1e-15,'TolCon',1e-20,'MaxFunEval',10000,'MaxIter',1000000,'DiffMinChange',1e-15
> > );
> > pCOM0 = [0 5 5]';
> > lb = [0*ones(3,1)]; ub =
> > [5*ones(3,1)]; [popt, Jopt,
> > exitflag,output,labda,grad,hessian] = fmincon( @(p)obj(p), pCOM0,[],
> > [], [], [], lb, ub, @(p)ctr(p), optNLP)
> >
> > %ctr.m
> > function [c,ceq] = ctr(p)
> > ceq=sum(p)-8;
> > c=[];
> > end
> >
> > %obj.m
> > function Y = obj(p)
> > Y = -p(1).^2-p(2).^2-p(3).^2+75;
> > end
>
> You are finding a maximum, not a minimum, with your objective function.
> That is the result when you take -sum(p.^2) as the objective instead of
> sum(p.^2). See
> http://www.mathworks.com/help/optim/ug/writing-objective-functions.html#brhkghv-5
>
> Also, your options settings are not very good. In particular, setting
> TolCon to 1e-20 is the same as setting it to zero, which can cause
> problems for fmincon. And setting DiffMinChange to 1e-15 makes no sense
> at all, leave it at the default value, and use centered finite
> differences if you want more accuracy (set FinDiffType to 'centered'). See
> http://www.mathworks.com/help/optim/ug/tolerances-and-stopping-criteria.html
>
> Good luck,
>
> Alan Weiss
> MATLAB mathematical toolbox documentation

Subject: fmincon initial point problem

From: Alan_Weiss

Date: 19 Mar, 2013 12:09:17

Message: 5 of 5

On 3/18/2013 10:19 PM, Haemish wrote:
> I have got it and sorry for my mistake.
>
> That is finding x^2+y^2+z^2+75 is not the object and -x^2-y^2-z^2+75
> is the object as in the code.
> Thus the object function is concave and fmincon cannot find a global
> minimum in the case of concave and minimization is deeply influenced
> byt the initial point. Is that right?
>
> Sincerely yours, thank you.
> ----------------------------------------------------------------------
> Alan_Weiss <aweiss@mathworks.com> wrote in message
> <ki79nf$f5q$1@newscl01ah.mathworks.com>...
>> On 3/18/2013 10:08 AM, Haemish wrote:
>> > Dear sir,
>> >
>> > I have some questions on fmincon initial value problem.
>> >
>> > The code belows are very simple one which find the minimum value.
>> >
>> > That is finding x^2+y^2+z^2+75 when lb=[0 0 0] and ub=[5 5 5]
>> > with constraint of x+y+z=8
>> >
>> > I think that even such a simple problem depends on the initial
>> value > strongly.
>> >
>> > Initial point [0 0 0] gives the answer [2.667 2.667 2.667] but
>> initial > point [0 1 1] gives the answer [0 4 4]. However I know that
>> the answer > is [0 3 5] (irrespective the [x y z] sequence).
>> >
>> > I think that this is convex quadratic problem but fmincon
>> minimization > answer should be found uniquely.
>> > Are there any problems on my probelm definition? And are there any
>> > tips to overcome fmincon initial value problem except for random >
>> initial value startings?
>> >
>> > Sincerely yours
>> >
>> > Thank you.
>> >
>> > ----------------------------- code >
>> ----------------------------------------
>> > %main.m
>> > optNLP = optimset( 'UseParallel','always','Algorithm', >
>> 'active-set','Display','iter-detailed','TolX',1e-10,'TolFun',1e-15,'TolCon',1e-20,'MaxFunEval',10000,'MaxIter',1000000,'DiffMinChange',1e-15
>> > );
>> > pCOM0 = [0 5 5]';
>> > lb = [0*ones(3,1)]; ub = > [5*ones(3,1)]; [popt, Jopt, >
>> exitflag,output,labda,grad,hessian] = fmincon( @(p)obj(p), pCOM0,[],
>> > [], [], [], lb, ub, @(p)ctr(p), optNLP)
>> >
>> > %ctr.m
>> > function [c,ceq] = ctr(p)
>> > ceq=sum(p)-8;
>> > c=[];
>> > end
>> >
>> > %obj.m
>> > function Y = obj(p)
>> > Y = -p(1).^2-p(2).^2-p(3).^2+75;
>> > end
>>
>> You are finding a maximum, not a minimum, with your objective
>> function. That is the result when you take -sum(p.^2) as the
>> objective instead of sum(p.^2). See
>> http://www.mathworks.com/help/optim/ug/writing-objective-functions.html#brhkghv-5
>>
>>
>> Also, your options settings are not very good. In particular, setting
>> TolCon to 1e-20 is the same as setting it to zero, which can cause
>> problems for fmincon. And setting DiffMinChange to 1e-15 makes no
>> sense at all, leave it at the default value, and use centered finite
>> differences if you want more accuracy (set FinDiffType to
>> 'centered'). See
>> http://www.mathworks.com/help/optim/ug/tolerances-and-stopping-criteria.html
>>
>>
>> Good luck,
>>
>> Alan Weiss
>> MATLAB mathematical toolbox documentation

Yes, concave objective functions lead to solutions that depend on the
initial value. See, for example,
http://www.mathworks.com/help/optim/ug/when-the-solver-succeeds.html#brhkghv-65

Alan Weiss
MATLAB mathematical toolbox documentation

Tags for this Thread

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.

Contact us