Error in Fmincon fuction

์กฐํšŒ ์ˆ˜: 5 (์ตœ๊ทผ 30์ผ)
Kunal Jain
Kunal Jain 2022๋…„ 2์›” 20์ผ
ํŽธ์ง‘: Torsten 2022๋…„ 2์›” 20์ผ
Example I am solving
Find the optimal state and optimal control based on minimizing the performance index ๐ฝ=โˆซ (๐‘ฅ(๐‘ก) โˆ’ 1/2 ๐‘ข(๐‘ก)^2 ) ๐‘‘๐‘ก 1 0 , 0 โ‰ค ๐‘ก โ‰ค 1 subject to ๐‘ข(๐‘ก) = ๐‘ฅฬ‡(๐‘ก) + ๐‘ฅ(๐‘ก) with the condition ๐‘ฅ(0) = 0, ๐‘ฅ(1) = 1/2 (1 โˆ’ 1/๐‘’ )^2 where ๐ฝ๐‘’๐‘ฅ๐‘Ž๐‘๐‘ก = 0.08404562020 In this example the initial approximation is ๐‘ฅ1 (๐‘ก) = 1/2 (1 โˆ’ 1/e )^2
ERROR:
On running solve_system_of_equations , I am getting error as :
Error using system_of_equations
Too many output arguments.
Error in fmincon (line 655)
[ctmp,ceqtmp] = feval(confcn{3},X,varargin{:});
Error in solve_system_of_equations (line 44)
x = fmincon(fun,x0,A,bb,Aeq,beq,lb,ub,nonlcon)
Caused by:
Failure in initial nonlinear constraint function evaluation. FMINCON cannot continue.
CODE:
function F = cost_function(x)
global def;
global m;
s=def.k ;
C2=x(1,(s+1):2*s);
u=(C2*m.H) ;
F=(1/2)*u*u';
function F = system_of_equations(x)
global def;
global m;
global init;
global P_alpha_1;
s=def.k ;
C1=x(1,1:s);
C2=x(1,(s+1):2*s);
x1=(C1*P_alpha_1*m.H) + init(1);
u=(C2*m.H) ;
D_alpha1_x1= C1*m.H;
%
M=Haar_matrix(s);
HC=M(:,s);
%%control law1
F = horzcat( D_alpha1_x1 + x1 - u , ...
(C1*P_alpha_1*HC) + init(1) - (1/2*((1-exp(-1))^2))) ;
end
alpha_1=1;
k=8; %no. of Haar wavelets
b=2; %Total number of days to plot
initialize(alpha_1,k,b )
global m;
global init;
global def;
global P_alpha_1;
global P_alpha_2;
P_alpha_1=fractional_operation_matrix(k,alpha_1,b,m.H);
s=def.k;
x0=zeros(3,3*s);
% system_of_equations(x)
A = [];
bb = [];
Aeq = [];
beq = [];
lb = [];
ub = [];
fun = @cost_function;
nonlcon=@system_of_equations;
x = fmincon(fun,x0,A,bb,Aeq,beq,lb,ub,nonlcon)

๋‹ต๋ณ€ (1๊ฐœ)

Walter Roberson
Walter Roberson 2022๋…„ 2์›” 20์ผ
function F = system_of_equations(x)
That function only returns one output.
nonlcon=@system_of_equations;
For fmincon, the nonlinear constraints function must return 2 outputs (and with some options, it would have to return four outputs.)
The first output is for the nonlinear inequality constraints. The second output is for the nonlinear equality constraints. If you do not have any nonlinear equality constraints, you must return the empty array, [] for the second output.
  ๋Œ“๊ธ€ ์ˆ˜: 2
Kunal Jain
Kunal Jain 2022๋…„ 2์›” 20์ผ
Thank you for answering my question
In this using x=ones(1,16)
function F = system_of_equations(x)
Result is
F =
0.6768 1.5303 2.0303 2.1768 2.4268 2.7803 2.7803 2.4268 2.2270
But after running solve_system_of_equations I am geting the same above Fmincon error
Can you please explain a bit more what u explained about the the outputs of fmincon more?
Thanks in advance
Torsten
Torsten 2022๋…„ 2์›” 20์ผ
ํŽธ์ง‘: Torsten 2022๋…„ 2์›” 20์ผ
The function "system_of_equations" must return two output arguments. You only return one argument, namely F.
Thus the function must read
function [c,ceq] = system_of_equations(x)
c = ...;
ceq = ...;
end
For the meaning of c and ceq, please refer to the documentation of fmincon, especially for the function in which the nonlinear inequality and equality constraints are defined (usually named "nonlcon").

๋Œ“๊ธ€์„ ๋‹ฌ๋ ค๋ฉด ๋กœ๊ทธ์ธํ•˜์‹ญ์‹œ์˜ค.

์นดํ…Œ๊ณ ๋ฆฌ

Help Center ๋ฐ File Exchange์—์„œ Nonlinear Optimization์— ๋Œ€ํ•ด ์ž์„ธํžˆ ์•Œ์•„๋ณด๊ธฐ

ํƒœ๊ทธ

Community Treasure Hunt

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

Start Hunting!

Translated by