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.
댓글 수: 0
채택된 답변
Sam Chak
2022년 5월 9일
Hi @susan sara
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 Center 및 File Exchange에서 Feature Detection and Extraction에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!