How to write Fmincon when I have two "to be optimized variables"?

1 次查看(过去 30 天)
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.

采纳的回答

Alan Weiss
Alan Weiss 2015-3-30
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 个评论
Walter Roberson
Walter Roberson 2018-1-4
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)

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Solver Outputs and Iterative Display 的更多信息

标签

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by