How to correct my code?
    5 ビュー (過去 30 日間)
  
       古いコメントを表示
    
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
      
      
 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
      
      
 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 件のコメント
その他の回答 (0 件)
参考
カテゴリ
				Help Center および File Exchange で Text Files についてさらに検索
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

