FMINCON requires the following inputs to be of data type double
15 ビュー (過去 30 日間)
古いコメントを表示
I have the following code and I can't understand how to fix the error.
0 件のコメント
採用された回答
Torsten
2022 年 5 月 14 日
Although I don't understand your problem setup because the variables in the objective function are not influenced by your constraint, here is a running code:
%Parameters of the system%
Fk = 10^10;
Bk = 20*10^6;
p = 0.1; %Watts
g0 = 10^(-4);
w0 = -100;
v = 0.2*10^(-11); %J/cycle
C = 8*500; %cycles/bit
fe = 100*10^9; %Hz
fc = 500*10^9; %Hz
s_enc = 240*10^6; %cycles, random number
s_dec = 240*10^6; %cycles, random number
w = 0.5; %decision weight
%Parameters of the system that change%
fl = (0.4:0.1:1)*10^9; %Hz
D = linspace(0,10,100)*10^6; %MB
theta = randi([0,1]);
r = randi([1 length(fl)],1,1); %generate random nuber
fl_temp = fl(r);
q = randi([1 length(D)],1,1); %generate random nuber
D_temp = D(r);
%variables of the system%
w0_watt = 10^(w0/10)/1000;
R = Bk*log2(1+(p*g0^2)/(w0_watt*Bk));
% E_enc = v*s_enc*D_temp*a3;
% t_end_dec = (v*s_enc*D_temp/fc)*a3 + (v*s_dec*D_temp/fe)*a3;
% E_l = v*C*D_temp*a1;
% T_l = (C*D_temp/fl_temp)*a1;
% T_s = (C*D_temp/fe)*a2;
% T_c = (C*D_temp/fc)*a3;
% T_trans = D_temp/R*(a2 + a3);
% E_r = p*T_trans;
% E_sec = theta*(E_enc + E_r) + (1-theta)*E_r;
% T_sec = theta*(t_end_dec + T_trans) + (1-theta)*T_trans;
%
% E = E_l + E_sec;
% T = max([T_l, T_sec + T_s, T_sec + T_c]);
%Soving the problem%
%set initial guess values for the problem variables%
a1 = 1/3;
a2 = 1/3;
a3 = 1/3;
Emax = 1.0;
Tmax = 1.0;
%Load guess values into an array%
x0 = [a1 a2 a3 Emax Tmax];
E_enc = v*s_enc*D_temp*a3;
t_end_dec = (v*s_enc*D_temp/fc)*a3 + (v*s_dec*D_temp/fe)*a3;
E_l = v*C*D_temp*a1;
T_l = (C*D_temp/fl_temp)*a1;
T_s = (C*D_temp/fe)*a2;
T_c = (C*D_temp/fc)*a3;
T_trans = D_temp/R*(a2 + a3);
E_r = p*T_trans;
E_sec = theta*(E_enc + E_r) + (1-theta)*E_r;
T_sec = theta*(t_end_dec + T_trans) + (1-theta)*T_trans;
E = E_l + E_sec;
T = max([T_l, T_sec + T_s, T_sec + T_c]);
%set lower and upper bounds%
lb = [0 0 0 E T];
ub = [1.0 1.0 1.0 1000.0 1000.0];
%call solver to minimize the objective function given the constraints%
% fmincon(fun,x0,A,b,Aeq,beq,lb,ub,nonlcon)%
A = [1 1 1 0 0];
b = 1.0;
Aeq = [];
beq = [];
[x,fval] = fmincon(@(x)objective(x,w),x0,A,b,Aeq,beq,lb,ub)
end
%define objective function for optimization%
function obj = objective(x,w)
Emax = x(4);
Tmax = x(5);
obj = w*Emax + (1-w)*Tmax;
end
9 件のコメント
Torsten
2022 年 5 月 18 日
a1, a2 and a3 are used to calculate quantities before you call fmincon.
This is incorrect. All these calculations have to be done within the objective function.
So you will first have to change this basic problem before looping or further changes to your code.
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Systems of Nonlinear Equations についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!