Info

This question is closed. Reopen it to edit or answer.

The following code works perfectly, when I omit while loop. However I get infinite loop when 'while' loop included. My goal is obtaining 4x1 matrix for GF1, whose values shall be within 5% of number 1

1 view (last 30 days)
T=[0 20 30 15; 20 0 10 40; 30 10 0 35; 15 40 35 0];
G = [130 140 225 90]';
GF1= G./sum(T,2);
while max([abs(GF1-1)]) > 0.05 % iteration process for growth factor to be within +/- 5% of 1
for a=1:4
x(a,:)=T(a,:)*GF1; %denominator
y(a,:)=T(a,:)*GF1(a)*Rowsum(a);
end
X1=repmat(x,1,4);
z=repmat(GF1',4,1);
y1=y.*z;
V=y1./X1;
K=zeros(4);
for m=1:4;
for n= 1:4;
K(m,n) = (V(m,n)+ V(n,m))*.5;
end
end
T = K;
GF1= G./sum(T,2)
end
  1 Comment
Walter Roberson
Walter Roberson on 3 Oct 2015
Note: your section of code
K=zeros(4);
for m=1:4;
for n= 1:4;
K(m,n) = (V(m,n)+ V(n,m))*.5;
end
end
T = K;
could be written as
T = (V + V')/2;

Answers (0)

Community Treasure Hunt

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

Start Hunting!