How to correct the code?

2 Ansichten (letzte 30 Tage)
ANCY S GEORGE
ANCY S GEORGE am 9 Mai 2022
Bearbeitet: ANCY S GEORGE am 14 Jun. 2022
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.

Akzeptierte Antwort

Sam Chak
Sam Chak am 9 Mai 2022
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
  1 Kommentar
ANCY S GEORGE
ANCY S GEORGE am 9 Mai 2022
Bearbeitet: ANCY S GEORGE am 13 Mai 2022
Thank you sir for your valuable efforts.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Nonlinear Optimization finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by