필터 지우기
필터 지우기

How to correct my code?

조회 수: 1 (최근 30일)
ANCY S GEORGE
ANCY S GEORGE 2022년 3월 31일
편집: ANCY S GEORGE 2022년 6월 14일
In my problem there are 7 number of peoples and each one have different salary.Based on a condition they are divide as lenders,borrowers and common.I have to find out the optimal expenditure of each people.Based on this solution they have to find the cost.Based on this updated cost,the expenditure of each people have to be updated.This is a iterative compution, it stops only when the error converges nearly to zero
k=1;
a1=3;b1=8;
a(k)=a1;b(k)=b1;
G=[50 100 150 175 200 250 300];
Gbar=mean(G);
H=[20 15 10 5 1 0.5 0.1];
itmax=5;
x=[];
y=[];
z=[];
for k=1:itmax
for i=1:length(G)
if G(i)>Gbar
x=[x i];
elseif G(i)<Gbar
y=[y i];
else
z=[z i];
end
end
A=(H(x)/a(k))-1;
A=(H(y)/b(k))-1;
A=G(z);
if s>r
a(k+1)=sqrt((sum(a1.*H(:,x)))/(p1));
if (a1>=a(:,k+1)) && (a(:,k+1)>=b1)
a(k+1)=a1+(s/beta1);
else
end
this problem end when following condition satisfied
if(a(k+1)-a(k)<=0.01)&&(b(k+1)-b(k)<=0.01)&&(A(k+1)-A(k)<=0.01)
end
end
But I didn't get the correct output.This doesn't undergo iteration.
I have to get the updated cost price of each people on each iteration.
Also updated value of expenditure of each people.My error is I get the second iterative value of expenditure of first man is the first expenditure value of second man.How to correct this code?
  댓글 수: 1
Jan
Jan 2022년 3월 31일
"updated value of expenditure of each people"
"value of expenditure of first man is the first expenditure value of second man"
Prefer to use the names of the variables in the description. What is "people", "man", "expenditure"?

댓글을 달려면 로그인하십시오.

채택된 답변

Jan
Jan 2022년 3월 31일
I did not understand, what you are asking for (see my comment). but this piece of the code looks suspicious:
A=(H(x)/a(k))-1; % lenders expenditure
A=(H(y)/b(k))-1; % borrowers expenditure
A=G(z); % common expenditure
You are overwriting the value of A twice. If this value matters, overwriting should be a problem. If it does not matter, why do you calculate it?

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Optimization에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by