Weighting based on Eigenvector method

7 views (last 30 days)
Richard
Richard on 21 Mar 2012
i am constructing a simple eigenvector method for a 6 rows X 10 columns matrix.This is main part of the code, the values in PM=[] have been omitted due to the large amount of input numbers
PM=[]
Wt(:,1)=[1;0;0;0;0;0;0;0;0;0];
[len,width]=size(PM);
delta(:,1)=[1 1 1 1 1 1 1 1 1 1]';
trial=18;
for t=2:trial
Wt1(:,t)=PM*Wt(:,t-1);
max_eig=sum(Wt1(:,t));
Wtnorm1(:,t)=Wt1(:,t)./max_eig;
delta(:,t)=abs(Wt(:,t-1)-Wtnorm1(:,t));
if delta(:,t-1)>=1e-6
Wt(:,t)=Wtnorm1(:,t);
else
CI=(max_eig-width)/(width-1);
weight=Wtnorm1;
break
end
end
final_weight=weight(:,length(weight));
unfortunately i cant seem to diagnose this error:
??? Attempted to access weight(:,10); index out of bounds because size(weight)=[10,4].
Error in ==> eigenvector at 31 final_weight=weight(:,length(weight));
i am pretty new to matlab so i am not sure how to read these error messages.thanks alot!
  1 Comment
the cyclist
the cyclist on 21 Mar 2012
Are you able to give a toy example of PM that will exhibit the error behavior, without all the real values? I tried PM = rand(6,10), but that gives an error earlier in the code.

Sign in to comment.

Answers (2)

the cyclist
the cyclist on 21 Mar 2012
It is hard to dig deeper without being able to run your code. However, the specific error is that length(weight) is equal to 10 (because length() returns the longer dimension of a 2-d array). But since weight is 10x4, you are trying to access the 10th column of an array that only has 4 columns. Hence, the error.

Richard
Richard on 21 Mar 2012
hi thanks alot for assisting me on this,pretty much stuck at this stage for at least a week.This is the original code(3x3) which i am basing my weighting method upon:
PM = [1/1 2/1 39/10;1/2 1/1 2/1;10/39 1/2 1/1]
Wt(:,1)=[1;0;0]
[len,width]=size(PM);
delta(:,1)=[1 1 1]';
trial=18;
for t=2:trial
Wt1(:,t)=PM*Wt(:,t-1);
max_eig=sum(Wt1(:,t));
Wtnorm1(:,t)=Wt1(:,t)./max_eig;
delta(:,t)=abs(Wt(:,t-1)-Wtnorm1(:,t));
if delta(:,t-1)>=1e-6
Wt(:,t)=Wtnorm1(:,t);
else
CI=(max_eig-width)/(width-1);
weight=Wtnorm1;
break
end
end
final_weight=weight(:,length(weight));
disp(['After',num2str(t),'iterations.....'])
disp(['The pairwise comparison result is [',num2str(final_weight(1)),' ',num2str(final_weight(2)),'',num2str(final_weight(3)),']'])
then for my 6x10 matrix the actual values are:
PM=[14.3/14.3 14.3/10 14.3/18 14.3/2.1 14.3/558 14.3/16.66 14.3/3.33 14.3/0.7 14.3/5 14.3/0.25;
10/14.3 10/10 10/18 10/2.1 10/558 10/16.66 10/3.33 10/0.7 10/5 10/0.25;
18/14.3 18/10 18/18 18/2.1 18/558 18/16.66 18/3.33 18/0.7 18/5 18/0.25;
2.1/14.3 2.1/10 2.1/18 2.1/2.1 2.1/558 2.1/16.66 2.1/3.33 2.1/0.7 2.1/5 2.1/0.25;
558/14.3 558/10 558/18 558/2.1 558/558 558/16.66 558/3.33 558/0.7 558/5 558/0.25;
16.66/14.3 16.66/10 16.66/18 16.66/2.1 16.66/558 16.66/16.66 16.66/3.33 16.66/0.7 16.66/5 16.66/0.25;
3.33/14.3 3.33/10 3.33/18 3.33/2.1 3.33/558 3.33/16.66 3.33/3.33 3.33/0.7 3.33/5 3.33/0.25;
0.7/14.3 0.7/10 0.7/18 0.7/2.1 0.7/558 0.7/16.66 0.7/3.33 0.7/0.7 0.7/5 0.7/0.25;
5/14.3 5/10 5/18 5/2.1 5/558 5/16.66 5/3.33 5/0.7 5/5 5/0.25;
0.25/14.3 0.25/10 0.25/18 0.25/2.1 0.25/558 0.25/16.66 0.25/3.33 0.25/0.7 0.25/5 0.25/0.25]
  1 Comment
the cyclist
the cyclist on 21 Mar 2012
I won't say that I deeply understand code. But, working backward, what is happening is the following:
(1) The 2nd dimension of "weight" is not as long as length(weight), so you are trying to index into an element that does not exist. In other words, the variable "weight" doesn't have enough columns.
(2) The reason that "weight" doesn't have enough columns is that you break out of the loop before you have created the columns you need.
(3) You break out of the loop based on the value of delta.
So, I am not exactly sure what is going wrong, but something in that chain is not working in the same way as your smaller 3x3 example.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!