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

1 回表示 (過去 30 日間)
Tao
Tao 2015 年 3 月 30 日
コメント済み: Walter Roberson 2018 年 1 月 4 日
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 件のコメント
Yaser Khojah
Yaser Khojah 2018 年 1 月 4 日
Thanks Walter. How would you write the linear constraint in this case?
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 Center および File ExchangeSolver 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