필터 지우기
필터 지우기

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 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