How to correct the code?

1 回表示 (過去 30 日間)
ANCY S GEORGE
ANCY S GEORGE 2022 年 5 月 9 日
編集済み: ANCY S GEORGE 2022 年 6 月 14 日
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
  1 件のコメント
ANCY S GEORGE
ANCY S GEORGE 2022 年 5 月 9 日
編集済み: ANCY S GEORGE 2022 年 5 月 13 日
Thank you sir for your valuable efforts.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeNonlinear Optimization についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by