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:
Optimization with fmincon.

Subject: Optimization with fmincon.

From: Thomas Trampedach

Date: 28 Jun, 2004 13:26:36

Message: 1 of 6

I am a Mathlab beginner and perhaps to optimistic about the prospect
off succeeding to solve my problem.

I have to optimize a nonlinear function with 6 unknown variables and
3 nonlinear constraints. I try using fmincon, but with moderate
success.

I run in to problems with singularity off the matrices witch
determines the object function or/and receives a warning like

Warning: One or more output arguments not assigned during call to
'feval'.
> In C:\MATLAB6p1\toolbox\optim\private\nlconst.m at line 269
  In C:\MATLAB6p1\toolbox\optim\fmincon.m at line 458
  In C:\MATLAB6p1\work\mimimumfile.m at line 88

Is there a better tool/function then fmincon?

I hope some one can help.

Best regards

Thomas

Subject: Optimization with fmincon.

From: pk

Date: 28 Jun, 2004 13:43:16

Message: 2 of 6

fincon should solve yr prob.... post the function and constarints
here
pk

Thomas Trampedach wrote:
>
>
> I am a Mathlab beginner and perhaps to optimistic about the
> prospect
> off succeeding to solve my problem.
>
> I have to optimize a nonlinear function with 6 unknown variables
> and
> 3 nonlinear constraints. I try using fmincon, but with moderate
> success.
>
> I run in to problems with singularity off the matrices witch
> determines the object function or/and receives a warning like
>
> Warning: One or more output arguments not assigned during call to
> 'feval'.
>> In C:\MATLAB6p1\toolbox\optim\private\nlconst.m at line 269
> In C:\MATLAB6p1\toolbox\optim\fmincon.m at line 458
> In C:\MATLAB6p1\work\mimimumfile.m at line 88
>
> Is there a better tool/function then fmincon?
>
> I hope some one can help.
>
> Best regards
>
> Thomas

Subject: Optimization with fmincon.

From: Steven Lord

Date: 28 Jun, 2004 13:44:44

Message: 3 of 6


"Thomas Trampedach" <ttrampedach@hotmail.com> wrote in message
news:eee167f.-1@webx.raydaftYaTP...
> I am a Mathlab beginner and perhaps to optimistic about the prospect
> off succeeding to solve my problem.
>
> I have to optimize a nonlinear function with 6 unknown variables and
> 3 nonlinear constraints. I try using fmincon, but with moderate
> success.
>
> I run in to problems with singularity off the matrices witch
> determines the object function or/and receives a warning like
>
> Warning: One or more output arguments not assigned during call to
> 'feval'.
> > In C:\MATLAB6p1\toolbox\optim\private\nlconst.m at line 269
> In C:\MATLAB6p1\toolbox\optim\fmincon.m at line 458
> In C:\MATLAB6p1\work\mimimumfile.m at line 88

That indicates that your objective function specifies that it has an output
argument, but that you don't assign anything to that output argument before
the objective function finishes execution. For instance, this function
would give that output:

function y = myfun(x)
disp(x)

Note I specify this function should return y, but I never define y in the
function. This would also trigger the warning you saw.

Try initializing the output variable as the very first command in your
objective function and try to run this problem again. If this causes the
warning to disappear, one or more of the paths through your objective
function fail to initialize it to a value.

> Is there a better tool/function then fmincon?

No, FMINCON is the appropriate Optimization Toolbox function to use for a
problem of the form you described.

--
Steve Lord
slord@mathworks.com

Subject: Optimization with fmincon.

From: Thomas Trampedach

Date: 28 Jun, 2004 14:25:23

Message: 4 of 6

pk wrote:
>
>
> fincon should solve yr prob.... post the function and constarints
> here
> pk
>
> Thomas Trampedach wrote:
>>
>>
>> I am a Mathlab beginner and perhaps to optimistic about the
>> prospect
>> off succeeding to solve my problem.
>>
>> I have to optimize a nonlinear function with 6 unknown
variables
>> and
>> 3 nonlinear constraints. I try using fmincon, but with moderate
>> success.
>>
>> I run in to problems with singularity off the matrices witch
>> determines the object function or/and receives a warning like
>>
>> Warning: One or more output arguments not assigned during call
to
>> 'feval'.
>>> In C:\MATLAB6p1\toolbox\optim\private\nlconst.m at line 269
>> In C:\MATLAB6p1\toolbox\optim\fmincon.m at line 458
>> In C:\MATLAB6p1\work\mimimumfile.m at line 88
>>
>> Is there a better tool/function then fmincon?
>>
>> I hope some one can help.
>>
>> Best regards
>>
>> Thomas

I have send the files to you email
Best regards
Thomas

Subject: Optimization with fmincon.

From: Thomas Trampedach

Date: 28 Jun, 2004 15:45:45

Message: 5 of 6

Thomas Trampedach wrote:
>
>
> pk wrote:
>>
>>
>> fincon should solve yr prob.... post the function and
constarints
>> here
>> pk
>>
>> Thomas Trampedach wrote:
>>>
>>>
>>> I am a Mathlab beginner and perhaps to optimistic about the
>>> prospect
>>> off succeeding to solve my problem.
>>>
>>> I have to optimize a nonlinear function with 6 unknown
> variables
>>> and
>>> 3 nonlinear constraints. I try using fmincon, but with
> moderate
>>> success.
>>>
>>> I run in to problems with singularity off the matrices
witch
>>> determines the object function or/and receives a warning
like
>>>
>>> Warning: One or more output arguments not assigned during
> call
> to
>>> 'feval'.
>>>> In C:\MATLAB6p1\toolbox\optim\private\nlconst.m at line
> 269
>>> In C:\MATLAB6p1\toolbox\optim\fmincon.m at line 458
>>> In C:\MATLAB6p1\work\mimimumfile.m at line 88
>>>
>>> Is there a better tool/function then fmincon?
>>>
>>> I hope some one can help.
>>>
>>> Best regards
>>>
>>> Thomas
>
> I have send the files to you email
> Best regards
> Thomas

Here is the function, constraint and the way I use fmincon.

I probably don't use Mathlab in a efficient way, so it is not easy to
read. sorry.
Thomas

I hope some one can help.

% ===== fmincon ==========

1. fmincon function

[x,fval,exitflag,output] =fmincon(@objective_function, [57, 35, 3.5,
205, 47, 0.1], [], [], [], [], [45 30 3 190 30 0.1], [60 40 4 210 55
0.2],[@constraints],optimset('Tolx',1e-3,'TolFun',1e-3,'MaxIter',100,'
MaxFunEvals',7000,'Tolcon',1e-3,'Display','iter'))

2. objective function

function v = objective_function(x);
% =============================== Input parameters
=================================

alpha=0.25;
delta=0.05;
lambda=0.1;
tau=0.2;
r=0.06;
k1=0.01;
k2=0.005;
k3=k1;
sigmaL=0.2;
sigmaH=0.3;

% =============================== Itteration values
===================================
V=100;
V0=V;
C=(69*10^(-4)+0.06)*108.6*0.494; %C=3.5;

% =============================== test values
========================

%x=[P VB C VU VS m]
%x = [(108.6*0.494) 33.6 (69*10^(-4)+0.06)*108.6*0.494 201 44.7 0.1]
%x(4)= 201;
%x(5)=44.7;
%x(6)=0.1;

% =============================== Calculated constants
=================================
rho=x(4)/V0;
VT=x(3)/lambda;
m=0.1;
x1L=(-(r-delta-0.5*sigmaL^2)+sqrt((r-delta-0.5*sigmaL^2)^2+2*sigmaL^2*
r))/(sigmaL^2);
x2L=(-(r-delta-0.5*sigmaL^2)-sqrt((r-delta-0.5*sigmaL^2)^2+2*sigmaL^2*
r))/(sigmaL^2);
x1H=(-(r-delta-0.5*sigmaH^2)+sqrt((r-delta-0.5*sigmaH^2)^2+2*sigmaH^2*
r))/(sigmaH^2);
x2H=(-(r-delta-0.5*sigmaH^2)-sqrt((r-delta-0.5*sigmaH^2)^2+2*sigmaH^2*
r))/(sigmaH^2);

y1L=(-(r-delta-0.5*sigmaL^2)+sqrt((r-delta-0.5*sigmaL^2)^2+2*sigmaL^2*
(r+x(6))))/(sigmaL^2);
y2L=(-(r-delta-0.5*sigmaL^2)-sqrt((r-delta-0.5*sigmaL^2)^2+2*sigmaL^2*
(r+x(6))))/(sigmaL^2);
y1H=(-(r-delta-0.5*sigmaH^2)+sqrt((r-delta-0.5*sigmaH^2)^2+2*sigmaH^2*
(r+x(6))))/(sigmaH^2);
y2H=(-(r-delta-0.5*sigmaH^2)-sqrt((r-delta-0.5*sigmaH^2)^2+2*sigmaH^2*
(r+x(6))))/(sigmaH^2);

% ==== vectors =======

 Omegadebt = 1e1*......
              [x(5)^y1L x(5)^y2L
-x(5)^y1H -x(5)^y2H;
              y1L*x(5)^(y1L-1) y2L*x(5)^(y2L-1)
-y1H*x(5)^(y1H-1) -y2H*x(5)^(y2H-1);
              x(4)^y1L x(4)^y2L 0
                    0;
              0 0
x(2)^y1H x(2)^y2H];
 mudebt = 1e1*........
              [0; 0;
x(1)-(x(3)+x(6)*x(1))/(r+x(6));
(1-alpha)*x(2)-(x(3)+x(6)*x(1))/(r+x(6))];
 a = inv(Omegadebt)*mudebt;

 Omegatb = 1*....
              [(x(4)^x1L-rho*V0^x1L) x(4)^x2L-rho*V0^x2L 0
              0 0 0;
              0 0 0
            0 x(2)^x1H x(2)^x2H;
              x1L*x(5)^(x1L-1) x2L*x(5)^(x2L-1)
-x1H*x(5)^(x1H-1) -x2H*x(5)^(x2H-1) 0 0;
              x(5)^x1L x(5)^x2L
-x(5)^x1H -x(5)^x2H 0 0;
              0 0
x1H*VT^(x1H-1) x2H*VT^(x2H-1) -x1H*VT^(x1H-1)
-x2H*VT^(x2H-1);
              0 0 VT^x1H
            VT^x2H -VT^x1H -VT^x2H];
 mutb = 1*........
             [(rho-1)*tau*x(3)/r; -tau*lambda*x(2)/delta; 0;
              0; tau*lambda/delta;
tau*x(3)/delta-tau*x(3)/r];
 b = inv(Omegatb)*mutb;

 Omegabc = 1*.....
            [(x(4)^x1L-rho*V0^x1L) x(4)^x2L-rho*V0^x2L 0
              0;
            0 0 x(2)^x1H
             x(2)^x2H;
            x1L*x(5)^(x1L-1) x2L*x(5)^(x2L-1)
-x1H*x(5)^(x1H-1) -x2H*x(5)^(x2H-1);
            x(5)^x1L x(5)^x2L
-x(5)^x1H -x(5)^x2H];
 mubc = 1*......
           [0; alpha*x(2); 0;
              0];
 c = inv(Omegabc)*mubc;

 Omegatc = 1e-4*........
            [(x(4)^x1L-rho*V0^x1L) (x(4)^x2L-rho*V0^x2L) 0
              0;
            0 0 x(2)^x1H
              x(2)^x2H;
            x1L*x(5)^(x1L-1) x2L*x(5)^(x2L-1)
-x1H*x(5)^(x1H-1) -x2H*x(5)^(x2H-1);
            x(5)^x1L x(5)^x2L
-x(5)^x1H -x(5)^x2H];
 mutc = 1e-4*.....
            [(rho-1)*k2*x(6)*x(1)/r + rho*k1*x(1); -k2*x(6)*x(1)/r;
0; 0];
 d = inv(Omegatc)*mutc;

% ===================== determines elements of the objective function
==============

% ==================== TB ====================================
        
             TB = tau*x(3)/r+b(1)*V^x1L + b(2)*V^x2L;
 
% ==================== BC ====================================

             BC = c(1)*V^x1L + c(2)*V^x2L;
       
% ==================== TC ====================================
  

             TC = k3*x(1)+k2*x(6)*x(1)/r+d(1)*V^x1L+d(2)*V^x2L;
 
% ==================== Objective function ==================

v = -1*(V + TB - BC - TC)

[-v; x(1); x(2); x(5); x(4); x(3); -x(1)/v*100; (x(3)/x(1)-r)*10000];

3. constraints

function [c,ceq] = constraints(x);

% =============================== Input parameters - the samme as in
the objective function =================================
alpha=0.25;
delta=0.05;
lambda=0.1;
tau=0.2;
r=0.06;
k1=0.01;
k2=0.005;
sigmaL=0.2;
sigmaH=0.3;
%m=0.1;

% =============================== Itteration values
===================================
V=100;
V0=V;

%x(4)= 201;
%x(5)=44.7;
x(6)=0.1;

% =============================== Calculated constants
=================================
rho=x(4)/V0;
VT=x(3)/lambda;

x1L=(-(r-delta-0.5*sigmaL^2)+sqrt((r-delta-0.5*sigmaL^2)^2+2*sigmaL^2*
r))/(sigmaL^2);
x2L=(-(r-delta-0.5*sigmaL^2)-sqrt((r-delta-0.5*sigmaL^2)^2+2*sigmaL^2*
r))/(sigmaL^2);
x1H=(-(r-delta-0.5*sigmaH^2)+sqrt((r-delta-0.5*sigmaH^2)^2+2*sigmaH^2*
r))/(sigmaH^2);
x2H=(-(r-delta-0.5*sigmaH^2)-sqrt((r-delta-0.5*sigmaH^2)^2+2*sigmaH^2*
r))/(sigmaH^2);

y1L=(-(r-delta-0.5*sigmaL^2)+sqrt((r-delta-0.5*sigmaL^2)^2+2*sigmaL^2*
(r+x(6))))/(sigmaL^2);
y2L=(-(r-delta-0.5*sigmaL^2)-sqrt((r-delta-0.5*sigmaL^2)^2+2*sigmaL^2*
(r+x(6))))/(sigmaL^2);
y1H=(-(r-delta-0.5*sigmaH^2)+sqrt((r-delta-0.5*sigmaH^2)^2+2*sigmaH^2*
(r+x(6))))/(sigmaH^2);
y2H=(-(r-delta-0.5*sigmaH^2)-sqrt((r-delta-0.5*sigmaH^2)^2+2*sigmaH^2*
(r+x(6))))/(sigmaH^2);
  

% =================== test af bestemmelse af hovedstolen
=====================
     
     Omegadebt = [x(5)^y1L x(5)^y2L
-x(5)^y1H -x(5)^y2H;
                  y1L*x(5)^(y1L-1) y2L*x(5)^(y2L-1)
-y1H*x(5)^(y1H-1) -y2H*x(5)^(y2H-1);
                  x(4)^y1L x(4)^y2L 0
                        0;
                  0 0
x(2)^y1H x(2)^y2H];
     mudebt = [0; 0;
x(1)-(x(3)+x(6)*x(1))/(r+x(6));
(1-alpha)*x(2)-(x(3)+x(6)*x(1))/(r+x(6))];
     adebt = inv(Omegadebt)*mudebt;

     
     Omegatb = [(x(4)^x1L-rho*V0^x1L) x(4)^x2L-rho*V0^x2L 0
                 0 0 0;
                  0 0 0
                0 x(2)^x1H x(2)^x2H;
                  x1L*x(5)^(x1L-1) x2L*x(5)^(x2L-1)
-x1H*x(5)^(x1H-1) -x2H*x(5)^(x2H-1) 0 0;
                  x(5)^x1L x(5)^x2L
-x(5)^x1H -x(5)^x2H 0 0;
                  0 0
x1H*VT^(x1H-1) x2H*VT^(x2H-1) -x1H*VT^(x1H-1)
-x2H*VT^(x2H-1);
                  0 0
VT^x1H VT^x2H -VT^x1H -VT^x2H];
     mutb = [(rho-1)*tau*x(3)/r; -tau*lambda*x(2)/delta;
0; 0; tau*lambda/delta;
tau*x(3)/delta-tau*x(3)/r];
     btb = inv(Omegatb)*mutb;

     Omegabc = [(x(4)^x1L-rho*V0^x1L) x(4)^x2L-rho*V0^x2L 0
                 0;
                0 0
x(2)^x1H x(2)^x2H;
                x1L*x(5)^(x1L-1) x2L*x(5)^(x2L-1)
-x1H*x(5)^(x1H-1) -x2H*x(5)^(x2H-1);
                x(5)^x1L x(5)^x2L
-x(5)^x1H -x(5)^x2H];
     mubc = [0; alpha*x(2); 0;
                  0];
     cbc = inv(Omegabc)*mubc;

     Omegatc = [(x(4)^x1L-rho*V0^x1L) (x(4)^x2L-rho*V0^x2L) 0
                  0;
                0 0
x(2)^x1H x(2)^x2H;
                x1L*x(5)^(x1L-1) x2L*x(5)^(x2L-1)
-x1H*x(5)^(x1H-1) -x2H*x(5)^(x2H-1);
                x(5)^x1L x(5)^x2L
-x(5)^x1H -x(5)^x2H];
     mutc = [ (rho-1)*k2*x(6)*x(1)/r + rho*k1*x(1); -k2*x(6)*x(1)/r;
 0; 0];
     dtc = inv(Omegatc)*mutc;

% ========= constraints1 ===================
     
     D0 = (x(3)+x(6)*x(1))/(r+x(6))+adebt(1)*V0^y1L+adebt(2)*V0^y2L;

% ========= constraints2 - smoothpasting condition
===================
    
     dtbt = tau*lambda/delta + x1H*btb(5)*x(2)^(x1H-1) +
x2H*btb(6)*x(2)^(x2H-1);
     dbct = x1H*cbc(3)*x(2)^(x1H-1) +
x2H*cbc(4)*x(2)^(x2H-1);
     dtct = x1H*dtc(3)*x(2)^(x1H-1) +
x2H*dtc(4)*x(2)^(x2H-1);
     ddh = y1H*adebt(3)*x(2)^(y1H-1) +
y2H*adebt(4)*x(2)^(y2H-1);

% ========= constraints3 - ET > 0 ===================
           
      TBT = tau*lambda*x(2)/delta + btb(5)*x(2)^x1H +
btb(6)*x(2)^x2H;
      BCT = cbc(3)*x(2)^x1H + cbc(4)*x(2)^x2H;
      TCT = k1*x(1) + k2*x(6)*x(1)/r + dtc(3)*x(2)^x1H +
dtc(4)*x(2)^x2H;
      DH = (x(3) + x(6)*x(1))/(r+x(6)) + adebt(3)*x(2)^y1H +
adebt(4)*x(2)^y2H;

% === constraints =====
      
      ceq = [D0-x(1)
          (1 + dtbt - dbct - dtct - ddh)];

% ====== applying c make the iteration run forever

      c = -1*(x(2) + TBT- BCT - TCT - DH);

Subject: Optimization with fmincon.

From: Marcus M. Edvall

Date: 28 Jun, 2004 20:25:26

Message: 6 of 6

Dear Thomas,

Of course there are better tools than optimization toolbox.

TOMLAB /SNOPT will show you that your problem is infeasible (without
giving weird messages or running forever) in about 0.5 secs.

Should you remove your final c constraint you will solve your problem
in about the same time.

Send me an email for the code.

Best wishes, Marcus
Tomlab Optimization Inc.
 <http://tomlab.biz>

>
>> Is there a better tool/function then fmincon?
>
> No, FMINCON is the appropriate Optimization Toolbox function to use
> for a
> problem of the form you described.
>
> --
> Steve Lord
> slord@mathworks.com
>

Tags for this Thread

No tags are associated with 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