How to correct the code?

1 次查看(过去 30 天)
In this code I optimize the objective function using fmincon.But I didnt get the correct output
clc;
clear all;
gr=3;gs=8;
E=[0;1.5;2;3.5;4;4.5;4.5];
l=[3.0;2.5;3.5;3.5;3.2;4.2;4.0];
Xi=[40;40;40;20;20;20;20];
s=3;
r=8 ;
for i=1:1:length(E)
if Em>0
a = [a i];
elseif Em<0
b = [b i];
else
c = [c i];
end
end
x0=zeros(7,1);
lb1=-100;
ub1=100;
for j=a(1):1:a(length(a))
F1=@(A)(-(Xi(j,:).*log(1+A(j,:))+s.*(E(j,:)-A(j,:))));
[A(j,:),fval1(j,:)]=fmincon(F1,x0,[],[],[],[],lb1,ub1)
end
Please help me to correct this.

采纳的回答

Sam Chak
Sam Chak 2022-5-9
Adding these lines should work
n = 1;
h = repmat({true(n)}, 7, 1);
Output = A(logical(blkdiag(h{:})))
Output =
4.0000
4.0000
4.0000
3.5000
5.6667
5.6667
5.6667

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Nonlinear Optimization 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by