help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Program refinement


From: Paul Kienzle
Subject: Re: Program refinement
Date: Sun, 1 Aug 2004 21:13:57 -0400


On Aug 1, 2004, at 9:00 PM, Rich Shepard wrote:

  I have a working program, but it's far from optimum and certainly not
generalized for a matrix of any arbitrary size. I'd greatly appreciate more
experienced folks suggesting how it should be rewritten to efficiently
handle matrices of different sizes.

  The data for the test 6x6 matrix is:

foo =

  1.00000  4.00000  3.00000  1.00000  3.00000  4.00000
  0.25000  1.00000  7.00000  3.00000  0.20000  1.00000
  0.33300  0.14300  1.00000  0.20000  0.20000  0.16700
  1.00000  0.33300  5.00000  1.00000  1.00000  0.33300
  0.33300  5.00000  5.00000  1.00000  1.00000  0.33300
  0.25000  1.00000  6.00000  3.00000  0.33300  1.00000

  The octave program, ahp.m, is:

# calculate primary vector using Saaty's method 4 on page 19
foo = load("table-1-2.dat")

# product of row elements and their 6th roots
bar = prod (foo,2);
# calculate 6th root of each element
root1 = bar(1) ^ (1/6);
root2 = bar(2) ^ (1/6);
root3 = bar(3) ^ (1/6);
root4 = bar(4) ^ (1/6);
root5 = bar(5) ^ (1/6);
root6 = bar(6) ^ (1/6);
# normalize column elements
sigmaroot = root1 + root2 + root3 + root4 + root5 + root6;
value1 = root1/sigmaroot;
value2 = root2/sigmaroot;
value3 = root3/sigmaroot;
value4 = root4/sigmaroot;
value5 = root5/sigmaroot;
value6 = root6/sigmaroot;
save -ascii test.output value1 value2 value3 value4 value5 value6
#EOF

Maybe something like this?

File ahp.m  (untested):

function m = ahp(x)
   n = size(x,2);
   r = prod(x,2).^(1/n);  # .^ for element powers
  m = r/sum(r);
#EOF


octave> data = load('table-1-2.dat');
octave> v = ahp(data);
octave> save -ascii test.output v



-------------------------------------------------------------
Octave is freely available under the terms of the GNU GPL.

Octave's home on the web:  http://www.octave.org
How to fund new projects:  http://www.octave.org/funding.html
Subscription information:  http://www.octave.org/archive.html
-------------------------------------------------------------



reply via email to

[Prev in Thread] Current Thread [Next in Thread]