accsum

accsum Commit Details

Date:2011-03-23 21:03:08 (7 years 3 months ago)
Author:Michael Baudin
Commit:16
Parents: 15
Message:Simplified the algorithm.
Changes:
M/macros/accsum_orderdynamic.sci

File differences

macros/accsum_orderdynamic.sci
88
99
1010
11
11
1212
1313
1414
......
4040
4141
4242
43
43
4444
4545
4646
......
4949
5050
5151
52
5253
5354
54
55
55
56
57
5658
59
5760
5861
62
5963
6064
65
6166
62
67
68
69
70
6371
6472
6573
// http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
function s = accsum_orderdynamic ( x , order )
// Try to find an order which makes the sum perform bad/good.
// Compute the sum with a dynamic re-ordering.
//
// Calling Sequence
// s = accsum_orderdynamic ( x , order )
// s = accsum_orderdynamic ( x , 2 )
//
// Authors
// Michael Baudin, 2010
// Michael Baudin, 2010-2011
//
// Bibliography
// "Stability and numerical accuracy of algorithms", Nicolas Higham
s = 0
z = x
n = size(x,"*")
// We remove an entry of z at each iteration of the loop:
// in the end, the array z is empty.
for k = 1 : size(x,"*")
[B,i] = gsort(abs(s+z),"g","i")
for k = 1 : n
// Sort into increasing order, from 1 to n-k+1.
[B,i] = gsort(abs(s+z(1:n-k+1)),"g","i")
if ( order == 1 ) then
// Set in i the indice which makes |s+z(i)| minimum
i = i(1)
else
// Set in i the indice which makes |s+z(i)| maximum
i = i($)
end
// Take into account for entry #i
s = s + z(i)
z(i) = []
// Switch entries #n-k+1 and #i
t = z(i)
z(i) = z(n-k+1)
z(n-k+1) = t
end
endfunction

Archive Download the corresponding diff file

Revision: 16