Conversion to double from function_handle is not possible.
1 回表示 (過去 30 日間)
古いコメントを表示
I'm trying to solve an economic dispatch problem using the fmincon function, but i'm getting many different errors in the function inside the loop. Can you please help me run this code without errors? This is my first time using fmincon.
Nc = 3;
a = [ 0.06 0.03 0.04];
b = [ 0.5 0.25 0.3];
c = [ 5 4 2 ];
p0 = [2 4 7 ];
objective = zeros(1,3);
for i = 1:Nc
objective(i) = @(p) a(i)^2 * p(i)^2 + b(i) * p(i) + c(i);
end
pd = 550;
A = [];
b = [];
Aeq = [ p(1) p(2) p(3)];
beq = [ pd ];
lb = [ 0 0 0 ];
ub = [ 4 6 9 ];
% disp([' Initial Objectives: ' num2str(objective(p0))])
cc = fmincon(objective(i), p0, A , b , Aeq, beq, lb, ub);
disp(cc)
0 件のコメント
回答 (1 件)
Jan
2021 年 10 月 17 日
objective = zeros(1,3); % Here objective is a double
for i = 1:Nc
% And here you want to store a function handle in the double elements:
objective(i) = @(p) a(i)^2 * p(i)^2 + b(i) * p(i) + c(i);
end
This cannot work.
Try this instead:
objective = @(p) a.^2 .* p.^2 + b .* p + c;
1 件のコメント
参考
カテゴリ
Help Center および File Exchange で Get Started with Optimization Toolbox についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!