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 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