How to write Fmincon when I have two "to be optimized variables"?
    3 views (last 30 days)
  
       Show older comments
    
I have two variables which I'm going to use Fmincon to optimize. Both of the variables are changing with time. I write Fmincon as below:
% Simulation time
Time = 0:0.005:25; 
% Initial Guess for the control input at every time interval
TopS_FL0 = 0.2 .* ones(length(Time),1);
TopS_RL0 = 0.2 .* ones(length(Time),1);
% Bounds for control input at every time interval
TopS_FL_L = 0 .* ones(length(Time),1);
TopS_FL_U = 1 .* ones(length(Time),1);
TopS_RL_L = 0 .* ones(length(Time),1);
TopS_RL_U = 1 .* ones(length(Time),1);
[ Topt1, Topt2 ] = fmincon( @( Top_FL, Top_RL )obj( other parameters_1, Top_FL, Top_RL), [TopS_FL0, TopS_RL0], [], [], [], [], [TopS_FL_L, TopS_RL_L],[TopS_FL_U, TopS_RL_U],...
@( Top_FL, Top_RL )ctr( other parameters_2, Top_FL, Top_RL ), optNLP);
When I run my code, it always shows that:
Not enough input arguments.
Error in fmincon (line 534)
      initVals.f = feval(funfcn{3},X,varargin{:});
Caused by:
    Failure in initial user-supplied objective function evaluation. FMINCON cannot continue.
Can anyone give me some help? Thank you very much.
0 Comments
Accepted Answer
  Alan Weiss
    
      
 on 30 Mar 2015
        As the documentation clearly states, fmincon expects your objective function to accept a vector of input variables, and output a scalar. So you need to do something like
 fun = @(x)obj(x,other_parameters)
where fun is something like
 function y = obj(x,other_parameters)
 Top_FL = x(1);
 Top_RL = x(2)
 ...
Alan Weiss
MATLAB mathematical toolbox documentation
5 Comments
  Walter Roberson
      
      
 on 4 Jan 2018
				Example:
A = [1 1 -2 0 0 0;
     0 0  0 0 1 -1]
b = [0;
     0]
to express Weights(1) + Weights(2) <= 2 * Weights(3) & Nrates(2) <= Nrates(3)
More Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


