# accsum Commit Details

Date: 2011-03-23 21:03:08 (7 years 10 months ago) Michael Baudin 16 15 Simplified the algorithm.

## File differences

macros/accsum_orderdynamic.sci
 8 8 9 9 10 10 11 11 12 12 13 13 14 14 ... ... 40 40 41 41 42 42 43 43 44 44 45 45 46 46 ... ... 49 49 50 50 51 51 52 52 53 53 54 54 55 55 56 57 56 58 59 57 60 58 61 62 59 63 60 64 65 61 66 62 67 68 69 70 63 71 64 72 65 73
 // 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␊ ␊

Revision: 16